123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using UnityEngine;
- using System.Collections;
- using DG.Tweening;
- /// <summary>
- /// warp下Element对应标记
- /// </summary>
- [DisallowMultipleComponent]
- public class UIWarpContentItem1 : MonoBehaviour
- {
- private RectTransform panelTransform;
- /// <summary>
- /// 数据索引
- /// </summary>
- public int index = -1;
- /// <summary>
- /// 动画
- /// </summary>
- Tweener tweener = null;
- /// <summary>
- /// 元素列表优化
- /// </summary>
- private UIWarpContent1 warpContent = null;
- /// <summary>
- /// 销毁
- /// </summary>
- private void OnDestroy()
- {
- warpContent = null;
- }
- /// <summary>
- /// 元素列表优化对象
- /// </summary>
- public UIWarpContent1 WarpContent
- {
- set
- {
- warpContent = value;
- }
- }
- public void Awake()
- {
- panelTransform = this.transform.GetComponent<RectTransform>();
- }
- /// <summary>
- /// 数据索引
- /// </summary>
- 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();
- }
- }
|