TimeLineChange.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. public class TimeLineChange : MonoBehaviour {
  6. public PlayableDirector mDirector;
  7. public GameObject mGame2;
  8. public TimelinePauseByTime mGamePauseObj;
  9. private bool StopAndFirstFream = false;
  10. public void Start()
  11. {
  12. mDirector.gameObject.SetActive(false);
  13. mGame2.SetActive(false);
  14. mGamePauseObj = mGame2.GetComponent<TimelinePauseByTime>();
  15. }
  16. public void CloseAllTimeLine()
  17. {
  18. TimeLineStop();
  19. mDirector.gameObject.SetActive(false);
  20. mGame2.SetActive(false);
  21. }
  22. public void SwitchDirector(TimeLineControlType ControlType)
  23. {
  24. if (ControlType == TimeLineControlType.E_Explain)
  25. {
  26. mDirector.gameObject.SetActive(true);
  27. TimeLinePlay();
  28. StopAndFirstFream = true;
  29. //Invoke("TimeLinePause", 0.1f);
  30. mGame2.SetActive(false);
  31. }
  32. else
  33. {
  34. mDirector.gameObject.SetActive(false);
  35. TimeLinePlay();
  36. StopAndFirstFream = true;
  37. //Invoke("TimeLinePause", 0.1f);
  38. mGame2.SetActive(true);
  39. if (mGamePauseObj != null)
  40. {
  41. mGamePauseObj.InitTaskCanvas();
  42. }
  43. }
  44. }
  45. public double GetLength()
  46. {
  47. return mDirector.duration;
  48. }
  49. public double GetCurrentTime()
  50. {
  51. return mDirector.time;
  52. }
  53. void _play()
  54. {
  55. if (!mDirector.gameObject.activeSelf)
  56. {
  57. mDirector.gameObject.SetActive(true);
  58. }
  59. mDirector.Play();
  60. }
  61. public void TimeLineRePlay()
  62. {
  63. mDirector.Stop();
  64. mDirector.time = 0;
  65. _play();
  66. }
  67. public void TimeLinePlay()
  68. {
  69. _play();
  70. }
  71. public void TimeLinePause()
  72. {
  73. mDirector.Pause();
  74. }
  75. public void TimeLineStop()
  76. {
  77. mDirector.Stop();
  78. }
  79. public void SetTime(float ratio)
  80. {
  81. mDirector.Pause();
  82. mDirector.time = mDirector.duration * ratio;
  83. _play();
  84. }
  85. public void Update()
  86. {
  87. if (StopAndFirstFream)
  88. {
  89. if (mDirector.time > 0.0f)
  90. {
  91. TimeLinePause();
  92. StopAndFirstFream = false;
  93. }
  94. }
  95. if (mDirector.time >= mDirector.duration)
  96. {
  97. if (mDirector.gameObject.activeSelf)
  98. {
  99. mDirector.gameObject.SetActive(false);
  100. }
  101. }
  102. }
  103. }