LevelBlock.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using CIS;
  5. using UnityEngine;
  6. public class LevelBlock : MonoBehaviour, ILevelBlock
  7. {
  8. public virtual void OnActive()
  9. {
  10. base.gameObject.SetActive(true);
  11. Component[] componentsInChildren = base.gameObject.GetComponentsInChildren(typeof(ILevelItem));
  12. foreach (Component component in componentsInChildren)
  13. {
  14. this.items.Add((ILevelItem)component, (ILevelItem)component);
  15. }
  16. this.checkpoints = new List<LevelCheckPoint>(base.gameObject.GetComponentsInChildren<LevelCheckPoint>());
  17. foreach (LevelCheckPoint levelCheckPoint in this.checkpoints)
  18. {
  19. levelCheckPoint.levelBlock = this;
  20. }
  21. this.checkpoints = (from x in this.checkpoints
  22. orderby x.index
  23. select x).ToList<LevelCheckPoint>();
  24. this.isActive = true;
  25. }
  26. public virtual void OnDeactive()
  27. {
  28. this.items.Clear();
  29. this.checkpoints.Clear();
  30. base.gameObject.SetActive(false);
  31. this.isActive = false;
  32. }
  33. public virtual void OnEnter()
  34. {
  35. this.isEntered = true;
  36. foreach (KeyValuePair<ILevelItem, ILevelItem> keyValuePair in this.items)
  37. {
  38. keyValuePair.Value.OnEntertBlock(this);
  39. }
  40. }
  41. public virtual void OnLeave()
  42. {
  43. this.isEntered = false;
  44. foreach (KeyValuePair<ILevelItem, ILevelItem> keyValuePair in this.items)
  45. {
  46. keyValuePair.Value.OnLeaveBlock(this);
  47. }
  48. }
  49. public virtual void OnReset()
  50. {
  51. foreach (KeyValuePair<ILevelItem, ILevelItem> keyValuePair in this.items)
  52. {
  53. keyValuePair.Value.OnReset();
  54. }
  55. }
  56. public virtual void OnPause(bool isPause)
  57. {
  58. foreach (KeyValuePair<ILevelItem, ILevelItem> keyValuePair in this.items)
  59. {
  60. keyValuePair.Value.OnPause(isPause);
  61. }
  62. }
  63. public virtual void RegisterPlayer(IPlayerController playerController)
  64. {
  65. ILevelItem levelItem = (ILevelItem)playerController.GameObject.GetComponent(typeof(ILevelItem));
  66. if (!this.items.ContainsKey(levelItem))
  67. {
  68. this.items.Add(levelItem, levelItem);
  69. }
  70. }
  71. public virtual void UnRegisterPlayer(IPlayerController playerController)
  72. {
  73. ILevelItem key = (ILevelItem)playerController.GameObject.GetComponent(typeof(ILevelItem));
  74. if (this.items.ContainsKey(key))
  75. {
  76. this.items.Remove(key);
  77. }
  78. }
  79. public virtual void SetupFirtBlock()
  80. {
  81. if (this.checkpoints.Count == 0)
  82. {
  83. UnityEngine.Debug.LogError("Checkpoint not found!");
  84. return;
  85. }
  86. IPlayerController playerController = SingletonMonoBehaviourClass<GameLogicMgr>.instance.playerController;
  87. LevelCheckPoint levelCheckPoint = this.checkpoints[0];
  88. playerController.SetRespawnPoint(levelCheckPoint.transform.position);
  89. playerController.GameObject.transform.position = levelCheckPoint.transform.position;
  90. float z = SingletonMonoBehaviourClass<GameLogicMgr>.instance.cameraController.GetGO().transform.position.z;
  91. SingletonMonoBehaviourClass<GameLogicMgr>.instance.cameraController.GetGO().transform.position = new Vector3(levelCheckPoint.transform.position.x, levelCheckPoint.transform.position.y, z);
  92. SingletonMonoBehaviourClass<GameLogicMgr>.instance.cameraController.SetCurrentPos(levelCheckPoint.transform.position.x, levelCheckPoint.transform.position.y);
  93. }
  94. public virtual GameObject GetGo()
  95. {
  96. return base.gameObject;
  97. }
  98. public virtual void OnPickingTime(float time)
  99. {
  100. }
  101. public bool IsActive()
  102. {
  103. return this.isActive;
  104. }
  105. public bool IsEntered()
  106. {
  107. return this.isEntered;
  108. }
  109. public int index;
  110. public LevelBlock previous;
  111. public LevelBlock next;
  112. public GameSection section;
  113. private bool isActive;
  114. private bool isEntered;
  115. protected Dictionary<ILevelItem, ILevelItem> items = new Dictionary<ILevelItem, ILevelItem>();
  116. protected List<LevelCheckPoint> checkpoints;
  117. }