UITweenController.cs 3.3 KB

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