Unity 挤压四周效果
using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class ToChangeImages:MonoBehaviour { float enlargeSize = 2.0f; float radiateSize = 220; Dictionary<RectTransform, Vector2> itemPosDict = new Dictionary<RectTransform, Vector2>(); List<RectTransform> changedItemList = new List<RectTransform>(); public RectTransform[] item; // Use this for initialization void Start() { StartThis(); } void StartThis() { for (int i = 0; i < item.Length; i++) { RectTransform item0 = item[i]; //Vector2 startPos = item0.position; Vector2 startPos = item0.transform.localPosition; Debug.Log(startPos.ToString()); itemPosDict.Add(item0, startPos); } } // Update is called once per frame void Update() { } public void OnMousePointEnter(RectTransform item1) { //缓动改变中心物体的尺寸 item1.DOScale(enlargeSize, 0.5f); Vector2 pos = itemPosDict[item1]; changedItemList = new List<RectTransform>(); //添加扩散物体到集合 foreach (KeyValuePair<RectTransform, Vector2> i in itemPosDict) { if (Vector2.Distance(i.Value, pos) < radiateSize) { changedItemList.Add(i.Key); } } //缓动来解决扩散物体的动画 for (int i = 0; i < changedItemList.Count; i++) { Vector2 targetPos = itemPosDict[item1] + (itemPosDict[changedItemList[i]] - itemPosDict[item1]).normalized * radiateSize; changedItemList[i].DOAnchorPos(targetPos, 0.8f); } } public void OnMousePointExit(RectTransform go) { //缓动恢复中心物体的尺寸 go.DOScale(1, 1); //缓动将扩散物体恢复到初始位置 for (int i = 0; i < changedItemList.Count; i++) { changedItemList[i].DOAnchorPos(itemPosDict[changedItemList[i]], 0.8f); } } }
转载:https://blog.csdn.net/qq_17367039/article/details/124080719
posted on 2022-05-05 14:13 zqiang0803 阅读(182) 评论(0) 编辑 收藏 举报