private IEnumerator LoadMainScene(SceneIndex scene, SceneModel model)
        {
            OnLoadingStart?.Invoke();
            IsLoading = true;

            // Make sure to clean up the current active scene before destroying it
            if (_activeScene != null)
            {
                _activeScene.Controller.BeforeDestroy();
            }

            // Start the scene loading asyncronous operation
            AsyncOperation loadSceneJob = SceneManager.LoadSceneAsync(scene.ToString());

            while (!loadSceneJob.isDone)
            {
                yield return(null);

                // Callback to update based on the async task progress
                OnLoadingUpdate?.Invoke(loadSceneJob.progress);
            }

            _loadedScenes.Clear();

            GC.Collect();

            Scene loadedScene = SceneManager.GetSceneByName(scene.ToString());

            if (loadedScene.isLoaded)
            {
                bool controllerFound = false;
                // Get the scene object to initialize the scene using the ISceneController interface
                GameObject[] rootObjects = loadedScene.GetRootGameObjects();
                foreach (GameObject rootObject in rootObjects)
                {
                    // Try to get the scene controller so we can initialize the scene
                    ISceneController sceneController = rootObject.GetComponent <ISceneController>();

                    // This object didn't have the scene controller
                    if (sceneController == null)
                    {
                        continue;
                    }

                    // Create a loaded scene handle
                    LoadedScene managedLoadedScene = new LoadedScene(sceneController, model, rootObject, scene);
                    _loadedScenes.Add(managedLoadedScene);

                    _activeScene = managedLoadedScene;
                    sceneController.BaseModel = model;
                    yield return(sceneController.Initialization());

                    sceneController.AfterInitialization();
                    controllerFound = true;
                }

                if (!controllerFound)
                {
                    Debug.LogError("[SceneTransitionManager] Could not find any object with component SceneController in scene: "
                                   + loadedScene.name);
                }
            }

            yield return(new WaitForSeconds(1));

            OnLoadingFinished?.Invoke();
            IsLoading = false;
        }
 private void NotifyLoadingFinished()
 {
     IsLoading = false;
     OnLoadingFinished?.Invoke();
 }