Пример #1
0
        /// <summary>
        /// Called when the user wants to create a new menu.
        /// </summary>
        /// <param name="menuCreatorPreset"></param>
        private void CreateMenu(MenuCreatorPreset menuCreatorPreset)
        {
            GameObject newMenu = Instantiate(menuCreatorPreset.PresetObject, _editorMenuCreatorSettings.MenuController.transform);

            Undo.RegisterCreatedObjectUndo(newMenu, "Created menu");

            MCMenu mcMenu = newMenu.GetComponentInChildren <MCMenu>();

            if (mcMenu)
            {
                AddMenuToController(mcMenu);
            }
        }
Пример #2
0
        /// <summary>
        /// Create a new preset.
        /// </summary>
        /// <param name="newFileName"></param>
        /// <returns></returns>
        private MenuCreatorPreset CreatePreset(string newFileName)
        {
            if (string.IsNullOrEmpty(newFileName))
            {
                CreatePreset("newPreset");
            }
            string path = string.Format("{0}/{1}.asset", EditorMenuCreatorSettings.GetPresetsLocation(), newFileName);

            Debug.Log("Creating at: " + path);
            if (AssetDatabase.LoadAssetAtPath(path, typeof(MenuCreatorPreset)))
            {
                return(CreatePreset(newFileName + "_"));
            }

            MenuCreatorPreset menuCreatorPreset = CreateInstance <MenuCreatorPreset>();

            menuCreatorPreset.Title = newFileName;
            AssetDatabase.CreateAsset(menuCreatorPreset, path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            return(menuCreatorPreset);
        }
Пример #3
0
        public static MenuCreatorPreset[] GetAllPresets()
        {
            EditorMenuCreatorSettings settings = GetEditorMenuCreatorSettings();

            if (settings.HasCustomPresetFolder)
            {
                List <MenuCreatorPreset> result = new List <MenuCreatorPreset>();

                string[] aMaterialFiles = Directory.GetFiles(settings.CustomPresetFolderFull, "*.asset", SearchOption.AllDirectories);
                foreach (string matFile in aMaterialFiles)
                {
                    string            assetPath         = string.Format("Assets{0}", matFile.Replace(Application.dataPath, "").Replace('\\', '/'));
                    MenuCreatorPreset menuCreatorPreset = AssetDatabase.LoadAssetAtPath <MenuCreatorPreset>(assetPath);
                    result.Add(menuCreatorPreset);
                }
                return(result.ToArray());
            }
            else
            {
                return(Resources.LoadAll <MenuCreatorPreset>(""));
            }
        }
Пример #4
0
        /// <summary>
        /// Draw the create preset panel.
        /// </summary>
        private void DrawCreatePreset()
        {
            bool hasPresets = CheckPresets();

            if (!hasPresets)
            {
                EditorGUILayout.HelpBox("You don't seem to have any presets, start by creating one!", MessageType.Info);
            }

            EditorGUILayout.BeginHorizontal();

            _newFileName = GUILayout.TextField(_newFileName, 20);

            if (GUILayout.Button("Create new"))
            {
                CreatePreset(_newFileName);
                UpdatePresetsList();
            }

            EditorGUILayout.EndHorizontal();

            if (!hasPresets)
            {
                return;
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayout.Label("Preset list", EditorStyles.centeredGreyMiniLabel);

            _scrollPositionPresetList = EditorGUILayout.BeginScrollView(_scrollPositionPresetList);
            for (int i = 0; i < _presets.Length; i++)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(_presets[i].Title))
                {
                    _currentSelectedPreset = _presets[i];
                }
                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayout.Label("Preset detail", EditorStyles.centeredGreyMiniLabel);

            if (_currentSelectedPreset != null)
            {
                _scrollPositionPresetDetail = EditorGUILayout.BeginScrollView(_scrollPositionPresetDetail);
                Editor editor = Editor.CreateEditor(_currentSelectedPreset);
                editor.DrawDefaultInspector();

                EditorGUILayout.Space();

                if (_currentSelectedPreset.PresetObject)
                {
                    MCMenu mcMenu = _currentSelectedPreset.PresetObject.GetComponentInChildren <MCMenu>();
                    if (mcMenu)
                    {
                        Editor mcEditor = Editor.CreateEditor(mcMenu);
                        mcEditor.DrawDefaultInspector();
                    }
                }
                EditorGUILayout.EndScrollView();
            }
        }