コード例 #1
0
ファイル: CSSceneTools.cs プロジェクト: dqchess/fire-emblem
 public static void CloseOpenedSceneIfNeeded(OpenSceneResult lastOpenSceneResult, string nextScenePath = null, bool forceClose = false)
 {
     if (IsOpenedSceneNeedsToBeClosed(lastOpenSceneResult, nextScenePath, forceClose))
     {
         EditorSceneManager.CloseScene(lastOpenSceneResult.scene, lastOpenSceneResult.sceneWasLoaded || forceClose);
     }
 }
コード例 #2
0
ファイル: CSSceneTools.cs プロジェクト: dqchess/fire-emblem
        public static OpenSceneResult OpenSceneWithSavePrompt(string path, bool activate = true)
        {
#if UNITY_2018_3_OR_NEWER
            StageUtility.GoToMainStage();
#endif

            var result = new OpenSceneResult();

            var targetScene = SceneManager.GetSceneByPath(path);
            if (targetScene == SceneManager.GetActiveScene())
            {
                result.scene     = targetScene;
                result.success   = true;
                result.scenePath = path;

                return(result);
            }

            if (!SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return(result);
            }

            return(OpenScene(path, activate));
        }
コード例 #3
0
ファイル: CSSceneTools.cs プロジェクト: dqchess/fire-emblem
        public static OpenSceneResult OpenScene(string path, bool activate = true)
        {
#if UNITY_2018_3_OR_NEWER
            StageUtility.GoToMainStage();
#endif

            var result = new OpenSceneResult();
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError(Maintainer.ConstructError("Can't open scene since path is absent!"));
                return(result);
            }

            var targetScene = SceneManager.GetSceneByPath(path);
            result.scene     = targetScene;
            result.scenePath = path;

            if (targetScene == SceneManager.GetActiveScene())
            {
                result.success = true;
                return(result);
            }

            if (!targetScene.isLoaded)
            {
                result.sceneWasAdded = EditorSceneManager.GetSceneManagerSetup().All(s => s.path != targetScene.path);

                try
                {
                    targetScene = EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
                }
                catch (Exception e)
                {
                    Debug.LogError(Maintainer.ConstructError("Error while opening scene: " + path + "\n" + e));
                    return(result);
                }

                result.scene = targetScene;

                if (!targetScene.IsValid())
                {
                    Debug.LogError(Maintainer.ConstructError("Can't open scene since path leads to invalid scene!"));
                    return(result);
                }
                result.sceneWasLoaded = true;
            }

            result.success = true;

            if (activate)
            {
                SceneManager.SetActiveScene(targetScene);
            }

            return(result);
        }
コード例 #4
0
ファイル: CSSceneTools.cs プロジェクト: dqchess/fire-emblem
        public static bool IsOpenedSceneNeedsToBeClosed(OpenSceneResult lastOpenSceneResult, string nextScenePath = null, bool forceClose = false)
        {
            if (lastOpenSceneResult == null)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(nextScenePath) && nextScenePath == lastOpenSceneResult.scenePath)
            {
                return(false);
            }

            return((lastOpenSceneResult.sceneWasLoaded || forceClose) && EditorSceneManager.loadedSceneCount > 1);
        }