コード例 #1
0
        static public void SaveSceneAsset()
        {
            string savePath = DetectSaveDatas();

            SceneSaveAsset sceneSaveAsset = ScriptableObject.CreateInstance <SceneSaveAsset>();

            CreateRuntimeSceneLoaderIfRequired(sceneSaveAsset);

            sceneSaveAsset.SceneSetups = ConvertEditorToRuntimeSceneSetups(EditorSceneManager.GetSceneManagerSetup());

            AssetDatabase.CreateAsset(sceneSaveAsset, savePath);
            AssetDatabase.Refresh(ImportAssetOptions.Default);
        }
コード例 #2
0
        private static void RemoveDeletedScenes(ref SceneSaveAsset SaveAsset)
        {
            SaveAsset.SceneSetups = Array.FindAll <RuntimeSceneSetup>(SaveAsset.SceneSetups, (RuntimeSceneSetup InSceneSetup) =>
            {
                string scenePath = InSceneSetup.path;
                if (string.IsNullOrEmpty(scenePath))
                {
                    return(false);
                }

                string fullPath = Path.GetFullPath(scenePath);
                return(File.Exists(fullPath));
            });
        }
コード例 #3
0
        public static bool LoadSceneAsset()
        {
            string savePath = DetectSaveDatas();

            SceneSaveAsset saveAsset = AssetDatabase.LoadAssetAtPath <SceneSaveAsset>(savePath);

            if (saveAsset)
            {
                RemoveDeletedScenes(ref saveAsset);

                EditorSceneManager.RestoreSceneManagerSetup(ConvertRuntimeToEditorSceneSetups(saveAsset.SceneSetups));
                return(true);
            }

            return(false);
        }
コード例 #4
0
        private static void CreateRuntimeSceneLoaderIfRequired(SceneSaveAsset SaveAsset)
        {
            Scene sceneBackup = EditorSceneManager.GetActiveScene();

            {
                RuntimeSceneLoader runtimeSceneLoader = GameObject.FindObjectOfType <RuntimeSceneLoader>();

                if (runtimeSceneLoader == null)
                {
                    GameObject runtimeSceneLoaderGo = new GameObject();
                    runtimeSceneLoaderGo.name = "RuntimeSceneLoader";
                    runtimeSceneLoader        = runtimeSceneLoaderGo.AddComponent <RuntimeSceneLoader>();
                }

                if (runtimeSceneLoader.SceneDataAsset == null)
                {
                    runtimeSceneLoader.SceneDataAsset = SaveAsset;
                }
            }
            EditorSceneManager.SetActiveScene(sceneBackup);
        }