internal static SettingsProvider SettingsProvider()
        {
            var provider = new SettingsProvider("Project/Editor Toolbox", SettingsScope.Project);

            void ReintializeProvider()
            {
                InitializeSettings();

                //rebuild the settings provider right after initialization
                provider.OnDeactivate();
                provider.OnActivate("", null);
            }

            provider.guiHandler = (searchContext) =>
            {
                if (globalSettingsEditor == null || globalSettingsEditor.serializedObject.targetObject == null)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Cannot find " + settingsType + " file located in this Project");
                    EditorGUILayout.Space();

                    if (GUILayout.Button("Create a new settings file"))
                    {
                        var settingsInstance = ScriptableObject.CreateInstance(settingsType);

                        var locationPath = EditorUtility.OpenFolderPanel("New Settings file location", "Assets", "");
                        //validate returned path and create relative one if possible
                        if (string.IsNullOrEmpty(locationPath))
                        {
                            return;
                        }

                        var relativePath = locationPath
                                           .Substring(locationPath
                                                      .IndexOf("Assets/")) + "/" + settingsType + ".asset";

                        AssetDatabase.CreateAsset(settingsInstance, relativePath);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();

                        ToolboxEditorLog.LogMessage("Created a settings file at - " + relativePath);

                        ReintializeProvider();
                    }

                    return;
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Settings file location - " + SettingsPath);
                EditorGUILayout.Space();

                globalSettingsEditor.OnInspectorGUI();
            };
            provider.activateHandler = (searchContext, elements) =>
            {
                globalSettingsEditor = Editor.CreateEditor(Settings);
            };
            provider.deactivateHandler = () =>
            {
                Object.DestroyImmediate(globalSettingsEditor);
            };
            provider.titleBarGuiHandler = () =>
            {
                if (GUILayout.Button(new GUIContent("Refresh", "Try to find a settings file in the main (Assets) directory")))
                {
                    ReintializeProvider();
                }
            };

            return(provider);
        }
Beispiel #2
0
        private void DrawInspectorSettings()
        {
            EditorGUI.indentLevel++;
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(useToolboxDrawersProperty);
            EditorGUILayout.Space();

            var validateInspector = false;

#if UNITY_2019_3_OR_NEWER
            EditorGUILayout.BeginVertical(Style.groupStyle);
#endif
#if UNITY_2019_3_OR_NEWER
            enabledToShowDrawerType = GUILayout.Toolbar(enabledToShowDrawerType, drawerHandlersShortNames, EditorStyles.toolbarButton);
#else
            enabledToShowDrawerType = GUILayout.Toolbar(enabledToShowDrawerType, drawerHandlersShortNames);
#endif
            EditorGUI.BeginDisabledGroup(!useToolboxDrawersProperty.boolValue);

            var longName = drawerHandlersLongNames[enabledToShowDrawerType];
            var tooltip  = drawerHandlersInfoLabels[enabledToShowDrawerType];
            var content  = new GUIContent(longName + " Drawers", tooltip);
            EditorGUILayout.LabelField(content, Style.drawersHeaderStyle);

#if UNITY_2019_3_OR_NEWER
            EditorGUILayout.EndVertical();
#endif
#if UNITY_2019_3_OR_NEWER
            EditorGUILayout.BeginVertical(Style.groupStyle);
#endif
            drawerHandlersLists[enabledToShowDrawerType].DoLayoutList();
#if UNITY_2019_3_OR_NEWER
            EditorGUILayout.EndVertical();
#endif
#if UNITY_2019_3_OR_NEWER
            EditorGUILayout.BeginVertical(Style.groupStyle);
#endif
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(Style.clearListContent, EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(target, "Clear Drawers");
                switch (enabledToShowDrawerType)
                {
                case 0:
                    currentTarget.ClearDecoratorDrawerHandlers();
                    break;

                case 1:
                    currentTarget.ClearConditionDrawerHandlers();
                    break;

                case 2:
                    currentTarget.ClearSelfPropertyDrawerHandlers();
                    break;

                case 3:
                    currentTarget.ClearListPropertyDrawerHandlers();
                    break;

                case 4:
                    currentTarget.ClearTargetTypeDrawerHandlers();
                    break;
                }
                validateInspector = true;
            }

            if (GUILayout.Button(Style.assignAllContent, EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(target, "Assign Drawers");
                switch (enabledToShowDrawerType)
                {
                case 0:
                    currentTarget.SetAllPossibleDecoratorDrawers();
                    break;

                case 1:
                    currentTarget.SetAllPossibleConditionDrawers();
                    break;

                case 2:
                    currentTarget.SetAllPossibleSelfPropertyDrawers();
                    break;

                case 3:
                    currentTarget.SetAllPossibleListPropertyDrawers();
                    break;

                case 4:
                    currentTarget.SetAllPossibleTargetTypeDrawers();
                    break;
                }
                validateInspector = true;
            }

            if (GUILayout.Button(Style.validListContent, EditorStyles.miniButtonRight))
            {
                ToolboxEditorLog.LogMessage("Function not implemented, force recompilation to validate drawers assignment.");
            }
            EditorGUILayout.EndHorizontal();
#if UNITY_2019_3_OR_NEWER
            EditorGUILayout.EndVertical();
#endif
            EditorGUILayout.Space();

            if (validateInspector)
            {
                currentTarget.ValidateInspectorSettings();
            }

            EditorGUI.EndDisabledGroup();

            if (EditorGUI.EndChangeCheck())
            {
                currentTarget.SetInspectorSettingsDirty();
            }
            EditorGUI.indentLevel--;
        }
Beispiel #3
0
        internal static SettingsProvider SettingsProvider()
        {
            var provider = new SettingsProvider("Project/Editor Toolbox", SettingsScope.Project);

            provider.guiHandler = (searchContext) =>
            {
                if (globalSettingsEditor == null || globalSettingsEditor.serializedObject.targetObject == null)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Cannot find " + settingsType + " file located in this Project");
                    EditorGUILayout.Space();

                    void InitializeProvider()
                    {
                        provider.OnDeactivate();
                        provider.OnActivate("", null);
                    }

                    if (GUILayout.Button("Try to find the settings file"))
                    {
                        InitializeSettings();
                        InitializeProvider();
                    }

                    if (GUILayout.Button("Create the new settings file"))
                    {
                        var settingsInstance = ScriptableObject.CreateInstance(settingsType);

                        var directoryPath = EditorUtility.OpenFolderPanel("New Settings file location", "Assets", "");
                        var settingsPath  = directoryPath.Substring(directoryPath.IndexOf("Assets/")) + "/" + settingsType + ".asset";

                        AssetDatabase.CreateAsset(settingsInstance, settingsPath);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();

                        ToolboxEditorLog.LogMessage("Created the settings file at - " + settingsPath);

                        InitializeSettings();
                        InitializeProvider();
                    }

                    return;
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Settings file location - " + SettingsPath);
                EditorGUILayout.Space();

                globalSettingsEditor.serializedObject.Update();
                globalSettingsEditor.OnInspectorGUI();
                globalSettingsEditor.serializedObject.ApplyModifiedProperties();
            };
            provider.activateHandler = (searchContext, elements) =>
            {
                globalSettingsEditor = Editor.CreateEditor(Settings);
            };
            provider.deactivateHandler = () =>
            {
                Object.DestroyImmediate(globalSettingsEditor);
            };

            return(provider);
        }