GameLogicMgr.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using CIS;
  5. using DG.Tweening;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class GameLogicMgr : SingletonMonoBehaviourClass<GameLogicMgr>
  9. {
  10. public bool IsGameEnd
  11. {
  12. get
  13. {
  14. return this.isGameEnd;
  15. }
  16. }
  17. public void EndPlay()
  18. {
  19. float num = Time.realtimeSinceStartup - this.startTime;
  20. UnityEngine.Debug.Log("totalTime: " + num);
  21. }
  22. public void StartPlay()
  23. {
  24. if (this.startTime < 0f)
  25. {
  26. this.startTime = Time.realtimeSinceStartup;
  27. }
  28. }
  29. public GameSection currGameSection
  30. {
  31. get
  32. {
  33. return this._currGameSection;
  34. }
  35. }
  36. private void Awake()
  37. {
  38. GameSection[] componentsInChildren = base.GetComponentsInChildren<GameSection>(true);
  39. foreach (GameSection gameSection in componentsInChildren)
  40. {
  41. this.gameSectionDic.Add(gameSection.sectionName, gameSection);
  42. }
  43. }
  44. public IEnumerator LoadSectionAsync(string fileName, Action<GameObject> callback)
  45. {
  46. ResourceRequest resourceRequest = Resources.LoadAsync<GameObject>(fileName);
  47. while (!resourceRequest.isDone)
  48. {
  49. yield return 0;
  50. }
  51. GameObject go = (GameObject)resourceRequest.asset;
  52. UnityEngine.Object.Instantiate<GameObject>(go);
  53. if (callback != null)
  54. {
  55. callback(go);
  56. }
  57. yield break;
  58. }
  59. public void LoadSection(string fileName, Action<GameObject> callback)
  60. {
  61. GameObject obj = Resources.Load<GameObject>(fileName);
  62. if (callback != null)
  63. {
  64. callback(obj);
  65. }
  66. }
  67. private void Start()
  68. {
  69. if (this.debug)
  70. {
  71. return;
  72. }
  73. this.playerController = (IPlayerController)this.playerControllerGo.GetComponent(typeof(IPlayerController));
  74. this.cameraController = (ICameraController)this.cameraControllerGo.GetComponent(typeof(ICameraController));
  75. if (!this.gameSectionDic.ContainsKey("first"))
  76. {
  77. UnityEngine.Debug.LogError("First section not found! Must have a 'first' section");
  78. }
  79. GameSection section = this.gameSectionDic["first"];
  80. this.PushSection(section, false);
  81. }
  82. public void ReLoadCurrentSection()
  83. {
  84. }
  85. public void ClearLevelTimeText()
  86. {
  87. this.startTime = -1f;
  88. }
  89. public void RegisterLevelItem(GameSection secion, ILevelItem item)
  90. {
  91. if (secion != null)
  92. {
  93. }
  94. }
  95. public GameSection GetGameSection(string sectionName)
  96. {
  97. if (this.gameSectionDic.ContainsKey(sectionName))
  98. {
  99. return this.gameSectionDic[sectionName];
  100. }
  101. return null;
  102. }
  103. public void GameEnd()
  104. {
  105. this.isGameEnd = true;
  106. if (this._currGameSection != null)
  107. {
  108. this._currGameSection.OnSectionLeave(null);
  109. }
  110. }
  111. public void PushSection(GameSection section, bool needMask = false)
  112. {
  113. if (this.isGameEnd)
  114. {
  115. return;
  116. }
  117. if (section != null && section.isEnd)
  118. {
  119. this.GameEnd();
  120. return;
  121. }
  122. if (this._currGameSection != null)
  123. {
  124. this._currGameSection.OnSectionLeave(section);
  125. if (needMask)
  126. {
  127. SpriteRenderer mask = SingletonMonoBehaviourClass<SHICameraController>.instance.overlayMask;
  128. mask.enabled = true;
  129. Color black = Color.black;
  130. black.a = 0f;
  131. mask.color = black;
  132. mask.DOFade(1f, 0f).OnComplete(delegate
  133. {
  134. mask.DOFade(0f, 2f);
  135. });
  136. }
  137. this._currGameSection = section;
  138. if (!section.isEnd)
  139. {
  140. section.OnSectionEnter(this._currGameSection);
  141. }
  142. }
  143. else
  144. {
  145. this._currGameSection = section;
  146. section.OnSectionEnter(null);
  147. section.SetupFirtBlock();
  148. }
  149. }
  150. public void SkipSection()
  151. {
  152. if (this._currGameSection != null)
  153. {
  154. this._currGameSection.OnSectionSkip();
  155. }
  156. }
  157. public void Pause(bool _isPuase, bool timeScale = false, bool showTutorial = false)
  158. {
  159. this.isPause = _isPuase;
  160. if (showTutorial)
  161. {
  162. this.tutorialSprite.gameObject.SetActive(true);
  163. }
  164. if (_isPuase)
  165. {
  166. if (timeScale)
  167. {
  168. Time.timeScale = 0f;
  169. }
  170. if (showTutorial)
  171. {
  172. SpriteRenderer overlayMask = SingletonMonoBehaviourClass<SHICameraController>.instance.overlayMask;
  173. Color black = Color.black;
  174. black.a = 0f;
  175. overlayMask.color = black;
  176. overlayMask.enabled = true;
  177. overlayMask.DOFade(0.65f, 0.2f).SetUpdate(true);
  178. DOTween.ToAlpha(() => this.tutorialSprite.color, delegate(Color x)
  179. {
  180. this.tutorialSprite.color = x;
  181. }, 1f, 0.2f).SetUpdate(true);
  182. }
  183. }
  184. else if (showTutorial)
  185. {
  186. SpriteRenderer mask = SingletonMonoBehaviourClass<SHICameraController>.instance.overlayMask;
  187. mask.DOFade(0f, 0.2f).SetUpdate(true).OnComplete(delegate
  188. {
  189. mask.enabled = false;
  190. });
  191. DOTween.ToAlpha(() => this.tutorialSprite.color, delegate(Color x)
  192. {
  193. this.tutorialSprite.color = x;
  194. }, 0f, 0.2f).SetUpdate(true).OnComplete(delegate
  195. {
  196. if (timeScale)
  197. {
  198. Time.timeScale = 1f;
  199. }
  200. this.tutorialSprite.gameObject.SetActive(false);
  201. });
  202. }
  203. else if (timeScale)
  204. {
  205. Time.timeScale = 1f;
  206. }
  207. if (this._currGameSection != null)
  208. {
  209. this._currGameSection.OnSectionPause(this.isPause);
  210. }
  211. }
  212. public bool IsPause()
  213. {
  214. return this.isPause;
  215. }
  216. public void Reset()
  217. {
  218. if (this._currGameSection != null)
  219. {
  220. this._currGameSection.OnSectionReset();
  221. }
  222. }
  223. public void ChangePlayerController(GameObject playerGo)
  224. {
  225. this.playerControllerGo = playerGo;
  226. this.playerController = (IPlayerController)this.playerControllerGo.GetComponent(typeof(IPlayerController));
  227. if (this.playerControllerGo == null || this.playerController == null)
  228. {
  229. UnityEngine.Debug.LogError("failed to change player controller");
  230. }
  231. }
  232. private GameSection _currGameSection;
  233. public GameObject playerControllerGo;
  234. public IPlayerController playerController;
  235. public GameObject cameraControllerGo;
  236. public ICameraController cameraController;
  237. public Image tutorialSprite;
  238. private bool isPause;
  239. private bool isGameEnd;
  240. private Hashtable sectionMap = new Hashtable();
  241. private Dictionary<string, GameSection> gameSectionDic = new Dictionary<string, GameSection>();
  242. private float startTime = -1f;
  243. public bool debug;
  244. }