You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AgentEditor.cs 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace MLAgents
  4. {
  5. /*
  6. This code is meant to modify the behavior of the inspector on Brain Components.
  7. Depending on the type of brain that is used, the available fields will be modified in the inspector accordingly.
  8. */
  9. [CustomEditor(typeof(Agent), true)]
  10. [CanEditMultipleObjects]
  11. public class AgentEditor : Editor
  12. {
  13. public override void OnInspectorGUI()
  14. {
  15. SerializedObject serializedAgent = serializedObject;
  16. serializedAgent.Update();
  17. SerializedProperty brain = serializedAgent.FindProperty("brain");
  18. SerializedProperty actionsPerDecision = serializedAgent.FindProperty(
  19. "agentParameters.numberOfActionsBetweenDecisions");
  20. SerializedProperty maxSteps = serializedAgent.FindProperty(
  21. "agentParameters.maxStep");
  22. SerializedProperty isResetOnDone = serializedAgent.FindProperty(
  23. "agentParameters.resetOnDone");
  24. SerializedProperty isODD = serializedAgent.FindProperty(
  25. "agentParameters.onDemandDecision");
  26. SerializedProperty cameras = serializedAgent.FindProperty(
  27. "agentParameters.agentCameras");
  28. SerializedProperty renderTextures = serializedAgent.FindProperty(
  29. "agentParameters.agentRenderTextures");
  30. EditorGUILayout.PropertyField(brain);
  31. if (cameras.arraySize > 0 && renderTextures.arraySize > 0)
  32. {
  33. EditorGUILayout.HelpBox("Brain visual observations created by first getting all cameras then all render textures.", MessageType.Info);
  34. }
  35. EditorGUILayout.LabelField("Agent Cameras");
  36. for (int i = 0; i < cameras.arraySize; i++)
  37. {
  38. EditorGUILayout.PropertyField(
  39. cameras.GetArrayElementAtIndex(i),
  40. new GUIContent("Camera " + (i + 1).ToString() + ": "));
  41. }
  42. EditorGUILayout.BeginHorizontal();
  43. if (GUILayout.Button("Add Camera", EditorStyles.miniButton))
  44. {
  45. cameras.arraySize++;
  46. }
  47. if (GUILayout.Button("Remove Camera", EditorStyles.miniButton))
  48. {
  49. cameras.arraySize--;
  50. }
  51. EditorGUILayout.EndHorizontal();
  52. EditorGUILayout.LabelField("Agent RenderTextures");
  53. for (int i = 0; i < renderTextures.arraySize; i++)
  54. {
  55. EditorGUILayout.PropertyField(
  56. renderTextures.GetArrayElementAtIndex(i),
  57. new GUIContent("RenderTexture " + (i + 1).ToString() + ": "));
  58. }
  59. EditorGUILayout.BeginHorizontal();
  60. if (GUILayout.Button("Add RenderTextures", EditorStyles.miniButton))
  61. {
  62. renderTextures.arraySize++;
  63. }
  64. if (GUILayout.Button("Remove RenderTextures", EditorStyles.miniButton))
  65. {
  66. renderTextures.arraySize--;
  67. }
  68. EditorGUILayout.EndHorizontal();
  69. EditorGUILayout.PropertyField(
  70. maxSteps,
  71. new GUIContent(
  72. "Max Step", "The per-agent maximum number of steps."));
  73. EditorGUILayout.PropertyField(
  74. isResetOnDone,
  75. new GUIContent(
  76. "Reset On Done",
  77. "If checked, the agent will reset on done. Else, AgentOnDone() will be called."));
  78. EditorGUILayout.PropertyField(
  79. isODD,
  80. new GUIContent(
  81. "On Demand Decisions",
  82. "If checked, you must manually request decisions."));
  83. if (!isODD.boolValue)
  84. {
  85. EditorGUILayout.PropertyField(
  86. actionsPerDecision,
  87. new GUIContent(
  88. "Decision Interval",
  89. "The agent will automatically request a decision every X" +
  90. " steps and perform an action at every step."));
  91. actionsPerDecision.intValue = Mathf.Max(1, actionsPerDecision.intValue);
  92. }
  93. serializedAgent.ApplyModifiedProperties();
  94. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  95. base.OnInspectorGUI();
  96. }
  97. }
  98. }