using System; using System.Collections.Generic; using UnityEngine; namespace SC.Tools { public abstract class PersonSystemBase { internal bool isRun = true; internal PersonSystemBase parentPersonSystem; internal SystemBase parentSystem; protected List subPersonSystemList = new List(); protected List subSystemList = new List(); public PersonSystemBase() { Awake(); } //public virtual void AddSubSystems() { // Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystems:"); //} /// /// 子系统加入的方法 /// /// public void AddSubSystem(PersonSystemBase subPersonSystem) { if (subPersonSystem == null) { Debug.Log("Error: ========= subSystem Null"); return; } Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystem:" + subPersonSystem); subPersonSystemList.Add(subPersonSystem); subPersonSystem.parentPersonSystem = this; } /// /// 子系统移除的方法 /// /// public void RemoveSubSystem(PersonSystemBase subPersonSystem) { if (subPersonSystem == null) { Debug.Log("Error: ========= subSystem Null"); return; } subPersonSystemList.Remove(subPersonSystem); subPersonSystem.parentPersonSystem = null; } /// /// 子系统加入的方法 /// /// public void AddSubSystem(SystemBase subSystem) { if (subSystem == null) { Debug.Log("Error: ========= subSystem Null"); return; } Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystem:" + subSystem.name); subSystemList.Add(subSystem); subSystem.parentPersonSystem = this; subSystem.gameObject.SetActive(true); } /// /// 子系统移除的方法 /// /// public void RemoveSubSystem(SystemBase subSystem) { if (subSystem == null) { Debug.Log("Error: ========= subSystem Null"); return; } subSystemList.Remove(subSystem); subSystem.parentPersonSystem = null; GameObject.DestroyImmediate(subSystem); } public virtual void SystemStart() { foreach (var item in subPersonSystemList) { item.SystemStart(); } foreach (var item in subSystemList) { item.SystemStart(); } Debug.Log("[" + GetType().ToString() + "]: " + "SystemStart"); isRun = true; } public virtual void SystemStop() { foreach (var item in subPersonSystemList) { item.SystemStop(); } foreach (var item in subSystemList) { item.SystemStop(); } Debug.Log("[" + GetType().ToString() + "]: " + "SystemStop"); OnDisable(); isRun = false; } //public virtual void Action() { // if (!isRun) // return; // foreach (var item in subPersonSystemList) { // item.Action(); // } // foreach (var item in subSystemList) { // item.Action(); // } // Debug.Log("[" + GetType().ToString() + "]: " + "Action"); //} public virtual void Awake() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.Awake(); } Debug.Log("[" + GetType().ToString() + "]: " + "Awake"); } public virtual void OnEnable() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.OnEnable(); } Debug.Log("[" + GetType().ToString() + "]: " + "OnEnable"); } public virtual void Start() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.Start(); } Debug.Log("[" + GetType().ToString() + "]: " + "Start"); } public virtual void Update() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.Update(); } } public virtual void LateUpdate() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.LateUpdate(); } } public virtual void OnDisable() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.OnDisable(); } Debug.Log("[" + GetType().ToString() + "]: " + "OnDisable"); } public virtual void OnDestroy() { if (!isRun) return; foreach (var item in subPersonSystemList) { item.OnDestroy(); } Debug.Log("[" + GetType().ToString() + "]: " + "OnDestroy"); } } }