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);
        }
        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));
            });
        }
        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);
        }
        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);
        }