public static void ProvideUISystem(UISystemBase uiSystem) { m_uiSystem = uiSystem; }
/// <summary> /// Updates the initialization process. /// </summary> private void UpdateInitState() { switch (m_initState) { case InitState.NONE: AdvanceInitState(); break; case InitState.INIT_SHARED_SYSTEMS: // Get references to the shared systems m_uiSystem = this.gameObject.AddDerivedIfNoBase <UISystemBase, UISystem>(); m_soundSystem = this.gameObject.AddDerivedIfNoBase <SoundSystemBase, SoundSystem>(); m_dataSystem = new DataSystem(); // Initialize shared systems m_uiSystem.Initialize(); m_soundSystem.Initialize(); m_dataSystem.Initialize(); #if SHOW_STATE_LOGS Debug.Log("Initializing shared systems..."); #endif AdvanceInitState(); break; case InitState.WAIT_INIT_SHARED_SYSTEMS: // Wait for shared systems to finish initialization #if SHOW_STATE_LOGS Debug.Log("Waiting for shared system initialization to finish..."); #endif if (m_uiSystem.IsInitialized && m_soundSystem.IsInitialized && m_dataSystem.IsInitialized) { AdvanceInitState(); } break; // TODO: Temporary state - should be moved to different classes case InitState.CREATE_SHARED_OBJECTS: #if SHOW_STATE_LOGS Debug.Log("Creating shared objects..."); #endif CreateSharedObjects(); AdvanceInitState(); break; case InitState.INIT_LOCATOR: #if SHOW_STATE_LOGS Debug.Log("Initializing Service Locator..."); #endif Locator.ProvideUISystem(m_uiSystem); Locator.ProvideSoundSystem(m_soundSystem); Locator.ProvideDataSystem(m_dataSystem); // If game is loaded from the Main scene (index 0) if (Application.loadedLevel == 0) { AdvanceInitState(); } // If game is loaded from a different scene else { // No need to load a different scene // Just load the SceneMaster m_initState = InitState.LOAD_SCENE_MASTER; } break; // The following states are cycled through whenever scenes are switched case InitState.LOAD_SCENE: #if SHOW_STATE_LOGS Debug.Log("Loading scene..."); #endif // Block input while next scene is loading m_faderUI.SetBlockInput(); StartLoading(m_sceneInfo.GetSceneNameOf(m_nextScene)); AdvanceInitState(); break; case InitState.WAIT_LOAD_SCENE: // Wait for scene to finish loading in the background #if SHOW_STATE_LOGS Debug.Log("Waiting for scene to load in the background..."); #endif if (m_async != null && m_async.progress >= READY_TO_LOAD_PROGRESS) { // Start fade out if (m_enableFadeAnim) { m_faderUI.FadeOut(true); } AdvanceInitState(); } break; case InitState.UNLOAD_CUR_SCENE: // If starting from Main scene, there will be nothing to unload #if SHOW_STATE_LOGS Debug.Log("Unloading current scene..."); #endif if (Application.loadedLevel == 0 || m_sceneMaster.Unload()) { AdvanceInitState(); } break; case InitState.WAIT_UNLOAD_CUR_SCENE: // If starting from Main scene, there will be nothing to unload #if SHOW_STATE_LOGS Debug.Log("Waiting for current scene to finish unloading..."); #endif if (Application.loadedLevel == 0 || !m_sceneMaster.IsInitialized) { // If scene fading is enabled, wait for scene to fade out first if (!m_enableFadeAnim || (m_enableFadeAnim && m_faderUI.FaderState == FaderUI.FadeAnimationState.FADED_OUT)) { // Clean up non-persistent sounds m_soundSystem.DeleteAllSoundObjects(false); AdvanceInitState(); } } break; case InitState.SWITCH_SCENE: // Load the next scene #if SHOW_STATE_LOGS Debug.Log("Switching scene..."); #endif ActivateScene(); // Initialization will continue in OnLevelWasLoaded break; case InitState.LOAD_SCENE_MASTER: #if SHOW_STATE_LOGS Debug.Log("Loading scene master in scene " + Application.loadedLevelName); #endif if (m_sceneMaster.Load()) { // Provide SceneMaster to the service locator Locator.ProvideSceneMaster(m_sceneMaster); AdvanceInitState(); } break; case InitState.WAIT_LOAD_SCENE_MASTER: #if SHOW_STATE_LOGS Debug.Log("Waiting for scene master to load..."); #endif if (m_sceneMaster.IsInitialized) { // Start fade in if (m_enableFadeAnim) { m_faderUI.FadeIn(); } AdvanceInitState(); } break; case InitState.DONE: #if SHOW_STATE_LOGS if (BuildInfo.IsDebugMode) { Debug.Log("Main initialization complete"); } #endif // Switch to IDLE state // If the SceneMaster switches the scene, this state change will be overridden AdvanceInitState(); // Update scene enum for the current scene m_curScene = m_nextScene; // Start the scene - pass control over to the active scene master m_sceneMaster.StartScene(); break; case InitState.IDLE: break; } }