Esempio n. 1
0
 private void ValidateDrawers()
 {
     ToolboxEditorLog.LogInfo("Function not implemented.");
 }
        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(string.Empty, null);
            }

            provider.guiHandler = (searchContext) =>
            {
                if (globalSettingsEditor == null || globalSettingsEditor.serializedObject.targetObject == null)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField(string.Format("Cannot find {0} file located in this Project", settingsType));
                    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 assetName    = string.Format("{0}.asset", settingsType);
                        var relativePath = Path.Combine(FileUtil.GetProjectRelativePath(locationPath), assetName);

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

                        ToolboxEditorLog.LogInfo("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);
        }