GameSection.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using CIS;
  5. using UnityEngine;
  6. public class GameSection : MonoBehaviour
  7. {
  8. protected void Awake()
  9. {
  10. this.FindCameraBoderByDefinedName(this.resourceNode);
  11. this.SetupBlocks(this.resourceNode);
  12. }
  13. protected void Start()
  14. {
  15. this.logicMgr = SingletonMonoBehaviourClass<GameLogicMgr>.instance;
  16. }
  17. protected void SetupBlocks(GameObject target)
  18. {
  19. LevelBlock[] componentsInChildren = target.GetComponentsInChildren<LevelBlock>(true);
  20. this.levelBlocks = new List<LevelBlock>(componentsInChildren);
  21. this.levelBlocks = (from x in this.levelBlocks
  22. orderby x.index
  23. select x).ToList<LevelBlock>();
  24. for (int i = 0; i < this.levelBlocks.Count; i++)
  25. {
  26. this.levelBlocks[i].section = this;
  27. if (i == 0)
  28. {
  29. this.levelBlocks[i].next = ((this.levelBlocks.Count <= 1) ? null : this.levelBlocks[1]);
  30. this.levelBlocks[i].previous = null;
  31. }
  32. else if (i == this.levelBlocks.Count - 1)
  33. {
  34. this.levelBlocks[i].next = null;
  35. this.levelBlocks[i].previous = this.levelBlocks[i - 1];
  36. }
  37. else
  38. {
  39. this.levelBlocks[i].next = this.levelBlocks[i + 1];
  40. this.levelBlocks[i].previous = this.levelBlocks[i - 1];
  41. }
  42. }
  43. }
  44. public virtual void SetupFirtBlock()
  45. {
  46. if (this.currBlock != null)
  47. {
  48. this.currBlock.SetupFirtBlock();
  49. }
  50. }
  51. public virtual void OnSectionLeave(GameSection section)
  52. {
  53. this.SetCurrentBlock(null);
  54. }
  55. public virtual LevelBlock GetBlock(int index)
  56. {
  57. if (index < 0)
  58. {
  59. return null;
  60. }
  61. if (index < this.levelBlocks.Count)
  62. {
  63. return this.levelBlocks[index];
  64. }
  65. return null;
  66. }
  67. public virtual void OnSectionReset()
  68. {
  69. if (this.currBlock != null)
  70. {
  71. this.currBlock.OnReset();
  72. StoryE11P6.OnShiPlayerDie();
  73. }
  74. }
  75. public virtual void OnSectionPause(bool pause)
  76. {
  77. if (this.currBlock != null)
  78. {
  79. this.currBlock.OnPause(pause);
  80. }
  81. }
  82. public virtual void OnSectionEnter(GameSection section)
  83. {
  84. this.SetCameraBoundary();
  85. if (this.levelBlocks.Count > 0)
  86. {
  87. this.SetCurrentBlock(this.levelBlocks[0]);
  88. }
  89. }
  90. public virtual void Update()
  91. {
  92. }
  93. public virtual void SetCurrentBlock(LevelBlock block)
  94. {
  95. if (block != null)
  96. {
  97. this.currBlock = block;
  98. if (!block.IsActive())
  99. {
  100. block.OnActive();
  101. }
  102. if (!block.IsEntered())
  103. {
  104. block.OnEnter();
  105. }
  106. if (block.previous != null)
  107. {
  108. if (block.previous.IsEntered())
  109. {
  110. block.previous.OnLeave();
  111. }
  112. block.previous.UnRegisterPlayer(SingletonMonoBehaviourClass<GameLogicMgr>.instance.playerController);
  113. if (block.previous.previous != null && block.previous.previous.IsActive())
  114. {
  115. block.previous.previous.OnDeactive();
  116. }
  117. }
  118. block.RegisterPlayer(SingletonMonoBehaviourClass<GameLogicMgr>.instance.playerController);
  119. if (block.next != null)
  120. {
  121. if (block.previous == null && !block.next.IsActive())
  122. {
  123. block.next.OnActive();
  124. }
  125. if (block.next.next != null && !block.next.next.IsActive())
  126. {
  127. block.next.next.OnActive();
  128. }
  129. }
  130. }
  131. else if (this.currBlock != null && this.currBlock.IsEntered())
  132. {
  133. this.currBlock.OnLeave();
  134. }
  135. }
  136. public virtual void OnSectionSkip()
  137. {
  138. }
  139. public void AddBlock(LevelBlock block)
  140. {
  141. this.levelBlocks.Add(block);
  142. }
  143. public void RemoveLevelBlock(LevelBlock block)
  144. {
  145. for (int i = 0; i < this.levelBlocks.Count; i++)
  146. {
  147. if (this.levelBlocks[i] == block)
  148. {
  149. this.levelBlocks.RemoveAt(i);
  150. break;
  151. }
  152. }
  153. }
  154. protected void FindCameraBoderByDefinedName(GameObject resourceNode)
  155. {
  156. this.cameraUpLimitTrans = resourceNode.transform.Find(GameSection.upBorderName);
  157. this.cameraDownLimitTrans = resourceNode.transform.Find(GameSection.downBorderName);
  158. this.cameraRightLimitTrans = resourceNode.transform.Find(GameSection.rightBorderName);
  159. this.cameraLeftLimitTrans = resourceNode.transform.Find(GameSection.leftBorderName);
  160. if (this.cameraUpLimitTrans == null || this.cameraDownLimitTrans == null || this.cameraRightLimitTrans == null || this.cameraLeftLimitTrans == null)
  161. {
  162. UnityEngine.Debug.LogError("camera boundaries can not be null!");
  163. }
  164. }
  165. protected void SetCameraBoundary()
  166. {
  167. ICameraController cameraController = SingletonMonoBehaviourClass<GameLogicMgr>.instance.cameraController;
  168. if (this.cameraUpLimitTrans == null || this.cameraDownLimitTrans == null || this.cameraRightLimitTrans == null || this.cameraLeftLimitTrans == null)
  169. {
  170. UnityEngine.Debug.LogError("camera boundaries can not be null!");
  171. }
  172. if (cameraController == null)
  173. {
  174. UnityEngine.Debug.LogError("camera controller new not found please attatch it to your camera node");
  175. }
  176. cameraController.ReloadLimitBorder(this.cameraUpLimitTrans, this.cameraDownLimitTrans, this.cameraLeftLimitTrans, this.cameraRightLimitTrans);
  177. }
  178. protected GameLogicMgr logicMgr;
  179. protected Transform cameraUpLimitTrans;
  180. protected Transform cameraDownLimitTrans;
  181. protected Transform cameraRightLimitTrans;
  182. protected Transform cameraLeftLimitTrans;
  183. public string sectionName;
  184. public MultiScroller scroller;
  185. public GameObject resourceNode;
  186. public bool isEnd;
  187. protected List<LevelBlock> levelBlocks = new List<LevelBlock>();
  188. protected LevelBlock currBlock;
  189. public static string upBorderName = "upBorder";
  190. public static string downBorderName = "downBorder";
  191. public static string leftBorderName = "leftBorder";
  192. public static string rightBorderName = "rightBorder";
  193. }