UITweenController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  4. using UnityEngine;
  5. using Object = UnityEngine.Object;
  6. namespace Core.UI.UTool.UITween
  7. {
  8. [ExecuteInEditMode]
  9. public class UITweenController : MonoBehaviour
  10. {
  11. public float maxDuration;
  12. public bool isUpdate;
  13. [HideInInspector] public float currTime;
  14. public List<TweenAssetGrpupInfo> GrpupInfos = new List<TweenAssetGrpupInfo>();
  15. private BetterList<TweenAssetGrpupInfo> _currPlay = new BetterList<TweenAssetGrpupInfo>();
  16. public ParticleSystem.MinMaxGradient MinMaxGradient = new ParticleSystem.MinMaxGradient();
  17. private bool isLoop;
  18. private void OnEnable()
  19. {
  20. if (Application.isPlaying)
  21. {
  22. StartPlay();
  23. }
  24. }
  25. public void Play(string animName)
  26. {
  27. _currPlay.Clear();
  28. for (int i = 0; i < GrpupInfos.Count; i++)
  29. {
  30. TweenAssetGrpupInfo tweenAssetGrpupInfo = GrpupInfos[i];
  31. if (tweenAssetGrpupInfo.animName.Equals(animName))
  32. {
  33. _currPlay.Add(tweenAssetGrpupInfo);
  34. }
  35. }
  36. }
  37. public void Stop()
  38. {
  39. isUpdate = false;
  40. }
  41. public void StartPlay()
  42. {
  43. maxDuration = 0;
  44. _currPlay.Clear();
  45. isLoop = false;
  46. for (int i = 0; i < GrpupInfos.Count; i++)
  47. {
  48. TweenAssetGrpupInfo tweenAssetGrpupInfo = GrpupInfos[i];
  49. tweenAssetGrpupInfo.SetMaxTime();
  50. if (tweenAssetGrpupInfo.isActive)
  51. {
  52. if (tweenAssetGrpupInfo.maxDuration > maxDuration)
  53. {
  54. maxDuration = tweenAssetGrpupInfo.maxDuration;
  55. }
  56. if (tweenAssetGrpupInfo.isLoop)
  57. {
  58. isLoop = true;
  59. }
  60. tweenAssetGrpupInfo.StartPlay();
  61. _currPlay.Add(tweenAssetGrpupInfo);
  62. }
  63. }
  64. isUpdate = true;
  65. currTime = 0;
  66. }
  67. public void SetMaxTime()
  68. {
  69. maxDuration = 0;
  70. for (int i = 0; i < GrpupInfos.Count; i++)
  71. {
  72. TweenAssetGrpupInfo tweenAssetGrpupInfo = GrpupInfos[i];
  73. tweenAssetGrpupInfo.SetMaxTime();
  74. if (tweenAssetGrpupInfo.isActive)
  75. {
  76. if (tweenAssetGrpupInfo.maxDuration > maxDuration)
  77. {
  78. maxDuration = tweenAssetGrpupInfo.maxDuration;
  79. }
  80. }
  81. }
  82. }
  83. public void JumpToTime(float t)
  84. {
  85. for (int i = 0; i < GrpupInfos.Count; i++)
  86. {
  87. GrpupInfos[i].JumpToTime(t);
  88. // allTweenInfo[i].Rest();
  89. }
  90. PlayTween(t, true);
  91. }
  92. private void PlayTween(float t, bool isFallBack)
  93. {
  94. for (int i = 0; i < GrpupInfos.Count; i++)
  95. {
  96. GrpupInfos[i].PlayTween(t, isFallBack);
  97. }
  98. }
  99. private void Update()
  100. {
  101. if (!isUpdate)
  102. {
  103. return;
  104. }
  105. currTime += Time.deltaTime;
  106. for (int i = 0; i < _currPlay.Count; i++)
  107. {
  108. _currPlay[i].PlayTween(currTime, false);
  109. }
  110. if (!isLoop&&currTime >= maxDuration)
  111. {
  112. isUpdate = false;
  113. }
  114. }
  115. }
  116. }