using System.Collections.Generic; namespace PhxhSDK { public class SubSystemManager : IUpdatable, IInitable, IStart, IOnApplicationPause { private readonly List _appPauseList = new(4); private readonly List _initables = new(8); private readonly List _startables = new(4); private readonly List _updateList = new(4); public void Init() { } public void Release() { for (var i = _initables.Count - 1; i >= 0; i--) { var initable = _initables[i]; initable.Release(); } _updateList.Clear(); } public void OnApplicationPause(bool pauseStatus) { foreach (var appPause in _appPauseList) appPause.OnApplicationPause(pauseStatus); } public void Start() { foreach (var st in _startables) st.Start(); } public void Update(float deltaTime) { foreach (var updatable in _updateList) updatable.Update(deltaTime); } public void AddSubSystem() where T : class, new() { // if T is subclass of Singleton, use Instance instead of new T subSystem = null; if (typeof(T).IsSubclassOf(typeof(Singlenton))) subSystem = Singlenton.Instance; else subSystem = new T(); var initable = subSystem as IInitable; if (initable != null) { initable.Init(); _initables.Add(initable); } var startable = subSystem as IStart; if (startable != null) _startables.Add(startable); var globalObj = subSystem as IGlobal; if (globalObj != null) globalObj.ToGlobal(); var updatable = subSystem as IUpdatable; if (updatable != null) _updateList.Add(updatable); var appPause = subSystem as IOnApplicationPause; if (appPause != null) _appPauseList.Add(appPause); } } }