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.Log("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; }
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.layoutsGroupStyle); #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.layoutsGroupStyle); #endif drawerHandlersLists[enabledToShowDrawerType].DoList(); #if UNITY_2019_3_OR_NEWER EditorGUILayout.EndVertical(); #endif #if UNITY_2019_3_OR_NEWER EditorGUILayout.BeginVertical(Style.layoutsGroupStyle); #endif EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(Style.clearListContent, EditorStyles.miniButtonLeft)) { Undo.RecordObject(target, "Clear Drawers"); switch (enabledToShowDrawerType) { case 0: currentTarget.DecoratorDrawerHandlers.Clear(); break; case 1: currentTarget.ConditionDrawerHandlers.Clear(); break; case 2: currentTarget.SelfPropertyDrawerHandlers.Clear(); break; case 3: currentTarget.ListPropertyDrawerHandlers.Clear(); break; case 4: currentTarget.TargetTypeDrawerHandlers.Clear(); 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.Log("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--; }