123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 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<PersonSystemBase> subPersonSystemList = new List<PersonSystemBase>();
- protected List<SystemBase> subSystemList = new List<SystemBase>();
- //public virtual void AddSubSystems() {
- // Debug.Log("[" + GetType().ToString() + "]: " + "AddSubSystems:");
- //}
- /// <summary>
- /// 子系统加入的方法
- /// </summary>
- /// <param name="subSystem"></param>
- 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;
- }
- /// <summary>
- /// 子系统移除的方法
- /// </summary>
- /// <param name="subSystem"></param>
- public void RemoveSubSystem(PersonSystemBase subPersonSystem) {
- if (subPersonSystem == null) {
- Debug.Log("Error: ========= subSystem Null");
- return;
- }
- subPersonSystemList.Remove(subPersonSystem);
- subPersonSystem.parentSystem = null;
- }
- /// <summary>
- /// 子系统加入的方法
- /// </summary>
- /// <param name="subSystem"></param>
- 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);
- }
- /// <summary>
- /// 子系统移除的方法
- /// </summary>
- /// <param name="subSystem"></param>
- 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");
- }
- }
|