Beispiel #1
0
        private void AddNewScene()
        {
            _showAddNewScene = EditorGUILayout.Foldout(_showAddNewScene, "Add New Scene", true, EditorStyles.boldLabel);
            if (!_showAddNewScene)
            {
                return;
            }

            DrawSceneModel(_newSceneToAdd, SceneDataLocation.None);

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Add a scene"))
            {
                //Validate new scene model, add and reset it
                if (_newSceneToAdd.ValidateSelf())
                {
                    _scenesData.Scenes.Add(_newSceneToAdd);
                    _newSceneToAdd = new SceneModel();
                }
                else
                {
                    EditorUtility.DisplayDialog("Error adding scene", "Some fields are emty or incorrect. Please fix it.", "OK");
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (GUILayout.Button("Reset All Fields"))
            {
                if (EditorUtility.DisplayDialog("Reset fields?", "Are you sure you want to reset all fields of the new scene?",
                                                "YES",
                                                "NO"))
                {
                    _newSceneToAdd = new SceneModel();
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GuiLine();
        }
Beispiel #2
0
        /// <summary>
        /// Base Method to draw a scene data model.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dataLocation"></param>
        private void DrawSceneModel(SceneModel model, SceneDataLocation dataLocation)
        {
            GuiLine();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            if (string.IsNullOrEmpty(model.SceneName))
            {
                EditorGUILayout.LabelField("Name of the new scene : " + NoSceneSelected);
            }
            else
            {
                EditorGUILayout.LabelField("Name of the new scene : " + model.SceneName);
            }

            if (dataLocation != SceneDataLocation.None)
            {
                if (GUILayout.Button("Remove scene"))
                {
                    if (dataLocation == SceneDataLocation.FromData)
                    {
                        var scenes = new List <SceneModel>(_scenesData.Scenes);
                        scenes.Remove(model);
                        _scenesData.Scenes = scenes;
                    }

                    if (dataLocation == SceneDataLocation.FromSelectedFolder)
                    {
                        var scenes = new List <SceneModel>(_scenesInSelectedFolder.Scenes);
                        scenes.Remove(model);
                        _scenesInSelectedFolder.Scenes = scenes;
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (string.IsNullOrEmpty(model.ScenePathInProject))
            {
                EditorGUILayout.LabelField("Path to scene : " + NoSceneSelected);
            }
            else
            {
                EditorGUILayout.LabelField("Path to scene : " + model.SceneVisblePathInProject);
            }

            if (GUILayout.Button("Select Scene"))
            {
                var pathToNewScene = EditorUtility.OpenFilePanel("Select Scene To Add", Application.dataPath, "unity");
                if (!string.IsNullOrEmpty(pathToNewScene))
                {
                    //Check if scene with the same path alredy presents in list
                    if (_scenesData.Scenes.Any(x => x.ScenePathInProject == pathToNewScene))
                    {
                        EditorUtility.DisplayDialog("Duplicate scene", "Scene with path: " + pathToNewScene + " already presenst in data",
                                                    "OK");
                        return;
                    }
                    else
                    {
                        var testSceneName = Path.GetFileNameWithoutExtension(pathToNewScene);
                        Debug.Log(testSceneName);

                        model.SceneName          = testSceneName;
                        model.ScenePathInProject = pathToNewScene;
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            model.SceneVisibleName =
                EditorGUILayout.TextField("Your alias for the scene : ", model.SceneVisibleName);

            model.OrderNumber = EditorGUILayout.IntField("Order number among menu items : ", model.OrderNumber);

            EditorGUILayout.EndHorizontal();
        }
Beispiel #3
0
        private void DrawSelectFolderToSearchScenes()
        {
            _scenesInFolderLabel = "Add scenes in folder (" + _scenesInSelectedFolder.Count + ")";
            _showSelectFolder    = EditorGUILayout.Foldout(_showSelectFolder, _scenesInFolderLabel, true, EditorStyles.boldLabel);
            if (!_showSelectFolder)
            {
                return;
            }

            GuiLine();

            EditorGUILayout.Space();
            EditorGUILayout.Space();


            EditorGUILayout.LabelField("Select folder to search scenes automatically. All found scenes in this folder will be processed.");

            EditorGUILayout.BeginHorizontal();

            //Select folder and recusrively scan contents to find scenes
            if (GUILayout.Button("Select Folder"))
            {
                var path = EditorUtility.OpenFolderPanel("Select folder to scan", Application.dataPath, "");
                var sceneFilesInDirectory = Directory.GetFiles(path, "*.unity", SearchOption.AllDirectories);
                _selectedFolder = path;
                foreach (var file in sceneFilesInDirectory)
                {
                    var sceneModel = new SceneModel(file);
                    _scenesInSelectedFolder.Scenes.Add(sceneModel);
                }
            }

            EditorGUILayout.LabelField("Selected folder : " + _selectedFolder);

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Scenes in selected folder : " + _scenesInSelectedFolder.Count);

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Add Selected Scenes"))
            {
                var processedScenesDictionary = _scenesData.Scenes.ToDictionary(x => x.ScenePathInProject, x => x);
                foreach (var scene in _scenesInSelectedFolder.Scenes)
                {
                    if (!processedScenesDictionary.ContainsKey(scene.ScenePathInProject))
                    {
                        processedScenesDictionary.Add(scene.ScenePathInProject, scene);
                    }
                }
                _scenesData.Scenes = processedScenesDictionary.Values.ToList();
                _scenesInSelectedFolder.Scenes.Clear();
            }

            if (GUILayout.Button("Reset Selection"))
            {
                if (EditorUtility.DisplayDialog("Reset selected folder?", "Are you sure you want to reset selected folder?", "YES",
                                                "NO"))
                {
                    _selectedFolder         = "";
                    _scenesInSelectedFolder = new ScenesData();
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            _showDataInSelectedFolder = EditorGUILayout.Foldout(_showDataInSelectedFolder, "Scenes in selected folder", true, EditorStyles.boldLabel);
            if (_showDataInSelectedFolder && _scenesInSelectedFolder.Count != 0)
            {
                _folderScenesPosition = GUILayout.BeginScrollView(_folderScenesPosition);

                foreach (var scene in _scenesInSelectedFolder.Scenes)
                {
                    DrawSceneModel(scene, SceneDataLocation.FromSelectedFolder);
                }
                GUILayout.EndScrollView();
            }
        }