BasePanelMgr.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. using System;
  2. using com.workman.cm3d2.scene.dailyEtc;
  3. using UnityEngine;
  4. public abstract class BasePanelMgr : MonoBehaviour
  5. {
  6. public abstract void Init();
  7. public void SetDurationToFadeIn(float duration)
  8. {
  9. this.durationToFadeIn_ = duration;
  10. }
  11. public void SetDurationToFadeOut(float duration)
  12. {
  13. this.durationToFadeOut_ = duration;
  14. }
  15. protected virtual void SetFadeTargetPanel()
  16. {
  17. }
  18. protected virtual void OpenPanel()
  19. {
  20. }
  21. protected virtual void OpenPanel(string openType)
  22. {
  23. }
  24. protected virtual void ClosePanel()
  25. {
  26. }
  27. protected virtual void BeforeFadeOut()
  28. {
  29. }
  30. protected virtual void BeforeFadeIn()
  31. {
  32. }
  33. private float durationToFadeIn
  34. {
  35. get
  36. {
  37. return this.durationToFadeIn_;
  38. }
  39. }
  40. private float durationToFadeOut
  41. {
  42. get
  43. {
  44. return this.durationToFadeOut_;
  45. }
  46. }
  47. protected virtual void Start()
  48. {
  49. GameObject f_goParent = GameObject.Find("/UI Root");
  50. GameObject childObject = UTY.GetChildObject(f_goParent, "Manager", false);
  51. if (childObject != null)
  52. {
  53. this.sceneMgr = childObject.GetComponent<SceneMgr>();
  54. }
  55. this.SetDurationToFadeIn(0.25f);
  56. this.SetDurationToFadeOut(0.25f);
  57. this.ChangeFadeState(BasePanelMgr.FadeState.None);
  58. }
  59. private void ChangeFadeState(BasePanelMgr.FadeState fadeState)
  60. {
  61. this.currentFadeState = fadeState;
  62. }
  63. protected T GetManager<T>() where T : BasePanelMgr
  64. {
  65. return this.sceneMgr.GetManager<T>();
  66. }
  67. public void BaseInit()
  68. {
  69. this.Init();
  70. this.SetFadeTargetPanel();
  71. }
  72. public void BaseOpenPanel()
  73. {
  74. this.BeforeOpen();
  75. BasePanelMgr.isOpen = true;
  76. this.OpenPanel();
  77. this.FadeInPanel();
  78. }
  79. public void BaseOpenPanel(string openType)
  80. {
  81. this.BeforeOpen();
  82. BasePanelMgr.isOpen = true;
  83. this.OpenPanel(openType);
  84. this.FadeInPanel();
  85. }
  86. public void BaseClosePanel()
  87. {
  88. this.BeforeClose();
  89. BasePanelMgr.isOpen = false;
  90. this.ClosePanel();
  91. this.FadeOutPanel();
  92. }
  93. public void BaseClosePanel(Action OnFinished)
  94. {
  95. this.BeforeClose();
  96. BasePanelMgr.isOpen = false;
  97. this.ClosePanel();
  98. this.FadeOutPanel(OnFinished);
  99. }
  100. public void BaseClosePanel<T>(Action<T> OnFinished, T param)
  101. {
  102. this.BeforeClose();
  103. BasePanelMgr.isOpen = false;
  104. this.ClosePanel();
  105. this.FadeOutPanel<T>(OnFinished, param);
  106. }
  107. protected void FadeInPanel()
  108. {
  109. this.fadeTargetPanel.SetActive(true);
  110. this.BeforeFadeIn();
  111. this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeIn);
  112. TweenAlpha tweenAlpha = this.fadeTargetPanel.GetComponent<TweenAlpha>();
  113. if (tweenAlpha)
  114. {
  115. UnityEngine.Object.Destroy(tweenAlpha);
  116. }
  117. if (this.durationToFadeIn <= 0f)
  118. {
  119. UIRect uirect = this.fadeTargetPanel.GetComponent<UIRect>();
  120. SpriteRenderer component = this.fadeTargetPanel.GetComponent<SpriteRenderer>();
  121. Material material = null;
  122. if (uirect == null && component == null)
  123. {
  124. Renderer component2 = this.fadeTargetPanel.GetComponent<Renderer>();
  125. if (component2 != null)
  126. {
  127. material = component2.material;
  128. }
  129. if (material == null)
  130. {
  131. uirect = this.fadeTargetPanel.GetComponentInChildren<UIRect>();
  132. }
  133. }
  134. float num = 1f;
  135. if (uirect != null)
  136. {
  137. uirect.alpha = num;
  138. }
  139. else if (component != null)
  140. {
  141. Color color = component.color;
  142. color.a = num;
  143. component.color = color;
  144. }
  145. else if (material != null)
  146. {
  147. Color color2 = material.color;
  148. color2.a = num;
  149. material.color = color2;
  150. }
  151. this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeIn);
  152. this.AfterFadeIn();
  153. return;
  154. }
  155. tweenAlpha = this.fadeTargetPanel.AddComponent<TweenAlpha>();
  156. tweenAlpha.from = 0f;
  157. tweenAlpha.to = 1f;
  158. tweenAlpha.duration = this.durationToFadeIn;
  159. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  160. {
  161. this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeIn);
  162. this.AfterFadeIn();
  163. });
  164. tweenAlpha.PlayForward();
  165. }
  166. protected void FadeOutPanel()
  167. {
  168. this.BeforeFadeOut();
  169. this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeOut);
  170. if (this.durationToFadeOut <= 0f)
  171. {
  172. UIRect uirect = this.fadeTargetPanel.GetComponent<UIRect>();
  173. SpriteRenderer component = this.fadeTargetPanel.GetComponent<SpriteRenderer>();
  174. Material material = null;
  175. if (uirect == null && component == null)
  176. {
  177. Renderer component2 = this.fadeTargetPanel.GetComponent<Renderer>();
  178. if (component2 != null)
  179. {
  180. material = component2.material;
  181. }
  182. if (material == null)
  183. {
  184. uirect = this.fadeTargetPanel.GetComponentInChildren<UIRect>();
  185. }
  186. }
  187. float num = 0f;
  188. if (uirect != null)
  189. {
  190. uirect.alpha = num;
  191. }
  192. else if (component != null)
  193. {
  194. Color color = component.color;
  195. color.a = num;
  196. component.color = color;
  197. }
  198. else if (material != null)
  199. {
  200. Color color2 = material.color;
  201. color2.a = num;
  202. material.color = color2;
  203. }
  204. this.fadeTargetPanel.SetActive(false);
  205. this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
  206. this.AfterFadeOut();
  207. return;
  208. }
  209. TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, this.durationToFadeOut, 0f);
  210. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  211. {
  212. this.fadeTargetPanel.SetActive(false);
  213. this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
  214. this.AfterFadeOut();
  215. });
  216. }
  217. protected void FadeOutPanel(Action OnFinished)
  218. {
  219. this.BeforeFadeOut();
  220. this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeOut);
  221. TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, this.durationToFadeOut, 0f);
  222. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  223. {
  224. this.fadeTargetPanel.SetActive(false);
  225. this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
  226. this.AfterFadeOut();
  227. OnFinished();
  228. });
  229. }
  230. protected void FadeOutPanel<T>(Action<T> OnFinished, T param)
  231. {
  232. this.BeforeFadeOut();
  233. this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeOut);
  234. TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, this.durationToFadeOut, 0f);
  235. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  236. {
  237. this.fadeTargetPanel.SetActive(false);
  238. this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
  239. this.AfterFadeOut();
  240. OnFinished(param);
  241. });
  242. }
  243. protected virtual void AfterFadeIn()
  244. {
  245. this.AfterOpen();
  246. }
  247. protected virtual void AfterFadeOut()
  248. {
  249. this.AfterClose();
  250. }
  251. protected virtual void BeforeOpen()
  252. {
  253. }
  254. protected virtual void AfterOpen()
  255. {
  256. }
  257. protected virtual void BeforeClose()
  258. {
  259. }
  260. protected virtual void AfterClose()
  261. {
  262. }
  263. public static bool IsOpen()
  264. {
  265. return BasePanelMgr.isOpen;
  266. }
  267. protected GameObject fadeTargetPanel;
  268. protected SceneMgr sceneMgr;
  269. protected BasePanelMgr.FadeState currentFadeState;
  270. private float durationToFadeIn_;
  271. private float durationToFadeOut_;
  272. private const string uiRootPath = "/UI Root";
  273. private const float DURATION_TO_FADE = 0.25f;
  274. protected static bool isOpen;
  275. public enum FadeState
  276. {
  277. None,
  278. StartFadeIn,
  279. EndFadeIn,
  280. StartFadeOut,
  281. EndFadeOut
  282. }
  283. }