浏览代码

[MLA-1939] Match3 Custom Editor (#5263)

/check-for-ModelOverriders
GitHub 4 年前
当前提交
578b0900
共有 14 个文件被更改,包括 135 次插入21 次删除
  1. 1
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs
  2. 1
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs
  3. 2
      com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs
  4. 2
      com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs
  5. 2
      com.unity.ml-agents/Editor/GridSensorComponentEditor.cs
  6. 4
      com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
  7. 2
      com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs
  8. 2
      com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs
  9. 36
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs
  10. 23
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs
  11. 38
      com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs
  12. 3
      com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs.meta
  13. 37
      com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs
  14. 3
      com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs.meta

1
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs


using Unity.MLAgents;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgentsExamples

1
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs


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) };
}

2
com.unity.ml-agents/Editor/BufferSensorComponentEditor.cs


namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(BufferSensorComponent))]
[CustomEditor(typeof(BufferSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class BufferSensorComponentEditor : UnityEditor.Editor
{

2
com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs


namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(CameraSensorComponent))]
[CustomEditor(typeof(CameraSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class CameraSensorComponentEditor : UnityEditor.Editor
{

2
com.unity.ml-agents/Editor/GridSensorComponentEditor.cs


namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(GridSensorComponent))]
[CustomEditor(typeof(GridSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class GridSensorComponentEditor : UnityEditor.Editor
{

4
com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs


}
}
[CustomEditor(typeof(RayPerceptionSensorComponent2D))]
[CustomEditor(typeof(RayPerceptionSensorComponent2D), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class RayPerceptionSensorComponent2DEditor : RayPerceptionSensorComponentBaseEditor
{

}
}
[CustomEditor(typeof(RayPerceptionSensorComponent3D))]
[CustomEditor(typeof(RayPerceptionSensorComponent3D), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class RayPerceptionSensorComponent3DEditor : RayPerceptionSensorComponentBaseEditor
{

2
com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs


using Unity.MLAgents.Sensors;
namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(RenderTextureSensorComponent))]
[CustomEditor(typeof(RenderTextureSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class RenderTextureSensorComponentEditor : UnityEditor.Editor
{

2
com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs


namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(VectorSensorComponent))]
[CustomEditor(typeof(VectorSensorComponent), editorForChildClasses: true)]
[CanEditMultipleObjects]
internal class VectorSensorComponentEditor : UnityEditor.Editor
{

36
com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs


[AddComponentMenu("ML Agents/Match 3 Actuator", (int)MenuGroup.Actuators)]
public class Match3ActuatorComponent : ActuatorComponent
{
[HideInInspector, SerializeField, FormerlySerializedAs("ActuatorName")]
string m_ActuatorName = "Match3 Actuator";
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;
[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;
}
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/>

23
com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs


using System;
using Unity.MLAgents.Sensors;
using UnityEngine;
using UnityEngine.Serialization;
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";
public string SensorName = "Match3 Sensor";
public string SensorName
{
get => m_SensorName;
set => m_SensorName = value;
}
[HideInInspector, SerializeField, FormerlySerializedAs("ObservationType")]
Match3ObservationType m_ObservationType = Match3ObservationType.Vector;
public Match3ObservationType ObservationType = Match3ObservationType.Vector;
public Match3ObservationType ObservationType
{
get => m_ObservationType;
set => m_ObservationType = value;
}
private ISensor[] m_Sensors;

Dispose();
var board = GetComponent<AbstractBoard>();
var cellSensor = Match3Sensor.CellTypeSensor(board, ObservationType, SensorName + " (cells)");
var cellSensor = Match3Sensor.CellTypeSensor(board, m_ObservationType, m_SensorName + " (cells)");
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 };

38
com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs


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()
{
}
}
}

3
com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs.meta


fileFormatVersion: 2
guid: b545474cca77481bbc3c6c161dd6bbc3
timeCreated: 1618441761

37
com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs


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()
{
}
}
}

3
com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs.meta


fileFormatVersion: 2
guid: ab55bf118d03479bb797c0037989c308
timeCreated: 1618440499
正在加载...
取消
保存