using UnityEngine; using System.Collections; using DG.Tweening; /// /// warp下Element对应标记 /// [DisallowMultipleComponent] public class UIWarpContentItem1 : MonoBehaviour { private RectTransform panelTransform; /// /// 数据索引 /// public int index = -1; /// /// 动画 /// Tweener tweener = null; /// /// 元素列表优化 /// private UIWarpContent1 warpContent = null; /// /// 销毁 /// private void OnDestroy() { warpContent = null; } /// /// 元素列表优化对象 /// public UIWarpContent1 WarpContent { set { warpContent = value; } } public void Awake() { panelTransform = this.transform.GetComponent(); } /// /// 数据索引 /// public int Index { get { return index; } set { index = value; Vector3 destPos = warpContent.getLocalPositionByIndex(index); ////在动画运行中,如果重新排列,需要停止动画,不然就会乱 if (tweener != null && tweener.IsPlaying()) { tweener.Kill(); transform.localPosition = destPos; } if (index < 25 && warpContent.hasPlayEffect && index >-1) { if (warpContent.KindOfEffect == 0) { transform.localPosition = new Vector3(destPos.x,- (warpContent.cellHeight + warpContent.cellHeightSpace)*8, destPos.z); tweener = panelTransform.DOLocalMove(destPos, 0.3f); tweener.SetEase(Ease.Linear);//动画曲线 tweener.SetDelay(index * 0.01f); } else if (warpContent.KindOfEffect == 1) { transform.localPosition = new Vector3((destPos.x - 1080), destPos.y, destPos.z); tweener = panelTransform.DOLocalMove(destPos, 0.2f); tweener.SetEase(Ease.InOutQuad);//动画曲线 tweener.SetDelay(index * 0.02f); } else if (warpContent.KindOfEffect == 2) { transform.localPosition = new Vector3((destPos.x + 1080),destPos.y, destPos.z); tweener = panelTransform.DOLocalMove(destPos, 0.2f); tweener.SetEase(Ease.InOutQuad);//动画曲线 tweener.SetDelay(index * 0.1f); } } else { transform.localPosition = destPos; } gameObject.name = (index < 10) ? ("0" + index) : (string.Empty + index); if (warpContent.onInitializeItem != null && index >= 0) { warpContent.onInitializeItem(gameObject, index); } } } public Vector3 Pos { get { return warpContent.getLocalPositionByIndex(index); } } public void OnEnable() { //if (isInit == true) //{ // panelTransform.DORestart(true); //} } public void OnDestory() { panelTransform.DOKill(); } }