/// <summary> /// Registers the sub component. /// If you want to instantiate a new component manualy but wants window events - register this component here. /// </summary> /// <param name="subComponent">Sub component.</param> public virtual void RegisterSubComponent(WindowObjectElement subComponent) { //Debug.Log("TRY REGISTER: " + subComponent + " :: " + this.GetComponentState() + "/" + subComponent.GetComponentState(), this); if (this.subComponents.Contains(subComponent) == false) { subComponent.rootComponent = this; this.subComponents.Add(subComponent); } else { WindowSystemLogger.Warning(this, "RegisterSubComponent can't complete because of duplicate item."); return; } #if UNITY_EDITOR if (Application.isPlaying == false) { return; } #endif var controller = (subComponent as IWindowEventsController); subComponent.DoLoad(async: false, onItem: null, callback: () => { switch (this.GetComponentState()) { case WindowObjectState.Hiding: if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { controller.DoInit(); WindowSystem.RunSafe(subComponent.OnWindowActive); } subComponent.SetComponentState(this.GetComponentState()); break; case WindowObjectState.Hidden: if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { controller.DoInit(); WindowSystem.RunSafe(subComponent.OnWindowActive); } subComponent.SetComponentState(this.GetComponentState()); break; case WindowObjectState.Initializing: case WindowObjectState.Initialized: if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { controller.DoInit(); WindowSystem.RunSafe(subComponent.OnWindowActive); } break; case WindowObjectState.Showing: // after OnShowBegin if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { controller.DoInit(); WindowSystem.RunSafe(subComponent.OnWindowActive); } if (subComponent.showOnStart == true) { controller.DoShowBegin(AppearanceParameters.Default()); } break; case WindowObjectState.Shown: // after OnShowEnd if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { controller.DoInit(); WindowSystem.RunSafe(subComponent.OnWindowActive); } if (subComponent.showOnStart == true) { controller.DoShowBegin(AppearanceParameters.Default().ReplaceCallback(() => { controller.DoShowEnd(AppearanceParameters.Default()); })); } break; } if (this.GetWindow() != null) { subComponent.Setup(this.GetWindow()); // subComponent.Setup(this.GetLayoutRoot()); } }); }
/// <summary> /// Registers the sub component. /// If you want to instantiate a new component manualy but wants window events - register this component here. /// </summary> /// <param name="subComponent">Sub component.</param> public virtual void RegisterSubComponent(WindowObjectElement subComponent) { //Debug.Log("TRY REGISTER: " + subComponent + " :: " + this.GetComponentState() + "/" + subComponent.GetComponentState(), this); if (this.subComponents.Contains(subComponent) == false) { this.subComponents.Add(subComponent); } else { WindowSystemLogger.Warning(this, "RegisterSubComponent can't complete because of duplicate item."); return; } switch (this.GetComponentState()) { case WindowObjectState.Hiding: if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { subComponent.DoInit(); } subComponent.SetComponentState(this.GetComponentState()); break; case WindowObjectState.Hidden: if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { subComponent.DoInit(); } subComponent.SetComponentState(this.GetComponentState()); break; case WindowObjectState.Initializing: case WindowObjectState.Initialized: if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { subComponent.DoInit(); } break; case WindowObjectState.Showing: // after OnShowBegin if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { subComponent.DoInit(); } if (subComponent.showOnStart == true) { subComponent.DoShowBegin(AppearanceParameters.Default()); } break; case WindowObjectState.Shown: // after OnShowEnd if (subComponent.GetComponentState() == WindowObjectState.NotInitialized) { subComponent.DoInit(); } if (subComponent.showOnStart == true) { subComponent.DoShowBegin(AppearanceParameters.Default().ReplaceCallback(() => { subComponent.DoShowEnd(AppearanceParameters.Default()); })); } break; } if (this.GetWindow() != null) { subComponent.Setup(this.GetWindow()); // subComponent.Setup(this.GetLayoutRoot()); } }