Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Unity.MLAgents;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There's another one in actuator component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a pass on Rider suggestions later.

using Unity.MLAgents.Integrations.Match3;

namespace Unity.MLAgentsExamples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class Match3ExampleActuatorComponent : Match3ActuatorComponent
public override IActuator[] CreateActuators()
{
var board = GetComponent<Match3Board>();
var agent = GetComponentInParent<Agent>();
var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1;
return new IActuator[] { new Match3ExampleActuator(board, ForceHeuristic, ActuatorName, seed) };
}
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(BufferSensorComponent))]
[CustomEditor(typeof(BufferSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class BufferSensorComponentEditor : UnityEditor.Editor
{
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(CameraSensorComponent))]
[CustomEditor(typeof(CameraSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class CameraSensorComponentEditor : UnityEditor.Editor
{
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Editor/GridSensorComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(GridSensorComponent))]
[CustomEditor(typeof(GridSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class GridSensorComponentEditor : UnityEditor.Editor
{
Expand Down
38 changes: 38 additions & 0 deletions com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, but keeping in place if we need it later. Can remove if desired.

}
}

void UpdateActuator()
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs
Original file line number Diff line number Diff line change
@@ -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()
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void UpdateSensorIfDirty()
}
}

[CustomEditor(typeof(RayPerceptionSensorComponent2D))]
[CustomEditor(typeof(RayPerceptionSensorComponent2D), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class RayPerceptionSensorComponent2DEditor : RayPerceptionSensorComponentBaseEditor
{
Expand All @@ -97,7 +97,7 @@ public override void OnInspectorGUI()
}
}

[CustomEditor(typeof(RayPerceptionSensorComponent3D))]
[CustomEditor(typeof(RayPerceptionSensorComponent3D), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class RayPerceptionSensorComponent3DEditor : RayPerceptionSensorComponentBaseEditor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(VectorSensorComponent))]
[CustomEditor(typeof(VectorSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class VectorSensorComponentEditor : UnityEditor.Editor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Name of the generated Match3Actuator object.
/// Note that changing this at runtime does not affect how the Agent sorts the actuators.
/// </summary>
public string ActuatorName = "Match3 Actuator";
public string ActuatorName
{
get => m_ActuatorName;
set => m_ActuatorName = value;
}

[HideInInspector, SerializeField, FormerlySerializedAs("RandomSeed")]
int m_RandomSeed = -1;

/// <summary>
/// A random seed used to generate a board, if needed.
/// A random seed used in the actuator's heuristic, if needed.
/// </summary>
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;

/// <summary>
/// Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.
/// </summary>
[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;
}

/// <inheritdoc/>
public override IActuator[] CreateActuators()
{
var board = GetComponent<AbstractBoard>();
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) };
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Unity.MLAgents.Sensors;
using UnityEngine;
using UnityEngine.Serialization;

namespace Unity.MLAgents.Integrations.Match3
{
Expand All @@ -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";

/// <summary>
/// Name of the generated Match3Sensor object.
/// Note that changing this at runtime does not affect how the Agent sorts the sensors.
/// </summary>
public string SensorName = "Match3 Sensor";
public string SensorName
{
get => m_SensorName;
set => m_SensorName = value;
}

[HideInInspector, SerializeField, FormerlySerializedAs("ObservationType")]
Match3ObservationType m_ObservationType = Match3ObservationType.Vector;

/// <summary>
/// Type of observation to generate.
/// </summary>
public Match3ObservationType ObservationType = Match3ObservationType.Vector;
public Match3ObservationType ObservationType
{
get => m_ObservationType;
set => m_ObservationType = value;
}

private ISensor[] m_Sensors;

Expand All @@ -30,9 +45,9 @@ public override ISensor[] CreateSensors()
Dispose();

var board = GetComponent<AbstractBoard>();
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 };
Expand Down