WfScreenChildren.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System;
  2. using UnityEngine;
  3. public abstract class WfScreenChildren : MonoBehaviour
  4. {
  5. public virtual void Awake()
  6. {
  7. this.root_obj_ = this.RootPanel;
  8. this.awake_active_ = this.root_obj_.activeSelf;
  9. if (!this.root_obj_.activeSelf)
  10. {
  11. this.root_obj_.SetActive(true);
  12. }
  13. this.call_fadein_wait_ = (this.cur_call_fadein_wait_ = 0);
  14. }
  15. public virtual void Update()
  16. {
  17. if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeInWait)
  18. {
  19. this.cur_call_fadein_wait_--;
  20. if (0 <= this.cur_call_fadein_wait_)
  21. {
  22. return;
  23. }
  24. if (this.IsCallFadeIn())
  25. {
  26. this.cur_call_fadein_wait_ = 0;
  27. if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeInWait)
  28. {
  29. this.FadeIn();
  30. }
  31. }
  32. }
  33. else
  34. {
  35. this.cur_call_fadein_wait_ = 0;
  36. }
  37. if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeIn)
  38. {
  39. if (!GameMain.Instance.MainCamera.IsFadeProc())
  40. {
  41. this.fade_status_ = WfScreenChildren.FadeStatus.Wait;
  42. }
  43. }
  44. else if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeOut)
  45. {
  46. if (!GameMain.Instance.MainCamera.IsFadeProc())
  47. {
  48. this.fade_status_ = WfScreenChildren.FadeStatus.FadeEnd;
  49. this.OnFinish();
  50. }
  51. }
  52. else if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeEnd)
  53. {
  54. this.OnFadeEnd();
  55. }
  56. }
  57. public bool Call()
  58. {
  59. if (!this.init_finishied)
  60. {
  61. NDebug.Assert("初期化完了前にCallが呼ばれました", false);
  62. return false;
  63. }
  64. if (this.fade_status_ != WfScreenChildren.FadeStatus.Null)
  65. {
  66. Debug.LogWarning("Call呼び出し\nフェード状態は" + this.fade_status_.ToString() + "なのでキャンセルされました");
  67. return false;
  68. }
  69. this.cur_call_fadein_wait_ = 0;
  70. if (!this.root_obj_.activeSelf)
  71. {
  72. this.root_obj_.SetActive(true);
  73. }
  74. this.OnCall();
  75. if (this.call_fadein_wait_ <= 0 && this.IsCallFadeIn())
  76. {
  77. this.FadeIn();
  78. }
  79. else
  80. {
  81. if (0 < this.call_fadein_wait_)
  82. {
  83. this.cur_call_fadein_wait_ = this.call_fadein_wait_;
  84. }
  85. if (this.fade_status_ == WfScreenChildren.FadeStatus.Null)
  86. {
  87. this.fade_status_ = WfScreenChildren.FadeStatus.FadeInWait;
  88. }
  89. }
  90. return true;
  91. }
  92. public void Reset()
  93. {
  94. this.fade_status_ = WfScreenChildren.FadeStatus.Null;
  95. }
  96. protected abstract void OnCall();
  97. protected virtual bool IsCallFadeIn()
  98. {
  99. return true;
  100. }
  101. public void SetCallInFadeWaitFrame(int frame)
  102. {
  103. this.call_fadein_wait_ = frame;
  104. }
  105. protected virtual void OnFinish()
  106. {
  107. }
  108. protected virtual void OnFadeEnd()
  109. {
  110. }
  111. public virtual bool Finish()
  112. {
  113. if (this.fade_status_ != WfScreenChildren.FadeStatus.Wait)
  114. {
  115. Debug.LogWarning("Finish呼び出し\nフェード状態は" + this.fade_status_.ToString() + "なのでキャンセルされました");
  116. return false;
  117. }
  118. this.FadeOut();
  119. return true;
  120. }
  121. public void SetFadeTime(float time)
  122. {
  123. this.fade_time_ = time;
  124. }
  125. protected void SetFadeStatus(WfScreenChildren.FadeStatus status)
  126. {
  127. this.fade_status_ = status;
  128. }
  129. protected virtual void FadeIn()
  130. {
  131. GameMain.Instance.MainCamera.FadeIn(this.fade_time_, false, null, true, true, default(Color));
  132. if (GameMain.Instance.MainCamera.IsFadeProc())
  133. {
  134. this.fade_status_ = WfScreenChildren.FadeStatus.FadeIn;
  135. }
  136. else
  137. {
  138. this.fade_status_ = WfScreenChildren.FadeStatus.Wait;
  139. }
  140. }
  141. protected virtual void FadeOut()
  142. {
  143. GameMain.Instance.MainCamera.FadeOut(this.fade_time_, false, null, true, default(Color));
  144. if (GameMain.Instance.MainCamera.IsFadeProc())
  145. {
  146. this.fade_status_ = WfScreenChildren.FadeStatus.FadeOut;
  147. }
  148. else
  149. {
  150. this.fade_status_ = WfScreenChildren.FadeStatus.FadeEnd;
  151. this.OnFinish();
  152. }
  153. }
  154. public virtual void LateUpdate()
  155. {
  156. if (!this.awake_init_)
  157. {
  158. if (!this.awake_active_)
  159. {
  160. this.root_obj_.SetActive(false);
  161. }
  162. this.awake_init_ = true;
  163. }
  164. }
  165. public bool init_finishied
  166. {
  167. get
  168. {
  169. return this.awake_init_;
  170. }
  171. }
  172. public GameObject root_obj
  173. {
  174. get
  175. {
  176. return this.root_obj_;
  177. }
  178. }
  179. public float fade_time
  180. {
  181. get
  182. {
  183. return this.fade_time_;
  184. }
  185. }
  186. public WfScreenManager parent_mgr { get; set; }
  187. public WfScreenChildren.FadeStatus fade_status
  188. {
  189. get
  190. {
  191. return this.fade_status_;
  192. }
  193. }
  194. [SerializeField]
  195. public GameObject RootPanel;
  196. private bool awake_active_;
  197. private bool awake_init_;
  198. private GameObject root_obj_;
  199. private float fade_time_ = 0.5f;
  200. private WfScreenChildren.FadeStatus fade_status_;
  201. private int call_fadein_wait_;
  202. private int cur_call_fadein_wait_;
  203. public enum FadeStatus
  204. {
  205. Null,
  206. FadeInWait,
  207. FadeIn,
  208. Wait,
  209. FadeOut,
  210. FadeEnd
  211. }
  212. }