作者:梦亦碎i | 来源:互联网 | 2023-09-23 22:38
话不多说,先献上效果图: 6个物体无限循环:
3个物体无限循环:
实现的原理: 其实从上面的3个循环的动画可以看出实现原理了。
1.首先创建对应的item循环节点,放在一个父物体下面统一管理。 2.父物体添加EventTrigger组件,用于取代scroll view监听拖拽事件。 3.在脚本里面通过遍历所有item,使用dotween对item进行位移,同时重新设置子item的层级 核心脚本
//改变位置 层级private void __changePos(int moveIndex){for (int i = 1; i <= btnList.Count; i++){var sequence = DOTween.Sequence();if (moveIndex > 0){int v = moveIndex - 1;//除去自身float moveTime = aniTime / moveIndex;//计算动画时间for (int k = v; k >= 0; k--)//遍历所有步骤{int temp = i - k;if (temp <1){temp += btnList.Count;}sequence.Append(btnList[i - 1].DOMove(prevBtnPos[temp - 1], moveTime).SetEase(Ease.Linear));sequence.Join(btnList[i - 1].DOScale(new Vector3(scaleList[temp - 1], scaleList[temp - 1], scaleList[temp - 1]), moveTime).SetEase(Ease.Linear));}}else{int v = Mathf.Abs(moveIndex) - 1;float moveTime = aniTime / Mathf.Abs(moveIndex);//计算动画时间for (int k = v; k >= 0; k--)//遍历所有步骤{int temp = i + k;if (temp > btnList.Count){temp -= btnList.Count;}sequence.Append(btnList[i - 1].DOMove(prevBtnPos[temp - 1], moveTime).SetEase(Ease.Linear));Debug.Log("移:" + temp);Debug.Log("移:" + scaleList[temp - 1]);sequence.Join(btnList[i - 1].DOScale(new Vector3(scaleList[temp - 1], scaleList[temp - 1], scaleList[temp - 1]), moveTime).SetEase(Ease.Linear));}}btnList[i - 1].transform.SetAsFirstSibling();//层级sequence.AppendCallback(() => {if (isClick){ }isClick = false;});}parent.transform.GetChild(0).SetSiblingIndex(campCount - 2);//左1}
也可以通过点击item进行跳转
//直接点击item进行跳转private void ClickCamp(Transform btn){int moveIndex = 0;for (int i = 1; i <= btnList.Count; i++){if (btnList[i - 1] == btn){int val = i - 1;if (val