NoviceTimeLineController.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Timeline;
  6. using UnityEngine.Playables;
  7. using UnityGameFramework.Runtime;
  8. using UnityEngine.Video;
  9. public class NoviceTimeLineController : MonoBehaviour
  10. {
  11. public VideoPlayer _timelineController1;
  12. public VideoPlayer _timelineController2;
  13. //public PlayableDirector _timelineController2;
  14. //public PlayableDirector _timelineController3;
  15. //public PlayableDirector _timelineController4;
  16. //public PlayableDirector _timelineController5;
  17. //public PlayableDirector _timelineController6;
  18. //public PlayableDirector _timelineController7;
  19. public GameObject _slefObj;
  20. //public GameObject _canvasObj;
  21. //public Camera _TLCamera;
  22. public Button _skipBtn;
  23. public GameObject _skipDialogObj;
  24. /// <summary>
  25. /// 确认跳过
  26. /// </summary>
  27. public Button _continueBtn;
  28. /// <summary>
  29. /// 取消跳过
  30. /// </summary>
  31. public Button _skipOKBtn;
  32. //public GameObject _battleCamera;
  33. float _countTime;
  34. float oldY;
  35. bool _isAttack;
  36. // 播放时长
  37. float _duration;
  38. int playIndex;
  39. private void Awake()
  40. {
  41. _timelineController1 = transform.Find("UICanvas/NoviceCG").GetComponent<VideoPlayer>();
  42. _timelineController2 = transform.Find("UICanvas/SceneCG").GetComponent<VideoPlayer>();
  43. _timelineController2.gameObject.SetActive(false);
  44. //_timelineController2 = transform.Find("TimelineTwo/Timeline_piantou2").GetComponent<PlayableDirector>();
  45. //_timelineController3 = transform.Find("TimelineTwo/Timeline_piantou3").GetComponent<PlayableDirector>();
  46. //_timelineController4 = transform.Find("TimelineTwo/Timeline_piantou4").GetComponent<PlayableDirector>();
  47. //_timelineController5 = transform.Find("TimelineTwo/Timeline_piantou5").GetComponent<PlayableDirector>();
  48. //_timelineController6 = transform.Find("TimelineTwo/Timeline_piantou6").GetComponent<PlayableDirector>();
  49. //_timelineController7 = transform.Find("TimelineTwo/Timeline_piantou7").GetComponent<PlayableDirector>();
  50. _slefObj = transform.Find("Canvas").gameObject;
  51. //_canvasObj = transform.Find("TimelineTwo/Canvas").gameObject;
  52. //_TLCamera = transform.Find("Main Camera").GetComponent<Camera>();
  53. _skipBtn = transform.Find("UICanvas/Button").GetComponent<Button>();
  54. _skipDialogObj = transform.Find("UICanvas/SkipDialog").gameObject;
  55. _continueBtn = _skipDialogObj.transform.Find("continue_btn").GetComponent<Button>();
  56. _skipOKBtn = _skipDialogObj.transform.Find("skip_btn").GetComponent<Button>();
  57. EventTriggerListener.Get(_continueBtn.gameObject).onClick = CloseSkipDialog;
  58. EventTriggerListener.Get(_skipBtn.gameObject).onClick = OpenSkipDialog;
  59. EventTriggerListener.Get(_skipOKBtn.gameObject).onClick = SkipTimeLine;
  60. _skipDialogObj.SetActive(false);
  61. }
  62. // Start is called before the first frame update
  63. void Start()
  64. {
  65. //closeAllTimeLine();
  66. }
  67. public void OpenSkipDialog(GameObject obj)
  68. {
  69. _skipDialogObj.SetActive(true);
  70. }
  71. public void CloseSkipDialog(GameObject obj)
  72. {
  73. _skipDialogObj.SetActive(false);
  74. }
  75. public void SkipTimeLine(GameObject obj)
  76. {
  77. //_TLCamera.gameObject.SetActive(false);
  78. //_canvasObj.SetActive(false);
  79. _skipBtn.gameObject.SetActive(false);
  80. _skipDialogObj.SetActive(false);
  81. ConvertEffect.Instance.PlayEffect(ConvertEffect.convertEffectType.LucencyToBlack, SkipTimeLineFinish);
  82. }
  83. public void SkipTimeLineFinish(GameObject obj)
  84. {
  85. ConvertEffect.Instance.PlayEffect(ConvertEffect.convertEffectType.BlackToLucency, null);
  86. CloseFinish(null);
  87. }
  88. // Update is called once per frame
  89. void Update()
  90. {
  91. if (_duration > 0)
  92. {
  93. _duration -= Time.deltaTime;
  94. if (_duration <= 0)
  95. {
  96. if (playIndex == 1)
  97. {
  98. _timelineController1.gameObject.SetActive(false);
  99. _skipDialogObj.gameObject.SetActive(false);
  100. // 观看重要剧情; 添加 钻石货币 2颗
  101. UserProxy.Instance.SendImportantStoryViewFullReward();
  102. PlayByIndex(2);
  103. }
  104. else if(playIndex == 2)
  105. {
  106. CloseAllTimeLine();
  107. }
  108. HpbarManager.Instance.SetShowState(true);
  109. if (playIndex == 6)
  110. {
  111. return;
  112. }
  113. }
  114. }
  115. }
  116. public void CloseAllTimeLine()
  117. {
  118. ConvertEffect.Instance.PlayEffect(ConvertEffect.convertEffectType.LucencyToBlack, CloseFinish);
  119. }
  120. public void CloseFinish(GameObject obj)
  121. {
  122. playIndex = 2;
  123. ConvertEffect.Instance.PlayEffect(ConvertEffect.convertEffectType.BlackToLucency, null);
  124. _skipBtn.gameObject.SetActive(false);
  125. Image img = this.transform.Find("UICanvas").GetComponent<Image>();
  126. img.raycastTarget = false;
  127. this._slefObj.gameObject.SetActive(false);
  128. EventComponent nowEvent = GameEntry.GetComponent<EventComponent>();
  129. nowEvent.FireNow(this, new NoviceEventTimeLineComplete(playIndex));
  130. _duration = 0;
  131. }
  132. public void PlayByIndex(int index)
  133. {
  134. HpbarManager.Instance.SetShowState(false);
  135. //this._battleCamera.gameObject.SetActive(false);
  136. switch (index)
  137. {
  138. case 1:
  139. this._slefObj.gameObject.SetActive(true);
  140. _duration = (float)_timelineController1.clip.length;
  141. _duration -= 0.3f;
  142. playIndex = 1;
  143. _timelineController1.Play();
  144. break;
  145. case 2:
  146. this._slefObj.gameObject.SetActive(true);
  147. _duration = (float)_timelineController2.clip.length;
  148. playIndex = 2;
  149. _timelineController2.gameObject.SetActive(true);
  150. _timelineController2.Play();
  151. //UserProxy.Instance.UpdateNewbieGuideStep(2, null);
  152. break;
  153. //case 2:
  154. // _timelineController2.gameObject.SetActive(true);
  155. // _duration = (float)_timelineController2.duration;
  156. // playIndex = 2;
  157. // _timelineController2.Play();
  158. // break;
  159. //case 3:
  160. // _timelineController3.gameObject.SetActive(true);
  161. // _duration = (float)_timelineController3.duration;
  162. // playIndex = 3;
  163. // _timelineController3.Play();
  164. // break;
  165. //case 4:
  166. // _timelineController4.gameObject.SetActive(true);
  167. // _duration = (float)_timelineController4.duration;
  168. // playIndex = 4;
  169. // _timelineController4.Play();
  170. // break;
  171. //case 5:
  172. // _timelineController5.gameObject.SetActive(true);
  173. // _duration = (float)_timelineController5.duration;
  174. // playIndex = 5;
  175. // _timelineController5.Play();
  176. // break;
  177. //case 6:
  178. // _timelineController6.gameObject.SetActive(true);
  179. // //_duration = (float)_timelineController6.duration;
  180. // _duration = 2.5f;
  181. // playIndex = 6;
  182. // _timelineController6.Play();
  183. // break;
  184. //case 7:
  185. // _timelineController7.gameObject.SetActive(true);
  186. // _duration = (float)_timelineController7.duration;
  187. // playIndex = 7;
  188. // _timelineController7.Play();
  189. // break;
  190. }
  191. }
  192. }