diff --git a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs index a277635a3f..d54e824df0 100644 --- a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs +++ b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs @@ -1,4 +1,3 @@ -using Unity.MLAgents; using Unity.MLAgents.Integrations.Match3; namespace Unity.MLAgentsExamples diff --git a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs index c3501bada4..ca70181be0 100644 --- a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs +++ b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs @@ -10,7 +10,6 @@ public class Match3ExampleActuatorComponent : Match3ActuatorComponent public override IActuator[] CreateActuators() { var board = GetComponent(); - var agent = GetComponentInParent(); var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1; return new IActuator[] { new Match3ExampleActuator(board, ForceHeuristic, ActuatorName, seed) }; } diff --git a/com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs b/com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs index 32d3b9e2fc..f41edb2740 100644 --- a/com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs @@ -3,7 +3,7 @@ namespace Unity.MLAgents.Editor { - [CustomEditor(typeof(BufferSensorComponent))] + [CustomEditor(typeof(BufferSensorComponent), editorForChildClasses: true)] [CanEditMultipleObjects] internal class BufferSensorComponentEditor : UnityEditor.Editor { diff --git a/com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs b/com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs index c77cc86409..5b84f43554 100644 --- a/com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs @@ -3,7 +3,7 @@ namespace Unity.MLAgents.Editor { - [CustomEditor(typeof(CameraSensorComponent))] + [CustomEditor(typeof(CameraSensorComponent), editorForChildClasses: true)] [CanEditMultipleObjects] internal class CameraSensorComponentEditor : UnityEditor.Editor { diff --git a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs index a16b1a3d19..02e89b4696 100644 --- a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs @@ -4,7 +4,7 @@ namespace Unity.MLAgents.Editor { - [CustomEditor(typeof(GridSensorComponent))] + [CustomEditor(typeof(GridSensorComponent), editorForChildClasses: true)] [CanEditMultipleObjects] internal class GridSensorComponentEditor : UnityEditor.Editor { diff --git a/com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs b/com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs new file mode 100644 index 0000000000..0ae31172dd --- /dev/null +++ b/com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs @@ -0,0 +1,38 @@ +using UnityEditor; +using Unity.MLAgents.Integrations.Match3; +namespace Unity.MLAgents.Editor +{ + [CustomEditor(typeof(Match3ActuatorComponent), editorForChildClasses: true)] + [CanEditMultipleObjects] + internal class Match3ActuatorComponentEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + var so = serializedObject; + so.Update(); + + // Drawing the RenderTextureComponent + EditorGUI.BeginChangeCheck(); + + EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); + { + EditorGUILayout.PropertyField(so.FindProperty("m_ActuatorName"), true); + EditorGUILayout.PropertyField(so.FindProperty("m_RandomSeed"), true); + } + EditorGUI.EndDisabledGroup(); + EditorGUILayout.PropertyField(so.FindProperty("m_ForceHeuristic"), true); + + var requireSensorUpdate = EditorGUI.EndChangeCheck(); + so.ApplyModifiedProperties(); + + if (requireSensorUpdate) + { + UpdateActuator(); + } + } + + void UpdateActuator() + { + } + } +} diff --git a/com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs.meta b/com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs.meta new file mode 100644 index 0000000000..ce515a1234 --- /dev/null +++ b/com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b545474cca77481bbc3c6c161dd6bbc3 +timeCreated: 1618441761 \ No newline at end of file diff --git a/com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs b/com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs new file mode 100644 index 0000000000..a8673e09d9 --- /dev/null +++ b/com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs @@ -0,0 +1,37 @@ +using UnityEditor; +using Unity.MLAgents.Integrations.Match3; +namespace Unity.MLAgents.Editor +{ + [CustomEditor(typeof(Match3SensorComponent), editorForChildClasses: true)] + [CanEditMultipleObjects] + internal class Match3SensorComponentEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + var so = serializedObject; + so.Update(); + + // Drawing the RenderTextureComponent + EditorGUI.BeginChangeCheck(); + + EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); + { + EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true); + EditorGUILayout.PropertyField(so.FindProperty("m_ObservationType"), true); + } + EditorGUI.EndDisabledGroup(); + + var requireSensorUpdate = EditorGUI.EndChangeCheck(); + so.ApplyModifiedProperties(); + + if (requireSensorUpdate) + { + UpdateSensor(); + } + } + + void UpdateSensor() + { + } + } +} diff --git a/com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs.meta b/com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs.meta new file mode 100644 index 0000000000..82a80140ed --- /dev/null +++ b/com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ab55bf118d03479bb797c0037989c308 +timeCreated: 1618440499 \ No newline at end of file diff --git a/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs b/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs index 2d619745e4..17a10a0c26 100644 --- a/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs +++ b/com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs @@ -87,7 +87,7 @@ void UpdateSensorIfDirty() } } - [CustomEditor(typeof(RayPerceptionSensorComponent2D))] + [CustomEditor(typeof(RayPerceptionSensorComponent2D), editorForChildClasses: true)] [CanEditMultipleObjects] internal class RayPerceptionSensorComponent2DEditor : RayPerceptionSensorComponentBaseEditor { @@ -97,7 +97,7 @@ public override void OnInspectorGUI() } } - [CustomEditor(typeof(RayPerceptionSensorComponent3D))] + [CustomEditor(typeof(RayPerceptionSensorComponent3D), editorForChildClasses: true)] [CanEditMultipleObjects] internal class RayPerceptionSensorComponent3DEditor : RayPerceptionSensorComponentBaseEditor { diff --git a/com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs b/com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs index 6bd69e14bb..8e5fd892d3 100644 --- a/com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs @@ -2,7 +2,7 @@ using Unity.MLAgents.Sensors; namespace Unity.MLAgents.Editor { - [CustomEditor(typeof(RenderTextureSensorComponent))] + [CustomEditor(typeof(RenderTextureSensorComponent), editorForChildClasses: true)] [CanEditMultipleObjects] internal class RenderTextureSensorComponentEditor : UnityEditor.Editor { diff --git a/com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs b/com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs index ff1cfd2e78..883153aab1 100644 --- a/com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs @@ -3,7 +3,7 @@ namespace Unity.MLAgents.Editor { - [CustomEditor(typeof(VectorSensorComponent))] + [CustomEditor(typeof(VectorSensorComponent), editorForChildClasses: true)] [CanEditMultipleObjects] internal class VectorSensorComponentEditor : UnityEditor.Editor { diff --git a/com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs b/com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs index 9d5f17afbc..e7b35dca9a 100644 --- a/com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs +++ b/com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs @@ -10,30 +10,50 @@ namespace Unity.MLAgents.Integrations.Match3 [AddComponentMenu("ML Agents/Match 3 Actuator", (int)MenuGroup.Actuators)] public class Match3ActuatorComponent : ActuatorComponent { + [HideInInspector, SerializeField, FormerlySerializedAs("ActuatorName")] + string m_ActuatorName = "Match3 Actuator"; + /// /// Name of the generated Match3Actuator object. /// Note that changing this at runtime does not affect how the Agent sorts the actuators. /// - public string ActuatorName = "Match3 Actuator"; + public string ActuatorName + { + get => m_ActuatorName; + set => m_ActuatorName = value; + } + + [HideInInspector, SerializeField, FormerlySerializedAs("RandomSeed")] + int m_RandomSeed = -1; /// - /// A random seed used to generate a board, if needed. + /// A random seed used in the actuator's heuristic, if needed. /// - public int RandomSeed = -1; + public int RandomSeed + { + get => m_RandomSeed; + set => m_RandomSeed = value; + } + + [HideInInspector, SerializeField, FormerlySerializedAs("ForceHeuristic")] + [Tooltip("Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.")] + bool m_ForceHeuristic; /// /// Force using the Agent's Heuristic() method to decide the action. This should only be used in testing. /// - [FormerlySerializedAs("ForceRandom")] - [Tooltip("Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.")] - public bool ForceHeuristic; + public bool ForceHeuristic + { + get => m_ForceHeuristic; + set => m_ForceHeuristic = value; + } /// public override IActuator[] CreateActuators() { var board = GetComponent(); - var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1; - return new IActuator[] { new Match3Actuator(board, ForceHeuristic, seed, ActuatorName) }; + var seed = m_RandomSeed == -1 ? gameObject.GetInstanceID() : m_RandomSeed + 1; + return new IActuator[] { new Match3Actuator(board, m_ForceHeuristic, seed, m_ActuatorName) }; } /// diff --git a/com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs b/com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs index 69efcfbb7d..f1b455a928 100644 --- a/com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs +++ b/com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs @@ -1,6 +1,7 @@ using System; using Unity.MLAgents.Sensors; using UnityEngine; +using UnityEngine.Serialization; namespace Unity.MLAgents.Integrations.Match3 { @@ -10,16 +11,30 @@ namespace Unity.MLAgents.Integrations.Match3 [AddComponentMenu("ML Agents/Match 3 Sensor", (int)MenuGroup.Sensors)] public class Match3SensorComponent : SensorComponent, IDisposable { + [HideInInspector, SerializeField, FormerlySerializedAs("SensorName")] + string m_SensorName = "Match3 Sensor"; + /// /// Name of the generated Match3Sensor object. /// Note that changing this at runtime does not affect how the Agent sorts the sensors. /// - public string SensorName = "Match3 Sensor"; + public string SensorName + { + get => m_SensorName; + set => m_SensorName = value; + } + + [HideInInspector, SerializeField, FormerlySerializedAs("ObservationType")] + Match3ObservationType m_ObservationType = Match3ObservationType.Vector; /// /// Type of observation to generate. /// - public Match3ObservationType ObservationType = Match3ObservationType.Vector; + public Match3ObservationType ObservationType + { + get => m_ObservationType; + set => m_ObservationType = value; + } private ISensor[] m_Sensors; @@ -30,9 +45,9 @@ public override ISensor[] CreateSensors() Dispose(); var board = GetComponent(); - var cellSensor = Match3Sensor.CellTypeSensor(board, ObservationType, SensorName + " (cells)"); + var cellSensor = Match3Sensor.CellTypeSensor(board, m_ObservationType, m_SensorName + " (cells)"); // This can be null if numSpecialTypes is 0 - var specialSensor = Match3Sensor.SpecialTypeSensor(board, ObservationType, SensorName + " (special)"); + var specialSensor = Match3Sensor.SpecialTypeSensor(board, m_ObservationType, m_SensorName + " (special)"); m_Sensors = specialSensor != null ? new ISensor[] { cellSensor, specialSensor } : new ISensor[] { cellSensor };