PersonSystemBase.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SC.Tools
  5. {
  6. public abstract class PersonSystemBase
  7. {
  8. internal bool isRun = true;
  9. internal PersonSystemBase parentPersonSystem;
  10. internal SystemBase parentSystem;
  11. protected List<PersonSystemBase> subPersonSystemList = new List<PersonSystemBase>();
  12. protected List<SystemBase> subSystemList = new List<SystemBase>();
  13. public PersonSystemBase() {
  14. Awake();
  15. }
  16. //public virtual void AddSubSystems() {
  17. // Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystems:");
  18. //}
  19. /// <summary>
  20. /// 子系统加入的方法
  21. /// </summary>
  22. /// <param name="subSystem"></param>
  23. public void AddSubSystem(PersonSystemBase subPersonSystem) {
  24. if (subPersonSystem == null) {
  25. Debug.Log("Error: ========= subSystem Null");
  26. return;
  27. }
  28. Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystem:" + subPersonSystem);
  29. subPersonSystemList.Add(subPersonSystem);
  30. subPersonSystem.parentPersonSystem = this;
  31. }
  32. /// <summary>
  33. /// 子系统移除的方法
  34. /// </summary>
  35. /// <param name="subSystem"></param>
  36. public void RemoveSubSystem(PersonSystemBase subPersonSystem) {
  37. if (subPersonSystem == null) {
  38. Debug.Log("Error: ========= subSystem Null");
  39. return;
  40. }
  41. subPersonSystemList.Remove(subPersonSystem);
  42. subPersonSystem.parentPersonSystem = null;
  43. }
  44. /// <summary>
  45. /// 子系统加入的方法
  46. /// </summary>
  47. /// <param name="subSystem"></param>
  48. public void AddSubSystem(SystemBase subSystem) {
  49. if (subSystem == null) {
  50. Debug.Log("Error: ========= subSystem Null");
  51. return;
  52. }
  53. Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystem:" + subSystem.name);
  54. subSystemList.Add(subSystem);
  55. subSystem.parentPersonSystem = this;
  56. subSystem.gameObject.SetActive(true);
  57. }
  58. /// <summary>
  59. /// 子系统移除的方法
  60. /// </summary>
  61. /// <param name="subSystem"></param>
  62. public void RemoveSubSystem(SystemBase subSystem) {
  63. if (subSystem == null) {
  64. Debug.Log("Error: ========= subSystem Null");
  65. return;
  66. }
  67. subSystemList.Remove(subSystem);
  68. subSystem.parentPersonSystem = null;
  69. GameObject.DestroyImmediate(subSystem);
  70. }
  71. public virtual void SystemStart() {
  72. foreach (var item in subPersonSystemList) {
  73. item.SystemStart();
  74. }
  75. foreach (var item in subSystemList) {
  76. item.SystemStart();
  77. }
  78. Debug.Log("[" + GetType().ToString() + "]: " + "SystemStart");
  79. isRun = true;
  80. }
  81. public virtual void SystemStop() {
  82. foreach (var item in subPersonSystemList) {
  83. item.SystemStop();
  84. }
  85. foreach (var item in subSystemList) {
  86. item.SystemStop();
  87. }
  88. Debug.Log("[" + GetType().ToString() + "]: " + "SystemStop");
  89. OnDisable();
  90. isRun = false;
  91. }
  92. //public virtual void Action() {
  93. // if (!isRun)
  94. // return;
  95. // foreach (var item in subPersonSystemList) {
  96. // item.Action();
  97. // }
  98. // foreach (var item in subSystemList) {
  99. // item.Action();
  100. // }
  101. // Debug.Log("[" + GetType().ToString() + "]: " + "Action");
  102. //}
  103. public virtual void Awake() {
  104. if (!isRun)
  105. return;
  106. foreach (var item in subPersonSystemList) {
  107. item.Awake();
  108. }
  109. Debug.Log("[" + GetType().ToString() + "]: " + "Awake");
  110. }
  111. public virtual void OnEnable() {
  112. if (!isRun)
  113. return;
  114. foreach (var item in subPersonSystemList) {
  115. item.OnEnable();
  116. }
  117. Debug.Log("[" + GetType().ToString() + "]: " + "OnEnable");
  118. }
  119. public virtual void Start() {
  120. if (!isRun)
  121. return;
  122. foreach (var item in subPersonSystemList) {
  123. item.Start();
  124. }
  125. Debug.Log("[" + GetType().ToString() + "]: " + "Start");
  126. }
  127. public virtual void Update() {
  128. if (!isRun)
  129. return;
  130. foreach (var item in subPersonSystemList) {
  131. item.Update();
  132. }
  133. }
  134. public virtual void LateUpdate() {
  135. if (!isRun)
  136. return;
  137. foreach (var item in subPersonSystemList) {
  138. item.LateUpdate();
  139. }
  140. }
  141. public virtual void OnDisable() {
  142. if (!isRun)
  143. return;
  144. foreach (var item in subPersonSystemList) {
  145. item.OnDisable();
  146. }
  147. Debug.Log("[" + GetType().ToString() + "]: " + "OnDisable");
  148. }
  149. public virtual void OnDestroy() {
  150. if (!isRun)
  151. return;
  152. foreach (var item in subPersonSystemList) {
  153. item.OnDestroy();
  154. }
  155. Debug.Log("[" + GetType().ToString() + "]: " + "OnDestroy");
  156. }
  157. }
  158. }