public static bool OnOpenSceneSet(int instanceID, int line)
        {
            Object unityObject = EditorUtility.InstanceIDToObject(instanceID);

            if (unityObject?.GetType() == typeof(SceneSet))
            {
                SceneSet targetSet = unityObject as SceneSet;

                if (targetSet.SetScenes.Count == 0)
                {
                    return(true);
                }

                int loadMode = EditorUtility.DisplayDialogComplex("Load Scene Set", "Select load mode.", "Full",
                                                                  "Additive (Keep Current Scenes)", "Cancel");

                if (loadMode == 0)
                {
                    targetSet.LoadSceneSet(false);
                }
                else if (loadMode == 1)
                {
                    targetSet.LoadSceneSet(true);
                }

                return(true);
            }

            return(false);
        }
        public static void CreateSceneSetFromScene()
        {
            SceneSet newSceneSet = CreateInstance <SceneSet>();

            SceneField newSceneField = new SceneField
            {
                SceneAsset = Selection.activeObject, SceneName = Selection.activeObject.name
            };

            newSceneSet.SetScenes.Add(newSceneField);

            AssetDatabase.CreateAsset(newSceneSet,
                                      AssetDatabase.GetAssetPath(Selection.activeObject)
                                      .Replace(".unity", " Scene Set.asset"));

            AssetDatabase.Refresh();

            Selection.activeObject = newSceneSet;
        }
Exemple #3
0
        /// <summary>
        ///     Draws the header panel.
        /// </summary>
        private void DrawHeaderPanel()
        {
            List <GUIContent> sceneSetContent = new List <GUIContent>();

            sceneSetContent.Add(new GUIContent("None"));

            foreach (SceneSet set in _sceneSets)
            {
                sceneSetContent.Add(new GUIContent(set.name));
            }

            _selectedSceneSet = EditorGUILayout.Popup(_selectedSceneSet, sceneSetContent.ToArray());

            List <GUIContent> sceneContent = new List <GUIContent>();

            sceneContent.Add(new GUIContent("Load Any Scene"));

            foreach (SceneAsset scene in _scenes)
            {
                sceneContent.Add(new GUIContent(scene.name));
            }

            int selectedScene = EditorGUILayout.Popup(0, sceneContent.ToArray());

            if (selectedScene > 0)
            {
                int loadMode = EditorUtility.DisplayDialogComplex("Load Scene", "Select load mode.", "Full",
                                                                  "Additive (Keep Current Scenes", "Cancel");

                if (loadMode == 0)
                {
                    EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(_scenes[selectedScene - 1]),
                                                 OpenSceneMode.Single);
                }
                else if (loadMode == 1)
                {
                    EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(_scenes[selectedScene - 1]),
                                                 OpenSceneMode.Additive);
                }
            }

            if (SOFlowEditorUtilities.DrawColourButton("Refresh", Color.cyan))
            {
                _sceneSets.Clear();
                _scenes.Clear();

                string[] assetFiles = Directory.GetFiles(Application.dataPath, "*.asset", SearchOption.AllDirectories);
                string[] sceneFiles = Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories);

                foreach (string file in assetFiles)
                {
                    try
                    {
                        SceneSet set =
                            AssetDatabase.LoadAssetAtPath <SceneSet>(file.Replace($"{Application.dataPath}\\",
                                                                                  "Assets/"));

                        if (set != null)
                        {
                            _sceneSets.Add(set);
                        }
                    }
                    catch
                    {
                        // Ignore
                    }
                }

                foreach (string file in sceneFiles)
                {
                    try
                    {
                        SceneAsset scene =
                            AssetDatabase.LoadAssetAtPath <SceneAsset>(file.Replace($"{Application.dataPath}\\",
                                                                                    "Assets/"));

                        if (scene != null)
                        {
                            _scenes.Add(scene);
                        }
                    }
                    catch
                    {
                        // Ignore
                    }
                }

                _sceneSets.Sort((firstScene, secondScene) => firstScene.name.CompareTo(secondScene.name));
                _scenes.Sort((firstScene, secondScene) => firstScene.name.CompareTo(secondScene.name));
            }
        }
Exemple #4
0
 private void OnEnable()
 {
     _target = (SceneSet)target;
 }