/// <summary> /// This method will add an initialize sub to this main, doesnt need to be a component. /// This method is implemented through IInitializeMain. /// </summary> /// <param name="sub">The sub that is to be added.</param> /// <param name="priority">The priority of the sub.</param> /// <param name="inInspector">Just let this be with the default value.</param> /// <param name="args">The value to be send to the Init method in the sub.</param> public virtual void AddInitializeSub(IInitializeSub sub, int priority, bool inInspector = false, object args = null) { if (inInspector) { if (startingSubs.Count < priority) { startingSubs.Add((Component)sub); } else { startingSubs.Insert(priority - 1, (Component)sub); } } else { if (subsToAdd.Count < priority) { subsToAdd.Add(sub); } else { subsToAdd.Insert(priority - 1, sub); } sub.Initialize(sceneObserver); sub.Init(args); } }
/// <summary> /// This method is called right before Init and is implemented through the IInitialize interface, only let the system call this method /// </summary> /// <param name="sceneObserver">The observer this was build with.</param> public void Initialize(SceneObserver sceneObserver) { thisIsMe = (T)this; scene = sceneObserver.Scene; instanceID = GetInstanceID(); this.sceneObserver = sceneObserver; subsToAdd = new List <IInitializeSub>(); subsToRemove = new List <IInitializeSub>(); initializeSubs = new List <IInitializeSub>(); for (int i = 0; i < startingSubs.Count; i++) { IInitializeSub sub = (IInitializeSub)startingSubs[i]; sub.Initialize(sceneObserver); sub.Init(this); initializeSubs.Add(sub); } startingSubs.Clear(); }