private void OnLoadingScreenHideComplete()
 {
     LoadingScreenController.Instance.OnLoadingScreenHideComplete -= OnLoadingScreenHideComplete;
     _isLoadingScene = false;
     // Debug.Log("Scene load complete!");
     OnSceneLoaded?.Invoke(_nextSceneName);
 }
Esempio n. 2
0
    private IEnumerator LoadSceneAsync(string sceneName)
    {
        Time.timeScale = 1;
        if (SceneTransition.Instance)
        {
            SceneTransition.Instance.FadeIn();
            while (!SceneTransition.isDone)
            {
                yield return(null);
            }
        }

        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);

        while (!operation.isDone)
        {
            yield return(null);
        }

        OnSceneLoaded?.Invoke(sceneName);

        if (SceneTransition.Instance)
        {
            SceneTransition.Instance.FadeOut();
        }
    }
Esempio n. 3
0
        private void InvokeLoadedActions(List <string> sceneNames, SceneType sceneType)
        {
            try
            {
                foreach (string sceneName in sceneNames)
                {  // Announce scenes individually regardless of type
                    OnSceneLoaded?.Invoke(sceneName);
                }

                switch (sceneType)
                {
                case SceneType.Content:
                    // Announce content as a set
                    OnContentLoaded?.Invoke(sceneNames);
                    break;

                case SceneType.Lighting:
                    // We only handle lighting scenes one at a time
                    Debug.Assert(sceneNames.Count == 1);
                    OnLightingLoaded?.Invoke(sceneNames[0]);
                    break;

                default:
                    // Don't announce other types of scenes invidually
                    break;
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Error when attempting to invoke loaded actions for " + string.Join(", ", sceneNames));
                Debug.LogException(e);
            }
        }
 private void LoadSceneInstant(string sceneName)
 {
     _isLoadingScene = false;
     SceneManager.LoadScene(sceneName);
     // Debug.Log("Scene load complete!");
     OnSceneLoaded?.Invoke(_nextSceneName);
 }
        /// <summary>
        /// Loads a single scene.
        /// </summary>
        /// <param name="scene">The scene name.</param>
        /// <param name="onComplete">Optional callback.</param>
        /// <returns></returns>
        public static IEnumerator CoroutineLoadScene(string scene, Action onComplete = null)
        {
            //Block flow if the scene does not exist
            if (!Application.CanStreamedLevelBeLoaded(scene))
            {
                if (LogLevel >= LogType.Less)
                {
                    Debug.LogWarning(Tag + "The scene \"" + scene + "\" cannot be found or does not exist.");
                }
                yield break;
            }

            AsyncOperation op = SceneManager.LoadSceneAsync(scene);

            //Wait until the current scene is loaded
            while (op.progress < 0.9f)
            {
                yield return(null);
            }
            //Debug
            //yield return new WaitForSeconds(1f);

            onComplete?.Invoke();
            OnSceneLoaded?.Invoke(new [] { scene });
        }
    private IEnumerator FadeAndSwitchScenes(string sceneName)
    {
        m_ScreenFader.FadeOut();

        while (m_ScreenFader.IsFading)
        {
            Debug.Log("Fading...");

            yield return(null);
        }

        OnSceneUnload?.Invoke();

        yield return(SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex));

        yield return(StartCoroutine(LoadSceneAndSetActive(sceneName)));

        OnSceneLoaded?.Invoke();

        StateController.Instance.StateMachine.ChangeState(StateController.shop);

        m_ScreenFader.FadeIn();

        while (m_ScreenFader.IsFading)
        {
            Debug.Log("Fading...");

            yield return(null);
        }
    }
        private void InvokeLoadedActions(List <string> sceneNames, SceneType sceneType)
        {
            foreach (string sceneName in sceneNames)
            {  // Announce scenes individually regardless of type
                OnSceneLoaded?.Invoke(sceneName);
            }

            switch (sceneType)
            {
            case SceneType.Content:
                // Announce content as a set
                OnContentLoaded?.Invoke(sceneNames);
                break;

            case SceneType.Lighting:
                // We only handle lighting scenes one at a time
                Debug.Assert(sceneNames.Count == 1);
                OnLightingLoaded?.Invoke(sceneNames[0]);
                break;

            default:
                // Don't announce other types of scenes invidually
                break;
            }
        }
        /// <summary>
        /// Load the scene in the given ScenePackage.
        /// </summary>
        /// <param name="scenePackage">The ScenePackage to load.</param>
        public IEnumerable <SceneBuildStatus> loadScene(ScenePackage scenePackage, SceneBuildOptions options)
        {
            currentScenePackage = scenePackage;
            yield return(new SceneBuildStatus()
            {
                Message = "Setting up Resources"
            });

            sceneResourceManager.changeResourcesToMatch(scenePackage.ResourceManager);
            sceneResourceManager.initializeResources();

            currentScene = scenePackage.SceneDefinition.createScene();
            if (OnSceneLoading != null)
            {
                OnSceneLoading.Invoke(this, currentScene);
            }
            currentSimObjects = scenePackage.SimObjectManagerDefinition.createSimObjectManager(currentScene.getDefaultSubScene());
            foreach (var status in currentScene.buildSceneStatus(options))
            {
                yield return(status);
            }
            if (OnSceneLoaded != null)
            {
                OnSceneLoaded.Invoke(this, currentScene);
            }
        }
        private IEnumerator LoadScene(string targetLevel, OnSceneLoaded callback = null)
        {
            yield return(SceneManager.LoadSceneAsync(targetLevel, LoadSceneMode.Single));

            isLoading = false;

            if (callback != null)
            {
                callback.Invoke();
            }
        }
 public virtual void OnSceneLoadedInvoke(Scene x)
 {
     if (GameSparksManager.Instance().IsDebug)
     {
         var subs     = OnSceneLoaded?.GetInvocationList();
         var debugStr = "OnSceneLoaded InvokationList: ";
         subs?.ToList().ForEach(m => debugStr += "\n" + m.Method.Name);
         Debug.Log(debugStr);
     }
     OnSceneLoaded?.Invoke(x);
 }
 private void SceneManager_OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
 {
     Detach();
     _active = false;
     OnSceneUnloaded?.Invoke();
     if (arg0.buildIndex == SceneBuildIndex)
     {
         Attach(arg0);
         _active = true;
         OnSceneLoaded?.Invoke();
     }
 }
Esempio n. 12
0
        private static void SceneLoadedHandler(Scene scene, LoadSceneMode mode)
        {
            if (AllAvailableGameObjectsByScene.ContainsKey(scene.name))
            {
                AllAvailableGameObjectsByScene[scene.name] = scene.GetRootGameObjects();
            }
            else
            {
                AllAvailableGameObjectsByScene.Add(scene.name, scene.GetRootGameObjects());
            }

            OnSceneLoaded?.Invoke(scene.name);
        }
Esempio n. 13
0
 private void FinishLoading(Scene scene)
 {
     if (scene.buildIndex != 0)
     {
         if (_isLoaded && _isUnloaded)
         {
             _isLoaded   = false;
             _isUnloaded = false;
             var currentScene = _loadingScene == SceneType.None ? CurrentScene : _loadingScene;
             OnSceneLoaded?.Invoke(this, new SceneLoadedEventArgs(currentScene));
         }
     }
 }
        private IEnumerator LoadSceneAsync(GameScene scene, bool slowLoad = false)
        {
            _busy = true;

            if (PopupWindow.Opened)
            {
                PopupWindow.Opened.Close();
            }

            var dimmer = slowLoad ? slowDimmer : fastDimmer;

            dimmer.Switch(true);
            yield return(StartCoroutine(dimmer.WaitForSwitchAsync()));

            var loadedScene = GetLoadedScene();

            if (loadedScene != string.Empty)
            {
                yield return(SceneManager.UnloadSceneAsync(loadedScene));
            }

            Time.timeScale = 1;

            if (slowLoad)
            {
                dimmer.StartWaitingForTap();
                yield return(StartCoroutine(dimmer.WaitForTapAsync()));
            }

            yield return(SceneManager.LoadSceneAsync(scene.ToStringName(), LoadSceneMode.Additive));

            if (scene.IsPivot())
            {
                PivotScene = scene;
            }

            if (_hasSceneLoadingConflict)
            {
                _hasSceneLoadingConflict = false;
                StartCoroutine(LoadSceneAsync(_conflictedLoadedScene, true));
                yield break;
            }

            dimmer.Switch(false);
            yield return(StartCoroutine(dimmer.WaitForSwitchAsync()));

            OnSceneLoaded?.Invoke(null, EventArgs.Empty);
            _busy = false;
        }
Esempio n. 15
0
 private void OnSceneLoadedEvent(Scene _scene, LoadSceneMode _mode)
 {
     if (onSceneLoaded != null)
     {
         try
         {
             UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UISceneManager", "On Scene Loaded", "Event invoke.");
             onSceneLoaded.Invoke(_scene, _mode);
         }
         catch (System.Exception exception)
         {
             Debug.LogError("Couldn't invoke event onSceneLoaded. Error: " + exception.Message);
         }
     }
 }
Esempio n. 16
0
 public void createScene()
 {
     scene       = sceneDefinition.createScene();
     scene.Scope = pluginManager.GlobalScope.ServiceProvider.CreateScope(); //Disposed in destroyscene
     if (OnSceneLoading != null)
     {
         OnSceneLoading.Invoke(this, scene);
     }
     createSimObjects();
     if (OnSceneLoaded != null)
     {
         OnSceneLoaded.Invoke(this, scene);
     }
     foreach (DebugInterface debugInterface in controller.PluginManager.DebugInterfaces)
     {
         debugInterface.createDebugInterface(controller.PluginManager.RendererPlugin, scene.getDefaultSubScene());
     }
 }
        /// <summary>
        /// Loads a single scene.
        /// </summary>
        /// <param name="scene">The scene to unload.</param>
        /// <param name="onComplete">Optional callback.</param>
        public static void LoadScene(string scene, Action onComplete = null)
        {
            //Block flow if the scene does not exist
            if (!Application.CanStreamedLevelBeLoaded(scene))
            {
                if (LogLevel >= LogType.Less)
                {
                    Debug.LogWarning(Tag + "The scene \"" + scene + "\" cannot be found or does not exist.");
                }
                return;
            }

            AsyncOperation op = SceneManager.LoadSceneAsync(scene);

            op.completed += _ => {
                onComplete?.Invoke();
                OnSceneLoaded?.Invoke(new [] { scene });
            };
        }
Esempio n. 18
0
        private void PrepareScene()
        {
            SpawnCamera();
            SpawnWorldUiCanvas();
            sceneSettings = FindObjectOfType <SceneSettings>();
#if (UNITY_EDITOR)
            levelController.StartCurrentEditorLevel();
            if (sceneSettings != null && sceneSettings.levels != null)
            {
                currentLevel = sceneSettings.startLevel;
                levelController.LoadLevel(sceneSettings.GetLevel(currentLevel));
            }
#else
            currentLevel = sceneSettings.startLevel;
            levelController.LoadLevel(sceneSettings.GetLevel(currentLevel));
#endif
            loadingScreen.Hide();
            isLoading = false;
            OnSceneLoaded?.Invoke();
        }
Esempio n. 19
0
        internal static void Internal_OnSceneEvent(SceneEventType eventType, Scene scene, ref Guid sceneId)
        {
            switch (eventType)
            {
            case SceneEventType.OnSceneSaving: OnSceneSaving?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneSaved: OnSceneSaved?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneSaveError: OnSceneSaveError?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneLoading: OnSceneLoading?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneLoaded: OnSceneLoaded?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneLoadError: OnSceneLoadError?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneUnloading: OnSceneUnloading?.Invoke(scene, sceneId); break;

            case SceneEventType.OnSceneUnloaded: OnSceneUnloaded?.Invoke(scene, sceneId); break;
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Load the scene in the given ScenePackage.
        /// </summary>
        /// <param name="scenePackage">The ScenePackage to load.</param>
        public IEnumerable <SceneBuildStatus> loadSceneCo(ScenePackage scenePackage, SceneBuildOptions options = SceneBuildOptions.SingleUseDefinitions)
        {
            this.scenePackage = scenePackage;
            yield return(new SceneBuildStatus()
            {
                Message = "Setting up Resources"
            });

            sceneResourceManager.changeResourcesToMatch(scenePackage.ResourceManager);
            sceneResourceManager.initializeResources();

            scene       = scenePackage.SceneDefinition.createScene();
            scene.Scope = pluginManager.GlobalScope.ServiceProvider.CreateScope();
            if (OnSceneLoading != null)
            {
                OnSceneLoading.Invoke(this, scene);
            }
            currentSimObjects = scenePackage.SimObjectManagerDefinition.createSimObjectManager(scene.getDefaultSubScene());
            if (dynamicMode)
            {
                foreach (var status in scene.buildSceneStatus(options))
                {
                    yield return(status);
                }
            }
            else
            {
                scene.buildStaticScene();
            }
            if (OnSceneLoaded != null)
            {
                OnSceneLoaded.Invoke(this, scene);
            }
            foreach (DebugInterface debugInterface in pluginManager.DebugInterfaces)
            {
                debugInterface.createDebugInterface(pluginManager.RendererPlugin, scene.getDefaultSubScene());
            }
        }
Esempio n. 21
0
        private IEnumerator LoadSceneByNameCoroutine(string sceneName)
        {
            TypedSceneName typedSceneName = null;

            _typedNamesDict.TryGetValue(sceneName, out typedSceneName);

            OnSceneStartLoading?.Invoke(sceneName);
            if (typedSceneName != null)
            {
                OnSceneStartLoadingByType?.Invoke(typedSceneName.SceneType);
            }

            var asyncOperation = SceneManager.LoadSceneAsync(sceneName);

            while (!asyncOperation.isDone)
            {
                yield return(null);
            }

            if (!Mathf.Approximately(_delayAfterLoad, 0f))
            {
                yield return(_delayWaiting);
            }

            yield return(null);

            _switchCoroutine = null;

            OnSceneLoaded?.Invoke(sceneName);
            if (typedSceneName != null)
            {
                OnSceneLoadedByType?.Invoke(typedSceneName.SceneType);
            }

            yield return(null);
        }
 private void LoadingComplete(AsyncOperation obj)
 {
     OnSceneLoaded?.Invoke(CurrentStateInfo);
     loadingOperation = null;
 }
 public static void SceneLoaded()
 {
     OnSceneLoaded?.Invoke();
 }
 public override void Awake()
 {
     base.Awake();
     InternalSceneManager.sceneLoaded += (Scene scene, LoadSceneMode loadSceneMode) => { onSceneLoaded?.Invoke(); };
 }
        /// <summary>
        /// Loads in an array of scenes additively.
        /// </summary>
        /// <param name="scenes">The array of scene names.</param>
        /// <param name="onComplete">Optional callback.</param>
        /// <param name="duplicateScenes">Should duplicate scenes be allowed. False by default.</param>
        /// <returns></returns>
        public static IEnumerator CoroutineLoadScenesAdditive(string[] scenes, Action onComplete = null, bool duplicateScenes = false)
        {
            AsyncOperation[] operations = new AsyncOperation[scenes.Length];

            //Step 1: List all of operations
            for (var i = 0; i < scenes.Length; i++)
            {
                string scene = scenes[i];

                //Block flow if the scene does not exist
                if (!Application.CanStreamedLevelBeLoaded(scene))
                {
                    if (LogLevel >= LogType.Less)
                    {
                        Debug.LogWarning(Tag + "The scene \"" + scene + "\" cannot be found or does not exist.");
                    }
                    continue;
                }

                if (!duplicateScenes)
                {
                    //Block flow if the scene has already been loaded
                    Scene sceneObj = SceneManager.GetSceneByName(scene);
                    if (sceneObj.isLoaded)
                    {
                        if (LogLevel >= LogType.All)
                        {
                            Debug.LogWarning(Tag + "The scene \"" + scene + "\" has already been loaded.");
                        }
                        continue;
                    }
                }

                //Start loading the scene
                AsyncOperation op = SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);
                op.allowSceneActivation = false;
                operations[i]           = op;

                //Wait until the current scene is loaded but not activated
                while (op.progress < 0.9f)
                {
                    yield return(null);
                }
                //Debug
                //yield return new WaitForSeconds(1f);
            }

            //Step 2: Activate all of the operations at once
            foreach (AsyncOperation op in operations)
            {
                if (op == null)
                {
                    continue;
                }

                op.allowSceneActivation = true;

                while (!op.isDone)
                {
                    yield return(null);
                }
                //Debug
                //yield return new WaitForSeconds(1f);
            }

            onComplete?.Invoke();
            OnSceneLoaded?.Invoke(scenes);
        }
Esempio n. 26
0
 private void OpenScene(int sceneId, out Scene scene)
 {
     scene = SceneManager.LoadScene(sceneId, new LoadSceneParameters(LoadSceneMode.Additive));
     OnSceneLoaded?.Invoke(sceneId);
 }
 private static void SceneOpenedCallback(Scene scene, UnityEditor.SceneManagement.OpenSceneMode mode)
 {
     _gameObjectsList.Clear();
     AppendAllTransformInSceneToList(scene);
     OnSceneLoaded?.Invoke(_gameObjectsList);
 }
        /// <summary>
        /// Loads in an array of scenes additively.
        /// </summary>
        /// <param name="scenes">The array of scene names.</param>
        /// <param name="onComplete">Optional callback.</param>
        /// <param name="duplicateScenes">Should duplicate scenes be allowed. False by default.</param>
        public static void LoadScenesAdditive(string[] scenes, Action onComplete = null, bool duplicateScenes = false)
        {
            AsyncOperation[] operations = new AsyncOperation[scenes.Length];

            //Step 1: Load all of operations
            for (var i = 0; i < scenes.Length; i++)
            {
                string scene = scenes[i];

                //Block flow if the scene does not exist
                if (!Application.CanStreamedLevelBeLoaded(scene))
                {
                    if (LogLevel >= LogType.Less)
                    {
                        Debug.LogWarning(Tag + "The scene \"" + scene + "\" cannot be found or does not exist.");
                    }
                    continue;
                }

                if (!duplicateScenes)
                {
                    //Block flow if the scene has already been loaded
                    Scene sceneObj = SceneManager.GetSceneByName(scene);
                    if (sceneObj.isLoaded)
                    {
                        if (LogLevel >= LogType.All)
                        {
                            Debug.LogWarning(Tag + "The scene \"" + scene + "\" has already been loaded.");
                        }
                        continue;
                    }
                }

                //Load the scene and deactivate
                AsyncOperation op = SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);
                op.allowSceneActivation = false;
                operations[i]           = op;
            }

            //Step 2: Activate all of the operations
            foreach (AsyncOperation op in operations)
            {
                if (op == null)
                {
                    continue;
                }

                op.allowSceneActivation = true;
            }

            //Step 3: Attach the callback to the last scene
            for (int i = operations.Length - 1; i >= 0; i--)
            {
                AsyncOperation op = operations[i];

                if (op == null)
                {
                    continue;
                }

                op.completed += _ => {
                    onComplete?.Invoke();
                    OnSceneLoaded?.Invoke(scenes);
                };
                break;
            }
        }
 private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
 {
     OnSceneLoaded?.Invoke(newScene, InUniverse(newScene));
 }