private static Scene[] GetScenesToUnload(MMAdditiveSceneLoadingManagerSettings.UnloadMethods unloaded)
        {
            switch (unloaded)
            {
            case MMAdditiveSceneLoadingManagerSettings.UnloadMethods.None:
                _initialScenes = new Scene[0];
                break;

            case MMAdditiveSceneLoadingManagerSettings.UnloadMethods.ActiveScene:
                _initialScenes = new Scene[1] {
                    SceneManager.GetActiveScene()
                };
                break;

            default:
            case MMAdditiveSceneLoadingManagerSettings.UnloadMethods.AllScenes:
                _initialScenes = MMScene.GetLoadedScenes();
                break;
            }
            return(_initialScenes);
        }
示例#2
0
        /// <summary>
        /// Call this static method to load a scene from anywhere
        /// </summary>
        /// <param name="sceneToLoadName">Level name.</param>
        public static void LoadScene(string sceneToLoadName, string loadingSceneName = "MMAdditiveLoadingScreen",
                                     ThreadPriority threadPriority = ThreadPriority.High, bool secureLoad = true,
                                     bool interpolateProgress      = true,
                                     float beforeEntryFadeDelay    = 0f,
                                     float entryFadeDuration       = 0.25f,
                                     float afterEntryFadeDelay     = 0.1f,
                                     float beforeExitFadeDelay     = 0.25f,
                                     float exitFadeDuration        = 0.2f,
                                     MMTweenType entryFadeTween    = null, MMTweenType exitFadeTween = null,
                                     float progressBarSpeed        = 5f,
                                     FadeModes fadeMode            = FadeModes.FadeInThenOut)
        {
            if (_loadingInProgress)
            {
                Debug.LogError("MMLoadingSceneManagerAdditive : a request to load a new scene was emitted while a scene load was already in progress");
                return;
            }

            if (entryFadeTween == null)
            {
                entryFadeTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutCubic);
            }

            if (exitFadeTween == null)
            {
                exitFadeTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutCubic);
            }

            if (secureLoad)
            {
                _scenesInBuild = MMScene.GetScenesInBuild();

                if (!_scenesInBuild.Contains(sceneToLoadName))
                {
                    Debug.LogError("MMLoadingSceneManagerAdditive : impossible to load the '" + sceneToLoadName + "' scene, " +
                                   "there is no such scene in the project's build settings.");
                    return;
                }
                if (!_scenesInBuild.Contains(loadingSceneName))
                {
                    Debug.LogError("MMLoadingSceneManagerAdditive : impossible to load the '" + loadingSceneName + "' scene, " +
                                   "there is no such scene in the project's build settings.");
                    return;
                }
            }

            _loadingInProgress = true;
            _initialScenes     = MMScene.GetLoadedScenes();

            Application.backgroundLoadingPriority = threadPriority;
            _sceneToLoadName            = sceneToLoadName;
            _loadingScreenSceneName     = loadingSceneName;
            _beforeEntryFadeDelay       = beforeEntryFadeDelay;
            _entryFadeDuration          = entryFadeDuration;
            _entryFadeTween             = entryFadeTween;
            _afterEntryFadeDelay        = afterEntryFadeDelay;
            _progressInterpolationSpeed = progressBarSpeed;
            _beforeExitFadeDelay        = beforeExitFadeDelay;
            _exitFadeDuration           = exitFadeDuration;
            _exitFadeTween       = exitFadeTween;
            _fadeMode            = fadeMode;
            _interpolateProgress = interpolateProgress;

            SceneManager.LoadScene(_loadingScreenSceneName, LoadSceneMode.Additive);
        }