Пример #1
0
        private void ValidateActivityBeforeStarting(Activity activity)
        {
            //Create current scene name list for validations
            IList <string> currentSceneNames = new List <string>();

            if (HasActivityRunning())
            {
                currentSceneNames = GetCurrentActivity().GetScenes();
            }

            //Create new scene name list for validations
            IList <string> newSceneNames = activity.GetScenes();

            //Can't start Activity if it's already running.
            if (HasActivityRunning())
            {
                if (GetCurrentActivity().Is(activity))
                {
                    throw new Exception("Unable to start Activity : it is already running.");
                }
            }

#if UNITY_EDITOR
            //Can't start Activity if one of his scenes is not in the BuildSettings. Can only check this while in Editor.
            foreach (string sceneName in newSceneNames)
            {
                string scenePath = AssetsExtensions.FindScenePath(sceneName).Replace("\\", "/");

                bool founded = false;
                foreach (UnityEditor.EditorBuildSettingsScene scene in UnityEditor.EditorBuildSettings.scenes)
                {
                    if (scene.path == scenePath)
                    {
                        founded = true;
                        break;
                    }
                }

                if (!founded)
                {
                    throw new Exception("Unable to start Activity : scene named \"" + sceneName + "\" is not in the Unity BuildSettings. " +
                                        "Thus, Unity can't load it. To solve this, just click the \"Harmony/Generate Build Settings From Activities\" " +
                                        "and try again.");
                }
            }
#endif
            //Can't start an Activity if one of his scenes is already loaded and is not part of the current activity
            foreach (string sceneName in newSceneNames)
            {
                if (SceneManagerExtensions.IsSceneLoaded(sceneName) && !currentSceneNames.Contains(sceneName))
                {
                    throw new Exception("Unable to start Activity : scene named \"" + sceneName + "\" is already loaded and is not part of the " +
                                        "current Activity. You may have loaded it manually somewhere.");
                }
            }
        }
 private void ScheduleCurrentActivityScenesToLoad()
 {
     foreach (string sceneName in GetCurrentActivity().GetScenes())
     {
         if (SceneManagerExtensions.IsSceneLoaded(sceneName) && !scenesToUnloadRemaining.Contains(sceneName))
         {
             scenesToLoadRemaining.Clear();   //Prevent anything from happening
             scenesToUnloadRemaining.Clear(); //Prevent anything from happening
             throw new ArgumentException("Unable to load Activity : scene named \"" + sceneName +
                                         "\" is already loaded and is not scheduled to be unloaded. You may have loaded it manually somewhere.");
         }
         scenesToLoadRemaining.Enqueue(sceneName);
     }
 }
 private void ScheduleCurrentActivityScenesToUnload()
 {
     foreach (string sceneName in GetCurrentActivity().GetScenes())
     {
         if (!SceneManagerExtensions.IsSceneLoaded(sceneName))
         {
             Debug.LogError("Problem while stopping current Activity : scene named \"" + sceneName +
                            "\" is not loaded, but belongs to the Activity being closed. You may have unloaded it manually somewhere.");
         }
         else
         {
             scenesToUnloadRemaining.Enqueue(sceneName);
         }
     }
 }
Пример #4
0
 private IEnumerator GetUnloadRoutineInternal()
 {
     foreach (var scene in scenes)
     {
         var sceneName = R.S.Scene.ToString(scene);
         if (SceneManagerExtensions.IsSceneLoaded(sceneName))
         {
             yield return(SceneManager.UnloadSceneAsync(sceneName));
         }
         else
         {
             Debug.LogWarning("Problem while unloading World \"" + name + "\" : scene named \"" + sceneName +
                              "\" is not loaded.");
         }
     }
 }
Пример #5
0
        private IEnumerator UnloadAndStopCurrentActivityProcedure()
        {
            menuStack.Clear();

            StackedActivity currentActivity = GetCurrentActivity();

            currentActivity.Stop();
            foreach (string scene in currentActivity.GetScenes())
            {
                if (SceneManagerExtensions.IsSceneLoaded(scene))
                {
                    yield return(SceneManager.UnloadSceneAsync(scene));
                }
                else
                {
                    Debug.LogWarning("Problem while stopping current Activity : scene named \"" + scene + "\" is not loaded, but belongs to " +
                                     "the Activity being closed. You may have unloaded it manually somewhere.");
                }
            }
        }
Пример #6
0
        private IEnumerator GetLoadRoutineInternal()
        {
            foreach (var scene in scenes)
            {
                var sceneName = R.S.Scene.ToString(scene);
                if (!SceneManagerExtensions.IsSceneLoaded(sceneName))
                {
                    var operation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

                    while (!operation.isDone)
                    {
                        progress = Mathf.Clamp01(operation.progress / .9f);
                        onProgress?.Invoke(progress);

                        yield return(operation);
                    }
                }
                else
                {
                    Debug.LogWarning("Problem while loading World \"" + name + "\" : scene named \"" + sceneName +
                                     "\" is already loaded.");
                }
            }
        }