StaffRollCtrl.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using UnityEngine;
  3. public class StaffRollCtrl : MonoBehaviour
  4. {
  5. public void Init(StaffRollMgr staffRollMgr, GameObject goPanel)
  6. {
  7. this.m_mgr = staffRollMgr;
  8. this.m_goPanel = goPanel;
  9. this.m_goStaffRollViewer = UTY.GetChildObject(this.m_goPanel, "StaffRollViewer", false);
  10. this.m_goLogoViewer = UTY.GetChildObject(this.m_goPanel, "LogoViewer", false);
  11. this.m_targetScroll = UTY.GetChildObject(this.m_goPanel, "StaffRollViewer/StaffRollUnitParent", false);
  12. this.m_targetScroll.transform.localPosition = new Vector2(this.m_targetScroll.transform.localPosition.x, (float)this.moveFromPosY);
  13. this.m_goTexture = UTY.GetChildObject(this.m_goPanel, "StaffRollViewer/Texture", false);
  14. this.m_listTexture = Resources.LoadAll<Texture2D>("SceneStaffRoll/Texture");
  15. this.m_dispTextureTime = (float)(this.durationToScroll / this.m_listTexture.Length) - (this.fadeInTimeTexure + this.fadeOutTimeTexure);
  16. this.m_goLogoViewer = UTY.GetChildObject(this.m_goPanel, "LogoViewer", false);
  17. this.m_goLogoViewer.SetActive(false);
  18. this.ChangeTextureState(StaffRollCtrl.TxetureState.None);
  19. }
  20. public void OnDestroy()
  21. {
  22. this.m_goTexture.GetComponent<UITexture>().mainTexture = null;
  23. for (int i = 0; i < this.m_listTexture.Length; i++)
  24. {
  25. Resources.UnloadAsset(this.m_listTexture[i]);
  26. }
  27. }
  28. private void Update()
  29. {
  30. switch (this.m_currentTextureState)
  31. {
  32. case StaffRollCtrl.TxetureState.FadeIn:
  33. this.FadeIn();
  34. break;
  35. case StaffRollCtrl.TxetureState.FadeOut:
  36. this.FadeOut();
  37. break;
  38. case StaffRollCtrl.TxetureState.Display:
  39. this.Display();
  40. break;
  41. case StaffRollCtrl.TxetureState.Next:
  42. this.Next();
  43. break;
  44. case StaffRollCtrl.TxetureState.End:
  45. this.End();
  46. break;
  47. }
  48. }
  49. public void DispStaffRollViewer()
  50. {
  51. this.PlayAnimation();
  52. }
  53. private void PlayAnimation()
  54. {
  55. this.StartScrollStaffRoll();
  56. this.m_goTexture.GetComponent<UITexture>().mainTexture = this.m_listTexture[1];
  57. this.StartTextureAnimation();
  58. }
  59. public void StartScrollStaffRoll()
  60. {
  61. TweenPosition.Begin(this.m_targetScroll, (float)this.durationToScroll, new Vector2(this.m_targetScroll.transform.localPosition.x, (float)this.moveToPosY));
  62. }
  63. private void ChangeTextureState(StaffRollCtrl.TxetureState nextState)
  64. {
  65. this.m_currentTextureState = nextState;
  66. }
  67. public void StartTextureAnimation()
  68. {
  69. this.ChangeTextureState(StaffRollCtrl.TxetureState.FadeIn);
  70. }
  71. protected void FadeIn()
  72. {
  73. this.ChangeTextureState(StaffRollCtrl.TxetureState.RunnigFade);
  74. this.m_tweenTexture = TweenAlpha.Begin(this.m_goTexture, this.fadeInTimeTexure, 1f);
  75. EventDelegate.Set(this.m_tweenTexture.onFinished, delegate()
  76. {
  77. this.ChangeTextureState(StaffRollCtrl.TxetureState.Display);
  78. this.m_updateTime = Time.time + this.m_dispTextureTime;
  79. });
  80. }
  81. private void Display()
  82. {
  83. if (this.m_updateTime < Time.time)
  84. {
  85. this.ChangeTextureState(StaffRollCtrl.TxetureState.FadeOut);
  86. }
  87. }
  88. private void FadeOut()
  89. {
  90. this.ChangeTextureState(StaffRollCtrl.TxetureState.RunnigFade);
  91. TweenAlpha tweenAlpha = TweenAlpha.Begin(this.m_goTexture, this.fadeOutTimeTexure, 0f);
  92. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  93. {
  94. this.ChangeTextureState(StaffRollCtrl.TxetureState.Next);
  95. });
  96. }
  97. private void Next()
  98. {
  99. Texture2D nextTexture = this.GetNextTexture();
  100. if (nextTexture == null)
  101. {
  102. this.ChangeTextureState(StaffRollCtrl.TxetureState.End);
  103. }
  104. else
  105. {
  106. UITexture component = this.m_goTexture.GetComponent<UITexture>();
  107. component.mainTexture = nextTexture;
  108. this.ChangeTextureState(StaffRollCtrl.TxetureState.FadeIn);
  109. }
  110. }
  111. private Texture2D GetNextTexture()
  112. {
  113. this.m_textureNumber++;
  114. if (this.m_listTexture.Length > this.m_textureNumber)
  115. {
  116. UITexture component = this.m_goTexture.GetComponent<UITexture>();
  117. return this.m_listTexture[this.m_textureNumber];
  118. }
  119. return null;
  120. }
  121. private void End()
  122. {
  123. this.ChangeTextureState(StaffRollCtrl.TxetureState.None);
  124. this.m_mgr.CloseViewerAndPanel();
  125. }
  126. public void SetEnd()
  127. {
  128. this.StopAnimation();
  129. this.End();
  130. }
  131. public void StopAnimation()
  132. {
  133. iTween.Stop(this.m_targetScroll, "move");
  134. if (this.m_tweenTexture != null)
  135. {
  136. UnityEngine.Object.Destroy(this.m_tweenTexture);
  137. }
  138. }
  139. public void DispLogoViewer()
  140. {
  141. this.m_currentTextureState = StaffRollCtrl.TxetureState.None;
  142. this.m_goStaffRollViewer.SetActive(false);
  143. this.m_goLogoViewer.SetActive(true);
  144. }
  145. [SerializeField]
  146. private int durationToScroll;
  147. [SerializeField]
  148. private int moveFromPosY;
  149. [SerializeField]
  150. private int moveToPosY;
  151. [SerializeField]
  152. private float fadeInTimeTexure;
  153. [SerializeField]
  154. private float fadeOutTimeTexure;
  155. private StaffRollCtrl.TxetureState m_currentTextureState = StaffRollCtrl.TxetureState.None;
  156. private StaffRollMgr m_mgr;
  157. private Texture2D[] m_listTexture;
  158. private GameObject m_goPanel;
  159. private GameObject m_goLogoViewer;
  160. private GameObject m_goStaffRollViewer;
  161. private GameObject m_targetScroll;
  162. private GameObject m_goTexture;
  163. private TweenAlpha m_tweenTexture;
  164. private float m_dispTextureTime;
  165. private float m_updateTime;
  166. private int m_textureNumber;
  167. private const string LOAD_TEXTURE_PATH = "SceneStaffRoll/Texture";
  168. private const int FIRST_TEXTURE = 1;
  169. private enum TxetureState
  170. {
  171. FadeIn,
  172. FadeOut,
  173. Display,
  174. RunnigFade,
  175. Next,
  176. End,
  177. None
  178. }
  179. }