public static SettingsProvider CreateMLAgentsSettings() { var provider = new SettingsProvider(SettingsPath, SettingsScope.Project) { // By default the last token of the path is used as display name if no label is provided. label = "ML-Agents", deactivateHandler = () => { var obj = MLAgentsSettings.GetSerializedSettings(); var settings = obj?.targetObject as MLAgentsSettings; if (settings != null) { if (EditorUtility.IsDirty(settings)) { AssetDatabase.SaveAssets(); } } }, // Populate the search keywords to enable smart search filtering and label highlighting: keywords = new HashSet <string>(new[] { "Number", "Some String" }) }; provider.guiHandler = GUIHandler; return(provider); }
private static void GUIHandler(string searchContext) { var obj = MLAgentsSettings.GetSerializedSettings(); var settings = obj?.targetObject as MLAgentsSettings; if (settings != null) { Undo.RecordObject(settings, "ML-Agents Training Settings"); EditorGUI.BeginChangeCheck(); for (var index = 0; index < settings.Configurations.Count; index++) { var config = settings.Configurations[index]; EditorGUILayout.BeginHorizontal(); config.foldout = EditorGUILayout.Foldout(config.foldout, config.isActive ? config.name + " (Active)" : config.name, config.isActive ? new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold } : EditorStyles.foldout); EditorGUI.BeginDisabledGroup(config.isActive); if (GUILayout.Button("Set Active", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false))) { settings.SetActiveExclusive(config); } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Clone", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false))) { settings.Configurations.Add(config.Clone() as TrainingsConfiguration); } if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false))) { var wantDelete = EditorUtility.DisplayDialog("Delete Configuration " + config.name, "Do you really want to delete " + config.name, "Yes Delete", "Wait what"); if (wantDelete) { removeBuffer.Add(config); } } EditorGUILayout.EndHorizontal(); if (config.foldout) { ++EditorGUI.indentLevel; EditorGUILayout.BeginHorizontal(); // GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); var wasActive = config.isActive; config.isActive = EditorGUILayout.Toggle("Active", config.isActive); if (!wasActive && config.isActive) { settings.SetActiveExclusive(config); } config.name = EditorGUILayout.TextField("Name", config.name); var bgIdent = 0; using (var change = new EditorGUI.ChangeCheckScope()) { bgIdent = GUIColorHelper.SetBackgroundColor(new Color(1, .8f, .8f), !config.HasValidRunID); config.runID = EditorGUILayout.TextField("Run ID", config.runID); GUIColorHelper.ResetBackgroundColor(bgIdent); if (change.changed) { config.runID = config.runID.Replace(" ", "-"); } } EditorGUILayout.BeginHorizontal(); bgIdent = GUIColorHelper.SetBackgroundColor(new Color(1, .8f, .8f), !config.MLAgentsDirExists); config.relPathToMLAgentsDir = EditorGUILayout.TextField("ML Agents Dir Rel.", config.relPathToMLAgentsDir); GUIColorHelper.ResetBackgroundColor(bgIdent); // var folder = EditorGUIUtility.FindTexture("Folder Icon"); if (GUILayout.Button("Open", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false)) ) //, GUILayout.Height(20), GUILayout.Width(24))) { Process.Start(config.AbsolutePathToMlAgentsDir); } if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) { var path = PathHelper.MakeAbsolute(config.relPathToMLAgentsDir); var selectedPath = EditorUtility.OpenFolderPanel("Select ML-Agents Root Directory", Directory.Exists(path) ? path : Application.dataPath, ""); if (Directory.Exists(selectedPath)) { config.relPathToMLAgentsDir = PathHelper.MakeRelative(selectedPath); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); bgIdent = GUIColorHelper.SetBackgroundColor(new Color(1, .8f, .8f), !config.ConfigExists); config.relPathToConfig = EditorGUILayout.TextField("Config Rel.", config.relPathToConfig); GUIColorHelper.ResetBackgroundColor(bgIdent); EditorGUI.BeginDisabledGroup(!config.MLAgentsDirExists); if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) { var path = PathHelper.MakeAbsolute(config.relPathToConfig, config.AbsolutePathToMlAgentsDir); var selectedPath = EditorUtility.OpenFilePanel("Select Trainings Config", Directory.Exists(path) ? path : config.AbsolutePathToMlAgentsDir, "yaml"); if (File.Exists(selectedPath)) { config.relPathToConfig = PathHelper.MakeRelative(selectedPath, config.AbsolutePathToMlAgentsDir); } } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); bgIdent = GUIColorHelper.SetBackgroundColor(new Color(1, .8f, .8f), config.HasInvalidBrain()); config.brainNames = EditorGUILayout.TextField("Brain Names", config.brainNames); GUIColorHelper.ResetBackgroundColor(bgIdent); if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) { var selectedPath = EditorUtility.OpenFilePanel("Add Brain", Application.dataPath, "asset"); if (File.Exists(selectedPath)) { config.AddBrain(selectedPath); } } // if (GUILayout.Button("Remove", GUILayout.ExpandWidth(false))) // { // var selectedPath = EditorUtility.OpenFilePanel("Select Brain", Application.dataPath, "asset"); // if (File.Exists(selectedPath)) // config.RemoveBrain(selectedPath); // } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Optional", EditorStyles.miniBoldLabel); EditorGUILayout.BeginHorizontal(); bgIdent = GUIColorHelper.SetBackgroundColor(new Color(1, .8f, .8f), !string.IsNullOrWhiteSpace(config.relPathToExecutable) && !config.ExecuteableExists); config.relPathToExecutable = EditorGUILayout.TextField("Executable Rel.", config.relPathToExecutable, new GUIStyle(EditorStyles.textField)); GUIColorHelper.ResetBackgroundColor(bgIdent); EditorGUI.BeginDisabledGroup(!config.MLAgentsDirExists); if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) { var path = PathHelper.MakeAbsolute(config.relPathToExecutable, config.AbsolutePathToMlAgentsDir); var selectedPath = EditorUtility.OpenFilePanel("Select Trainings Executable", Directory.Exists(path) ? path : config.AbsolutePathToMlAgentsDir, "exe"); if (File.Exists(selectedPath)) { config.relPathToExecutable = PathHelper.MakeRelative(selectedPath, config.AbsolutePathToMlAgentsDir); } } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); config.anacondaEnvironmentName = EditorGUILayout.TextField("Anaconda Env.", config.anacondaEnvironmentName); EditorGUILayout.BeginHorizontal(); // bgIdent = GUIColorHelper.SetBackgroundColor(new Color(1, .8f, .8f), // !config.CurriculumExistsAndIsValid && !string.IsNullOrWhiteSpace(config.relPathToCurriculum)); // config.relPathToCurriculum = EditorGUILayout.TextField("Curriculum Dir Rel.", config.relPathToCurriculum); config.curriculum = EditorGUILayout.ObjectField("Curriculum", config.curriculum, typeof(Curriculum), false) as Curriculum; // GUIColorHelper.ResetBackgroundColor(bgIdent); // EditorGUI.BeginDisabledGroup(!config.MLAgentsDirExists); // if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) // { // var path = PathHelper.MakeAbsolute(config.relPathToCurriculum, config.AbsolutePathToMlAgentsDir); // var selectedPath = EditorUtility.OpenFolderPanel("Select Curriculum Directory", // Directory.Exists(path) ? path : config.AbsolutePathToMlAgentsDir, // ""); // if (Directory.Exists(selectedPath)) // config.relPathToCurriculum = PathHelper.MakeRelative(selectedPath, config.AbsolutePathToMlAgentsDir); // } // EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Detect Problems", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false))) { config.DetectProblems(); } EditorGUILayout.EndHorizontal(); foreach (var problem in config.detectedProblems) { EditorGUILayout.HelpBox(problem, MessageType.Warning); } --EditorGUI.indentLevel; if (index < settings.Configurations.Count - 1) { GUILayout.Space(15); } } } foreach (var toBeRemoved in removeBuffer) { settings.RemoveConfiguration(toBeRemoved); } removeBuffer.Clear(); GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save Settings")) { EditorUtility.SetDirty(settings); AssetDatabase.SaveAssets(); } if (GUILayout.Button("Add Configuration")) { settings.AddConfiguration(); } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(settings); settings.NotifyChanged(); } GUILayout.Space(10); EditorGUILayout.HelpBox("Current Training Process ID: " + settings.lastTrainingProcessID, MessageType.Info); if (GUILayout.Button("Open Training Window")) { MLAgentsTrainingWindow.OpenWindow(); } GUILayout.Space(10); } }