using SC.Tools; using System.Collections.Generic; using UnityEngine; public abstract class SystemBase : MonoBehaviour { internal bool isRun = true; internal PersonSystemBase parentPersonSystem; internal SystemBase parentSystem; protected List subPersonSystemList = new List(); protected List subSystemList = new List(); //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.parentSystem = this; } /// /// 子系统移除的方法 /// /// public void RemoveSubSystem(PersonSystemBase subPersonSystem) { if (subPersonSystem == null) { Debug.Log("Error: ========= subSystem Null"); return; } subPersonSystemList.Remove(subPersonSystem); subPersonSystem.parentSystem = 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.parentSystem = this; subSystem.gameObject.SetActive(true); subSystem.transform.SetParent(transform, false); } /// /// 子系统移除的方法 /// /// public void RemoveSubSystem(SystemBase subSystem) { if (subSystem == null) { Debug.Log("Error: ========= subSystem Null"); return; } subSystemList.Remove(subSystem); subSystem.parentSystem = null; DestroyImmediate(subSystem); } public virtual void SystemStart() { foreach (var item in subPersonSystemList) { item.SystemStart(); } foreach (var item in subSystemList) { item.SystemStart(); } isRun = true; gameObject.SetActive(true); Debug.Log("[" + GetType().ToString() + "]: " + "SystemStart"); } public virtual void SystemStop() { foreach (var item in subPersonSystemList) { item.SystemStop(); } foreach (var item in subSystemList) { item.SystemStop(); } gameObject.SetActive(false); isRun = false; Debug.Log("[" + GetType().ToString() + "]: " + "SystemStop"); } //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"); } }