UITweenController.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 void OnEnable()
  18. {
  19. if (Application.isPlaying)
  20. {
  21. StartPlay();
  22. }
  23. }
  24. public void Play(string animName)
  25. {
  26. _currPlay.Clear();
  27. for (int i = 0; i < GrpupInfos.Count; i++)
  28. {
  29. TweenAssetGrpupInfo tweenAssetGrpupInfo = GrpupInfos[i];
  30. if (tweenAssetGrpupInfo.animName.Equals(animName))
  31. {
  32. _currPlay.Add(tweenAssetGrpupInfo);
  33. }
  34. }
  35. }
  36. public void StartPlay()
  37. {
  38. maxDuration = 0;
  39. _currPlay.Clear();
  40. for (int i = 0; i < GrpupInfos.Count; i++)
  41. {
  42. TweenAssetGrpupInfo tweenAssetGrpupInfo = GrpupInfos[i];
  43. tweenAssetGrpupInfo.SetMaxTime();
  44. if (tweenAssetGrpupInfo.isActive)
  45. {
  46. if (tweenAssetGrpupInfo.maxDuration > maxDuration)
  47. {
  48. maxDuration = tweenAssetGrpupInfo.maxDuration;
  49. }
  50. tweenAssetGrpupInfo.StartPlay();
  51. _currPlay.Add(tweenAssetGrpupInfo);
  52. }
  53. }
  54. isUpdate = true;
  55. currTime = 0;
  56. }
  57. public void SetMaxTime()
  58. {
  59. maxDuration = 0;
  60. for (int i = 0; i < GrpupInfos.Count; i++)
  61. {
  62. TweenAssetGrpupInfo tweenAssetGrpupInfo = GrpupInfos[i];
  63. tweenAssetGrpupInfo.SetMaxTime();
  64. if (tweenAssetGrpupInfo.isActive)
  65. {
  66. if (tweenAssetGrpupInfo.maxDuration > maxDuration)
  67. {
  68. maxDuration = tweenAssetGrpupInfo.maxDuration;
  69. }
  70. }
  71. }
  72. }
  73. public void JumpToTime(float t)
  74. {
  75. for (int i = 0; i < GrpupInfos.Count; i++)
  76. {
  77. GrpupInfos[i].JumpToTime(t);
  78. // allTweenInfo[i].Rest();
  79. }
  80. PlayTween(t, true);
  81. }
  82. private void PlayTween(float t, bool isFallBack)
  83. {
  84. for (int i = 0; i < GrpupInfos.Count; i++)
  85. {
  86. GrpupInfos[i].PlayTween(t, isFallBack);
  87. }
  88. }
  89. private void Update()
  90. {
  91. if (!isUpdate)
  92. {
  93. return;
  94. }
  95. currTime += Time.deltaTime;
  96. for (int i = 0; i < _currPlay.Count; i++)
  97. {
  98. _currPlay[i].PlayTween(currTime, false);
  99. }
  100. if (currTime >= maxDuration)
  101. {
  102. isUpdate = false;
  103. }
  104. }
  105. }
  106. }