UIWarpContentItem1.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using UnityEngine;
  2. using System.Collections;
  3. using DG.Tweening;
  4. /// <summary>
  5. /// warp下Element对应标记
  6. /// </summary>
  7. [DisallowMultipleComponent]
  8. public class UIWarpContentItem1 : MonoBehaviour
  9. {
  10. private RectTransform panelTransform;
  11. /// <summary>
  12. /// 数据索引
  13. /// </summary>
  14. public int index = -1;
  15. /// <summary>
  16. /// 动画
  17. /// </summary>
  18. Tweener tweener = null;
  19. /// <summary>
  20. /// 元素列表优化
  21. /// </summary>
  22. private UIWarpContent1 warpContent = null;
  23. /// <summary>
  24. /// 销毁
  25. /// </summary>
  26. private void OnDestroy()
  27. {
  28. warpContent = null;
  29. }
  30. /// <summary>
  31. /// 元素列表优化对象
  32. /// </summary>
  33. public UIWarpContent1 WarpContent
  34. {
  35. set
  36. {
  37. warpContent = value;
  38. }
  39. }
  40. public void Awake()
  41. {
  42. panelTransform = this.transform.GetComponent<RectTransform>();
  43. }
  44. /// <summary>
  45. /// 数据索引
  46. /// </summary>
  47. public int Index
  48. {
  49. get
  50. {
  51. return index;
  52. }
  53. set
  54. {
  55. index = value;
  56. Vector3 destPos = warpContent.getLocalPositionByIndex(index);
  57. ////在动画运行中,如果重新排列,需要停止动画,不然就会乱
  58. if (tweener != null && tweener.IsPlaying())
  59. {
  60. tweener.Kill();
  61. transform.localPosition = destPos;
  62. }
  63. if (index < 25 && warpContent.hasPlayEffect && index >-1)
  64. {
  65. if (warpContent.KindOfEffect == 0)
  66. {
  67. transform.localPosition = new Vector3(destPos.x,- (warpContent.cellHeight + warpContent.cellHeightSpace)*8, destPos.z);
  68. tweener = panelTransform.DOLocalMove(destPos, 0.3f);
  69. tweener.SetEase(Ease.Linear);//动画曲线
  70. tweener.SetDelay(index * 0.01f);
  71. }
  72. else if (warpContent.KindOfEffect == 1)
  73. {
  74. transform.localPosition = new Vector3((destPos.x - 1080), destPos.y, destPos.z);
  75. tweener = panelTransform.DOLocalMove(destPos, 0.2f);
  76. tweener.SetEase(Ease.InOutQuad);//动画曲线
  77. tweener.SetDelay(index * 0.02f);
  78. }
  79. else if (warpContent.KindOfEffect == 2)
  80. {
  81. transform.localPosition = new Vector3((destPos.x + 1080),destPos.y, destPos.z);
  82. tweener = panelTransform.DOLocalMove(destPos, 0.2f);
  83. tweener.SetEase(Ease.InOutQuad);//动画曲线
  84. tweener.SetDelay(index * 0.1f);
  85. }
  86. }
  87. else
  88. {
  89. transform.localPosition = destPos;
  90. }
  91. gameObject.name = (index < 10) ? ("0" + index) : (string.Empty + index);
  92. if (warpContent.onInitializeItem != null && index >= 0)
  93. {
  94. warpContent.onInitializeItem(gameObject, index);
  95. }
  96. }
  97. }
  98. public Vector3 Pos
  99. {
  100. get
  101. {
  102. return warpContent.getLocalPositionByIndex(index);
  103. }
  104. }
  105. public void OnEnable()
  106. {
  107. //if (isInit == true)
  108. //{
  109. // panelTransform.DORestart(true);
  110. //}
  111. }
  112. public void OnDestory()
  113. {
  114. panelTransform.DOKill();
  115. }
  116. }