Ejemplo n.º 1
0
    /// <summary>
    ///  This function updates the loading progress once per frame until loading is complete
    /// </summary>
    /// <param name="sceneReference">This is a place holder for the moment</param>
    /// <returns>IEnumerator</returns>
    private IEnumerator TrackLoadingProgress(GameSceneSO sceneReference)
    {
        float totalProgress = 0;

        // When the scene reaches 0.9f, it means that it is loaded
        // The remaining 0.1f are for the integration
        while (totalProgress <= 0.9f)
        {
            totalProgress = 0;
            for (int i = 0; i < _scenesToLoadAsyncOperations.Count; ++i)
            {
                Debug.Log("Scene " + i + " :" + _scenesToLoadAsyncOperations[i].isDone + " progress = " + _scenesToLoadAsyncOperations[i].progress);
                totalProgress += _scenesToLoadAsyncOperations[i].progress;
            }

            //The fillAmount is for all scenes, so we divide the progress by the number of scenes to load
            _loadingProgressBar.fillAmount = totalProgress / _scenesToLoadAsyncOperations.Count;
            Debug.Log("progress bar " + _loadingProgressBar.fillAmount + " and value = " + totalProgress / _scenesToLoadAsyncOperations.Count);

            yield return(null);
        }

        _scenesToLoadAsyncOperations.Clear();

        runningLoader = null;

        //Hide progress bar when loading is done
        _loadingInterface.SetActive(false);
    }
Ejemplo n.º 2
0
    private void LoadScenes(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
    {
        AddScenesToUnload();

        _activeScene = locationsToLoad[0];

        for (int i = 0; i < locationsToLoad.Length; ++i)
        {
            var currentSceneName = locationsToLoad[i].Scene.name;

            if (!CheckLoadState(currentSceneName))
            {
                _scenesToLoadAsyncOperation.Add(SceneManager.LoadSceneAsync(currentSceneName, LoadSceneMode.Additive));
            }

            _scenesToLoadAsyncOperation[0].completed += SetActiveScene;

            if (showLoadingScreen)
            {
                _loadingInterface.SetActive(true);
                StartCoroutine(TrackLoadingProgress());
            }
            else
            {
                _scenesToLoadAsyncOperation.Clear();
            }
        }

        UnloadScenes();
    }
Ejemplo n.º 3
0
 public static void OpenSceneSafe(GameSceneSO gameSceneSO)
 {
     if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
     {
         EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(gameSceneSO.sceneReference.editorAsset));
     }
 }
Ejemplo n.º 4
0
    private void LoadScenes(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
    {
        //Take the first scene in the array as the scene we want to set active
        _activeScene = locationsToLoad[0];
        UnloadScenes();

        if (showLoadingScreen)
        {
            _ToggleLoadingScreen.RaiseEvent(true);
        }

        if (_scenesToLoadAsyncOperations.Count == 0)
        {
            for (int i = 0; i < locationsToLoad.Length; i++)
            {
                string currentScenePath = locationsToLoad[i].scenePath;
                _scenesToLoadAsyncOperations.Add(SceneManager.LoadSceneAsync(currentScenePath, LoadSceneMode.Additive));
            }
        }

        //Checks if any of the persistent scenes is not loaded yet and load it if unloaded
        //This is especially useful when we go from main menu to first location
        for (int i = 0; i < _persistentScenes.Count; ++i)
        {
            if (IsSceneLoaded(_persistentScenes[i].scenePath) == false)
            {
                _scenesToLoadAsyncOperations.Add(SceneManager.LoadSceneAsync(_persistentScenes[i].scenePath, LoadSceneMode.Additive));
            }
        }
        StartCoroutine(WaitForLoading(showLoadingScreen));
    }
Ejemplo n.º 5
0
    private void OnGUI()
    {
        GUILayout.Box("Scene Management", EditorStyles.boldLabel);
        _initScene = EditorGUILayout.ObjectField("Init Scene", _initScene, typeof(GameSceneSO), false) as GameSceneSO;

        if (GUILayout.Button("Load Init Scene"))
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                SceneManager.LoadSceneAsync(_initScene.Scene.name, LoadSceneMode.Additive);
            }
            else
            {
                _loadedScene = EditorSceneManager.OpenScene(INIT_SCENE_PATH, OpenSceneMode.Additive);
            }
        }

        if (GUILayout.Button("Unload Init Scene"))
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                SceneManager.UnloadSceneAsync(_initScene.Scene.name);
            }
            else
            {
                EditorSceneManager.CloseScene(_loadedScene, true);
            }
        }
    }
Ejemplo n.º 6
0
    /// <summary> This function loads the scenes passed as array parameter </summary>
    public void LoadScenes(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
    {
        //Add all current open scenes to unload list
        AddScenesToUnload();

        _activeScene = locationsToLoad[0];

        for (int i = 0; i < locationsToLoad.Length; ++i)
        {
            String currentSceneName = locationsToLoad[i].sceneName;
            if (!CheckLoadState(currentSceneName))
            {
                //Add the scene to the list of scenes to load asynchronously in the background
                _scenesToLoadAsyncOperations.Add(SceneManager.LoadSceneAsync(currentSceneName, LoadSceneMode.Additive));
            }
        }
        _scenesToLoadAsyncOperations[0].completed += SetActiveScene;
        if (showLoadingScreen)
        {
            //Show the progress bar and track progress if loadScreen is true
            loadingInterface.SetActive(true);
            StartCoroutine(TrackLoadingProgress());
        }
        else
        {
            //Clear the scenes to load
            _scenesToLoadAsyncOperations.Clear();
        }

        //Unload the scenes
        UnloadScenes();
    }
Ejemplo n.º 7
0
        public static Color GetDefaultColor(GameSceneSO gameScene)
        {
            var type = gameScene.GetType();

            if (kDefaultMarkerColors.TryGetValue(type, out var color))
            {
                return(color);
            }
            return(Color.red);
        }
Ejemplo n.º 8
0
    void OnNewSceneLoaded(AsyncOperationHandle <SceneInstance> obj)
    {
        _currentLoadedScene = _sceneToLoad;
        SetActiveScene();

        if (_showLoadingScreen)
        {
            _toggleLoadingScreen.RaiseEvent(false);
        }
    }
Ejemplo n.º 9
0
    private void OnNewSceneLoaded(AsyncOperationHandle <SceneInstance> obj)
    {
        //Save loaded scenes (to be unloaded at next load request)
        _currentlyLoadedScene = _sceneToLoad;
        SetActiveScene();

        if (_showLoadingScreen)
        {
            _toggleLoadingScreen.RaiseEvent(false);
        }
    }
Ejemplo n.º 10
0
 public void RaiseEvent(GameSceneSO gameSceneso, bool showLoading = false)
 {
     if (onLoadingRequested != null)
     {
         onLoadingRequested.Invoke(gameSceneso, showLoading);
     }
     else
     {
         Debug.LogWarning("A Scene loading was requested ...");
     }
 }
Ejemplo n.º 11
0
    private void LocationColdStartup(GameSceneSO currentlyOpenedLocation, bool showLoadingScreen)
    {
        _currentLoadedScene = currentlyOpenedLocation;

        if (_currentLoadedScene.sceneType == GameSceneSO.GameSceneType.Location)
        {
            //Gameplay managers is loaded synchronously
            gameManagerLoadingOpHandler            = gamePlayScene.assetReference.LoadSceneAsync(LoadSceneMode.Additive, true);
            gameManagerLoadingOpHandler.Completed += onLocationStartUpLoaded;
        }
    }
Ejemplo n.º 12
0
    private void CacheLoadLocations(GameSceneSO locationsToLoad, bool showLoadingScreen)
    {
        LocationSO locationSO = locationsToLoad as LocationSO;

        if (locationSO)
        {
            saveData._locationId = locationSO.Guid;
        }

        SaveDataToDisk();
    }
 public void RaiseEvent(GameSceneSO locationToLoad, bool showLoadingScreen = false, bool fadeScreen = false)
 {
     if (OnLoadingRequested != null)
     {
         OnLoadingRequested.Invoke(locationToLoad, showLoadingScreen, fadeScreen);
     }
     else
     {
         Debug.LogWarning("A Scene loading was requested, but nobody picked it up. " +
                          "Check why there is no SceneLoader already present, " +
                          "and make sure it's listening on this Load Event channel.");
     }
 }
Ejemplo n.º 14
0
    /// <summary>
    /// This special loading function is only used in the editor, when the developer presses Play in a Location scene, without passing by Initialisation.
    /// </summary>
    private void LocationColdStartup(GameSceneSO currentlyOpenedLocation, bool showLoadingScreen, bool fadeScreen)
    {
        _currentlyLoadedScene = currentlyOpenedLocation;

        if (_currentlyLoadedScene.sceneType == GameSceneSO.GameSceneType.Location)
        {
            //Gameplay managers is loaded synchronously
            _gameplayManagerLoadingOpHandle = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true);
            _gameplayManagerLoadingOpHandle.WaitForCompletion();
            _gameplayManagerSceneInstance = _gameplayManagerLoadingOpHandle.Result;

            StartGameplay();
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Prepares to load the main menu scene, first removing the Gameplay scene in case the game is coming back from gameplay to menus.
    /// </summary>
    private void LoadMenu(GameSceneSO menuToLoad, bool showLoadingScreen)
    {
        _sceneToLoad       = menuToLoad;
        _showLoadingScreen = showLoadingScreen;

        //In case we are coming from a Location back to the main menu, we need to get rid of the persistent Gameplay manager scene
        if (_gameplayManagerSceneInstance.Scene != null &&
            _gameplayManagerSceneInstance.Scene.isLoaded)
        {
            Addressables.UnloadSceneAsync(_gameplayManagerLoadingOpHandle, true);
        }

        UnloadPreviousScene();
    }
Ejemplo n.º 16
0
    void LoadLocation(GameSceneSO gameSceneso, bool showLoading)
    {
        _sceneToLoad       = gameSceneso;
        _showLoadingScreen = showLoading;

        if (sceneInstance.Scene == null || !sceneInstance.Scene.isLoaded)
        {
            gameManagerLoadingOpHandler            = gamePlayScene.assetReference.LoadSceneAsync(LoadSceneMode.Additive, true);
            gameManagerLoadingOpHandler.Completed += OnGameplayMangersLoaded;
        }
        else
        {
            UnloadPreviousScene();
        }
    }
Ejemplo n.º 17
0
    /// <summary>
    /// This function loads the location scenes passed as array parameter
    /// </summary>
    private void LoadLocation(GameSceneSO locationToLoad, bool showLoadingScreen)
    {
        _sceneToLoad       = locationToLoad;
        _showLoadingScreen = showLoadingScreen;

        //In case we are coming from the main menu, we need to load the Gameplay manager scene first
        if (_gameplayManagerSceneInstance.Scene == null ||
            !_gameplayManagerSceneInstance.Scene.isLoaded)
        {
            _gameplayManagerLoadingOpHandle            = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true);
            _gameplayManagerLoadingOpHandle.Completed += OnGameplayMangersLoaded;
        }
        else
        {
            UnloadPreviousScene();
        }
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Prepares to load the main menu scene, first removing the Gameplay scene in case the game is coming back from gameplay to menus.
    /// </summary>
    private void LoadMenu(GameSceneSO menuToLoad, bool showLoadingScreen, bool fadeScreen)
    {
        //Prevent a double-loading, for situations where the player falls in two Exit colliders in one frame
        if (_isLoading)
        {
            return;
        }

        _sceneToLoad       = menuToLoad;
        _showLoadingScreen = showLoadingScreen;
        _isLoading         = true;

        //In case we are coming from a Location back to the main menu, we need to get rid of the persistent Gameplay manager scene
        if (_gameplayManagerSceneInstance.Scene != null &&
            _gameplayManagerSceneInstance.Scene.isLoaded)
        {
            Addressables.UnloadSceneAsync(_gameplayManagerLoadingOpHandle, true);
        }

        StartCoroutine(UnloadPreviousScene());
    }
Ejemplo n.º 19
0
    private void OnNewSceneLoaded(AsyncOperationHandle <SceneInstance> obj)
    {
        //Save loaded scenes (to be unloaded at next load request)
        _currentlyLoadedScene = _sceneToLoad;

        Scene s = obj.Result.Scene;

        SceneManager.SetActiveScene(s);
        LightProbes.TetrahedralizeAsync();

        _isLoading = false;

        if (_showLoadingScreen)
        {
            _toggleLoadingScreen.RaiseEvent(false);
        }

        _fadeRequestChannel.FadeIn(_fadeDuration);

        StartGameplay();
    }
Ejemplo n.º 20
0
    /// <summary>
    /// This function loads the scenes passed as array parameter
    /// </summary>
    /// <param name="locationsToLoad"></param>
    /// <param name="showLoadingScreen"></param>
    private void LoadScenes(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
    {
        _activeScene = locationsToLoad[0];
        AddScenesToUnload();
        UnloadScenes();

        if (showLoadingScreen)
        {
            _loadingInterface.SetActive(true);
        }

        if (_scenesToLoadAsyncOperations.Count == 0)
        {
            for (int i = 0; i < locationsToLoad.Length; i++)
            {
                string currentScenePath = locationsToLoad[i].scenePath;
                if (IsSceneLoaded(currentScenePath) == false)
                {
                    if (runningLoader == null)
                    {
                        _scenesToLoadAsyncOperations.Add(SceneManager.LoadSceneAsync(currentScenePath, LoadSceneMode.Additive));
                        _scenesToLoadAsyncOperations[i].completed += SetActiveScene;
                        // TODO: Run a coroutine for each scene loading that updates a combined value
                        // for the progress bar. This way, as each scene completes loading, we will
                        // know what scene it is. Then decide if it activates right away or not.
                        // runningLoader = StartCoroutine(TrackLoadingProgress(locationsToLoad[i]));
                    }
                }
            }

            if (_scenesToLoadAsyncOperations.Count > 0)
            {
                // TODO: locationsToLoad[0] is a place holder right now.
                runningLoader = StartCoroutine(TrackLoadingProgress(locationsToLoad[0]));
            }
        }
    }
Ejemplo n.º 21
0
    /// <summary>
    /// This function loads the location scenes passed as array parameter
    /// </summary>
    private void LoadLocation(GameSceneSO locationToLoad, bool showLoadingScreen, bool fadeScreen)
    {
        //Prevent a double-loading, for situations where the player falls in two Exit colliders in one frame
        if (_isLoading)
        {
            return;
        }

        _sceneToLoad       = locationToLoad;
        _showLoadingScreen = showLoadingScreen;
        _isLoading         = true;

        //In case we are coming from the main menu, we need to load the Gameplay manager scene first
        if (_gameplayManagerSceneInstance.Scene == null ||
            !_gameplayManagerSceneInstance.Scene.isLoaded)
        {
            _gameplayManagerLoadingOpHandle            = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true);
            _gameplayManagerLoadingOpHandle.Completed += OnGameplayMangersLoaded;
        }
        else
        {
            StartCoroutine(UnloadPreviousScene());
        }
    }
Ejemplo n.º 22
0
 private void OnEnable()
 {
     gameSceneTarget = target as GameSceneSO;
     PopulateScenePicker();
     InitializeGuiStyles();
 }
Ejemplo n.º 23
0
 private void OnEnable()
 {
     _gameSceneInspected = target as GameSceneSO;
     PopulateScenePicker();
     InitializeGuiStyles();
 }
Ejemplo n.º 24
0
 private void OnGameSceneSOCreated(GameSceneSO _)
 {
     Helper.RunOnNextUpdate(PopulateItems);
 }