TweenController.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TweenController : MonoBehaviour
  5. {
  6. public List<TweenBase> mlist = new List<TweenBase>();
  7. void Awake()
  8. {
  9. TweenBase[] tb = GetComponents<TweenBase>();
  10. for (int i = 0; i < tb.Length; i++)
  11. {
  12. mlist.Add(tb[i]);
  13. }
  14. }
  15. public void Begin()
  16. {
  17. for (int i = 0; i < mlist.Count; i++)
  18. {
  19. if(mlist[i] == null)
  20. {
  21. Debug.LogError("tween有数组是空" + i);
  22. continue;
  23. }
  24. mlist[i].Init();
  25. if (mlist[i].delaytime > 0)
  26. {
  27. StartCoroutine(DelayStart(mlist[i].delaytime, mlist[i]));
  28. }
  29. else
  30. {
  31. mlist[i].StartAction();
  32. }
  33. }
  34. }
  35. IEnumerator DelayStart(float time, TweenBase tb)
  36. {
  37. yield return new WaitForSeconds(time);
  38. tb.StartAction();
  39. }
  40. void Update()
  41. {
  42. if (Input.GetKeyUp(KeyCode.Space))
  43. {
  44. Begin();
  45. }
  46. }
  47. }