Example #1
0
        public static int entrySelectedComponent            = 0;                    // currently selected component from the list

        // do a reset of things
        public static void Reset()
        {
            InitComponentTypes();
            ClearSelection();
            Core.FindDefaultTemplates();
            Core.FindUserTemplates();
        }
Example #2
0
        /// <summary>
        /// Given a path to a config, loads the folder config and returns it
        /// </summary>
        /// <param name="configPath"></param>
        /// <returns></returns>
        public static GenericHierarchyConfig LoadConfigFromPath(string configPath)
        {
            var folderConfig = new GenericHierarchyConfig();

            folderConfig = Core.LoadConfig(configPath);
            return(folderConfig);
        }
Example #3
0
        private static void CreateFolder(GenericHierarchyEntry entry, string parent)
        {
            var newPath = string.Empty;         // save the path in case we need to generate a placeholder file
            var created = false;

            if (!AssetDatabase.IsValidFolder(entry.name))
            {
                var guid = AssetDatabase.CreateFolder(parent, entry.name);
                newPath = AssetDatabase.GUIDToAssetPath(guid);
                Debug.Log("Created folder: " + newPath);
                created = true;
            }
            else
            {
                Debug.Log("Folder exists: " + entry.name);
                created = false;
            }

            if (entry.addEmptyPlaceholder && created)
            {
                Core.WriteEmptyFile(newPath);
            }

            if (entry.children != null)
            {
                foreach (var child in entry.children)
                {
                    CreateFolder((GenericHierarchyEntry)child, parent + "/" + entry.name);
                }
            }
        }
Example #4
0
        /// <summary>
        /// makes a duplicate of the active selected config and saves it to the user templates folder with the new filename
        /// </summary>
        /// <param name="path"></param>
        public static void DuplicateConfig(string newFileName)
        {
            var config = LoadConfigFromPath(activeSelection.path);

            Core.SaveConfig(newFileName, config);
            ClearSelection();
        }
Example #5
0
        public static void SaveConfigChanges()
        {
            Debug.Log("Saving config changes to: " + activeSelection.path);

            Core.SaveConfig(activeSelection.fileName, activeConfig);
            ClearSelection();
        }
 /// <summary>
 /// given a config, generate a textarea to display the raw json
 /// </summary>
 /// <param name="config"></param>
 protected void ShowSceneConfigRaw(GenericHierarchyConfig config)
 {
     rawTemplateText  = Core.ConfigToString(config);
     _sceneEditScroll = GUILayout.BeginScrollView(_sceneEditScroll, GUILayout.Width(RIGHTPANELWIDTH), GUILayout.ExpandHeight(true));
     {
         rawTemplateText = GUILayout.TextArea(rawTemplateText, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
     }
     GUILayout.EndScrollView();
 }
 /// <summary>
 /// given a config, generate a textarea to display the raw json
 /// </summary>
 /// <param name="config"></param>
 protected void ShowFolderConfigRaw(GenericHierarchyConfig config)
 {
     rawTemplateText   = Core.ConfigToString(config);
     _folderEditScroll = GUILayout.BeginScrollView(_folderEditScroll, GUILayout.Width(350f), GUILayout.ExpandHeight(true));
     {
         rawTemplateText = GUILayout.TextArea(rawTemplateText, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
     }
     GUILayout.EndScrollView();
 }
        protected void Reset()
        {
            // reset the controller
            Control.Reset();

            _folderEditScroll = Vector2.zero;
            _sceneEditScroll  = Vector2.zero;
            _templateScroll   = Vector2.zero;
            _sceneViewScroll  = Vector2.zero;

            /*
             * Generate our template buttons
             */

            // templates built into the package
            Control.defaultTemplateButtons.Clear();
            foreach (var template in Core.defaultTemplates)
            {
                // load the config
                var config = Core.LoadGenericConfig(template.path);
                var button = new TemplateButtonEntry
                {
                    config      = config,
                    displayName = config.name,
                    fileName    = template.fileName,
                    description = config.description,
                    path        = template.path,
                    type        = config.type,
                    isPressed   = false,
                    isBuiltIn   = true,
                };
                Control.defaultTemplateButtons.Add(button);
            }

            // templates in user-land project space
            Control.userTemplateButtons.Clear();
            foreach (var template in Core.userTemplates)
            {
                var config = Core.LoadGenericConfig(template.path);
                var button = new TemplateButtonEntry
                {
                    config      = config,
                    displayName = config.name,
                    fileName    = template.fileName,
                    description = config.description,
                    path        = template.path,
                    type        = config.type,
                    isPressed   = false,
                    isBuiltIn   = false,
                };
                Control.userTemplateButtons.Add(button);
            }
        }
Example #9
0
        /// <summary>
        /// We've switched to a different config, let's reset and load that config
        /// </summary>
        /// <param name="newSelection"></param>
        public static void SetActiveSelection(TemplateButtonEntry newSelection)
        {
            ClearSelection();
            activeSelection = newSelection;
            // reset template file name for copies
            tempFileName = activeSelection.displayName + " Copy";

            // load the active config
            activeConfig = Core.LoadConfig(activeSelection.path);
            // cache these, they are used in the template editor
            tempConfigNameString        = activeConfig.name;
            tempConfigDescriptionString = activeConfig.description;
        }
        /// <summary>
        /// Delete selected config UI
        /// </summary>
        protected void ShowDeleteConfigUI()
        {
            GUILayout.Space(10f);
            GUILayout.Label(Loc.DELETE_TITLE, EditorStyles.boldLabel, GUILayout.MaxWidth(RIGHTPANELWIDTH));
            GUILayout.Label(Loc.DELETE_HELPTEXT, EditorStyles.helpBox, GUILayout.MaxWidth(RIGHTPANELWIDTH));

            GUILayout.Space(10f);

            if (!Control.activeSelection.isBuiltIn)
            {
                GUI.backgroundColor = Loc.cancelColor;
                if (GUILayout.Button(Loc.DELETE, GUILayout.MaxWidth(RIGHTPANELWIDTH), GUILayout.MaxHeight(STANDARDBUTTONHEIGHT)))
                {
                    if (EditorUtility.DisplayDialog(Loc.DIALOG_CONFIRMDELETE_TITLE,
                                                    Loc.DIALOG_CONFIRMDELETEENTRY_MESSAGE,
                                                    Loc.DIALOG_OK,
                                                    Loc.DIALOG_CANCEL))
                    {
                        Core.DeleteConfig(Control.activeSelection.path);
                    }
                }
                GUI.backgroundColor = Loc.defaultColor;
            }
            else
            {
                GUILayout.BeginHorizontal();
                {
                    GUI.color = Loc.cancelColor;
                    GUILayout.Label(imgClear, GUILayout.Width(SMALLBUTTONSIZE * 2), GUILayout.Height(SMALLBUTTONSIZE * 2));
                    GUI.color = Loc.defaultColor;
                    GUILayout.Label(Loc.DIALOG_CONFIG_DELETE_BUILTIN, EditorStyles.boldLabel, GUILayout.MaxWidth(RIGHTPANELWIDTH));
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.Space(10f);
        }
Example #11
0
        private void OnGUI()
        {
            GUILayout.Space(10f);
            titleContent = new GUIContent(Loc.DIALOG_NEWCONFIG_TITLE);
            GUILayout.Space(10f);

            GUILayout.Label(Loc.DIALOG_NEWCONFIG_MESSAGE, EditorStyles.helpBox);
            GUILayout.Space(10f);

            GUILayout.Label(Loc.DIALOG_NEWCONFIG_SELECTTYPE);
            selectedType = EditorGUILayout.Popup(selectedType, validTypes);
            GUILayout.Space(10f);

            switch (selectedType)
            {
            case (int)TEMPLATE_TYPE.FOLDER:
            {
                GUILayout.Label(Loc.DIALOG_NEWCONFIG_HELP_FOLDER, EditorStyles.helpBox);
                break;
            }

            case (int)TEMPLATE_TYPE.SCENE:
            {
                GUILayout.Label(Loc.DIALOG_NEWCONFIG_HELP_SCENE, EditorStyles.helpBox);
                break;
            }
            }

            GUILayout.Space(10f);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(Loc.DIALOG_NEWCONFIG_FILENAME, GUILayout.Width(LABEL_WIDTH));
                // show our text input and make sure that it's focused
                GUI.SetNextControlName("textInput");
                templateFileName = GUILayout.TextField(templateFileName, GUILayout.ExpandWidth(true));
                if (!focused)
                {
                    GUI.FocusControl("textInput");
                    var te = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                    te.cursorIndex = 1;
                    focused        = true;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(Loc.DIALOG_NEWCONFIG_DISPLAYNAME, GUILayout.Width(LABEL_WIDTH));
                templateDisplayName = GUILayout.TextField(templateDisplayName, GUILayout.ExpandWidth(true));
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(10f);
            GUILayout.BeginHorizontal();
            {
                var style = EditorStyles.miniButton;

                GUI.backgroundColor = Loc.cancelColor;
                if (GUILayout.Button("Cancel", style, GUILayout.Height(35f)))
                {
                    Close();
                }

                GUI.backgroundColor = Loc.doneColor;
                if (GUILayout.Button("Save", style, GUILayout.Height(35f)))
                {
                    if (templateFileName != string.Empty)
                    {
                        switch (selectedType)
                        {
                        case (int)TEMPLATE_TYPE.FOLDER:
                        {
                            var newFolderConfig = new GenericHierarchyConfig()
                            {
                                name = templateDisplayName,
                                type = TEMPLATE_TYPE.FOLDER
                            };
                            // save the new config into the user's templates folder
                            Core.SaveConfig(templateFileName, newFolderConfig);

                            Control.Reset();
                            break;
                        }

                        case (int)TEMPLATE_TYPE.SCENE:
                        {
                            var newSceneConfig = new GenericHierarchyConfig()
                            {
                                name = templateDisplayName,
                                type = TEMPLATE_TYPE.SCENE
                            };
                            // save the new config into the user's templates folder
                            Core.SaveConfig(templateFileName, newSceneConfig);

                            Control.Reset();

                            // attempt to reset the parent window so we can refresh our file list, but doesn't seem to work, unity asset database doesn't refresh in time
                            if (opener.windowType == EditorWindowType.NewSceneWizard)
                            {
                                var parentWindow = (NewSceneWizardView)opener;
                                parentWindow.Reset();
                            }
                            else if (opener.windowType == EditorWindowType.TemplateEditor)
                            {
                                var parentWindow = (TemplateEditorView)opener;
                                parentWindow.Reset();
                            }

                            break;
                        }
                        }
                        Close();
                    }
                }
                GUI.backgroundColor = Loc.defaultColor;
            }
            GUILayout.EndHorizontal();
        }