Beispiel #1
0
        public void SaveBuildSettingsInSceneManager()
        {
            Scene sceneManagerScene = GetSceneManagerScene();

            // make sure there was a scene manager
            if (!sceneManagerScene.IsValid())
            {
                Debug.LogError("Couldn't find SceneManager");
                return;
            }
            // create an empty list
            List <string> scenesToAdd = new List <string>();

            // first load in all the current scenes in the build settings
            foreach (EditorBuildSettingsScene buildScene in EditorBuildSettings.scenes)
            {
                // if this is not the manager scene
                if (sceneManagerScene.path != buildScene.path)
                {
                    // name without extension
                    string sceneName = System.IO.Path.GetFileNameWithoutExtension(buildScene.path);
                    //scenePathsToAdd.Add(buildScene.path);
                    scenesToAdd.Add(sceneName);
                }
            }

            // get access to the SceneManager
            FungusSceneManager fungusSceneManagerScript = GetFungusSceneManagerScript();

            // tell the mananger to save it's paths
            fungusSceneManagerScript.SetScenes(scenesToAdd);

            // force save
            EditorSceneManager.SaveScene(sceneManagerScene);
        }
Beispiel #2
0
        void SaveSceneList()
        {
            // get access to the main script (we are an editor script)
            FungusSceneManager manager = (FungusSceneManager)target;

            // create an empty list
            //List<string> scenePathsToAdd = new List<string>();
            List <string> scenesToAdd = new List <string>();

            // first load in all the current scenes in the build settings
            foreach (EditorBuildSettingsScene buildScene in EditorBuildSettings.scenes)
            {
                // if this is not the manager scene
                if (manager.gameObject.scene.path != buildScene.path)
                {
                    // name without extension
                    string sceneName = System.IO.Path.GetFileNameWithoutExtension(buildScene.path);
                    //scenePathsToAdd.Add(buildScene.path);
                    scenesToAdd.Add(sceneName);
                }
            }

            // tell the mananger to save it's paths
            manager.scenes = scenesToAdd;

            // set the current scene as "dirty"
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
Beispiel #3
0
        protected FungusSceneManager GetFungusSceneManagerScript()
        {
            Scene scene = GetSceneManagerScene();

            // make sure we actually got a scene
            if (!scene.IsValid())
            {
                return(null);
            }

            foreach (GameObject go in scene.GetRootGameObjects())
            {
                FungusSceneManager fungusSceneManager = go.GetComponent <FungusSceneManager>();
                if (fungusSceneManager != null)
                {
                    return(fungusSceneManager);
                }
            }

            return(null);
        }
Beispiel #4
0
        // OnInspectorGUI()


        void DrawScenes()
        {
            // get access to the main script (we are an editor script)
            FungusSceneManager manager = (FungusSceneManager)target;

            // the Save Scene Button

            EditorGUILayout.Space();

            // the List of saved Scenes

            //EditorGUI.BeginChangeCheck();

            //if (GUILayout.Button("Save Build Settings Scene List"))
            //{
            //    SaveSceneList();
            //    Undo.RecordObject(target, "Save Scene List");
            //}
            //EditorGUI.EndChangeCheck();

            EditorGUILayout.Space();

            foldoutScenes = EditorGUILayout.Foldout(foldoutScenes, "Scenes (" + manager.scenes.Count + ")");

            if (foldoutScenes)
            {
                //foreach (string path in manager.paths)
                foreach (string sceneName in manager.scenes)
                {
                    //Scene scene = EditorSceneManager.GetSceneByName(sceneName);
                    //                string filename = System.IO.Path.GetFileName(path);
                    //string name = System.IO.Path.GetFileNameWithoutExtension(path);
                    EditorGUILayout.LabelField(sceneName);
                }

                this.Repaint();
            }

            EditorGUILayout.Space();
        }
Beispiel #5
0
        //        void CreateCharacters(Scene newScene)
        //        {
        //            //GameObject charactersPrefab = Resources.Load<GameObject>("CharacterManager/Prefabs/Characters");
        //            //// this is the path to the prefab
        //            ////string charactersPrefabPath = "Assets/FungusManager/CharacterManager/Prefabs/FungusCharacters.prefab";
        //            //// find out if there already is a prefab in our project
        //            //string projectCharactersPrefabPath = GetPrefabPath("FungusCharacterManager");
        //            //// if we found something
        //            //if (projectCharactersPrefabPath != "")
        //            //{
        //            //    // use this prefab path instead of the one in the project path
        //            //    charactersPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(projectCharactersPrefabPath, typeof(GameObject));
        //            //}

        //            //GameObject charactersGameObject = PrefabUtility.InstantiatePrefab(charactersPrefab, newScene) as GameObject;

        //            //// if this is a new prefab
        //            //if (projectCharactersPrefabPath == "")
        //            //{
        //            //    // make sure this prefab goes into the same folder at the Start scene's folder
        //            //    string newPrefabFolder = path + "/FungusCharacterManager.prefab";
        //            //    // save it to new position
        //            //    GameObject newPrefab = PrefabUtility.CreatePrefab(newPrefabFolder, charactersGameObject) as GameObject;
        //            //    // set this as our prefab
        //            //    PrefabUtility.ConnectGameObjectToPrefab(charactersGameObject, newPrefab);
        //            //}
        //        }


        //        protected Scene GetCleanScene(bool emptyScene = true)
        //        {
        //            Scene managerScene = GetSceneManagerScene();

        //            // close the other scene
        //            for (int i = 0; i < EditorSceneManager.sceneCount; i++)
        //            {
        //                Scene scene = EditorSceneManager.GetSceneAt(i);
        //                // leave manager scene
        //                if (managerScene.IsValid() && managerScene == scene) continue;
        //                // close anything else
        //                if (!EditorSceneManager.CloseScene(scene, true))
        //                {
        //                    Debug.LogError("Couldn't close scene " + scene.name);
        //                    return new Scene();
        //                }
        //            }

        //            if (managerScene.IsValid())
        //            {
        //                SetSceneToActive(managerScene);
        //            }

        //            // return an empty or default scene depending on whether we're using the Hyperzoom system or not
        //            if (emptyScene) return EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
        //            return EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Additive);

        //        }

        #endregion



        #region Scene List

        private void DisplayScenes()
        {
            FungusSceneManager fungusSceneManagerScript = GetFungusSceneManagerScript();

            if (fungusSceneManagerScript == null)
            {
                return;
            }

            List <string> scenes = fungusSceneManagerScript.scenes;

            displayScenesScroll = EditorGUILayout.BeginScrollView(displayScenesScroll);

            foreach (string scene in scenes)
            {
                if (scene != null)
                {
                    DisplayScene(scene);
                }
            }

            EditorGUILayout.EndScrollView();
        }
Beispiel #6
0
        protected Scene GetSceneManagerScene()
        {
            for (int i = 0; i < EditorSceneManager.sceneCount; i++)
            {
                Scene scene = EditorSceneManager.GetSceneAt(i);

                // ignore scene that just closed
                if (!scene.IsValid() || !scene.isLoaded)
                {
                    continue;
                }

                foreach (GameObject go in scene.GetRootGameObjects())
                {
                    FungusSceneManager fungusSceneManager = go.GetComponent <FungusSceneManager>();
                    if (fungusSceneManager != null)
                    {
                        return(scene);
                    }
                }
            }
            // return an empty scene
            return(new Scene());
        }