Skip to content

Commit 3c6b665

Browse files
committed
Adding a custom editor for BufferSensorComponent
1 parent d284c03 commit 3c6b665

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using UnityEditor;
2+
using Unity.MLAgents.Sensors;
3+
4+
namespace Unity.MLAgents.Editor
5+
{
6+
[CustomEditor(typeof(BufferSensorComponent))]
7+
[CanEditMultipleObjects]
8+
internal class BufferSensorComponentEditor : UnityEditor.Editor
9+
{
10+
public override void OnInspectorGUI()
11+
{
12+
var so = serializedObject;
13+
so.Update();
14+
15+
// Drawing the BufferSensorComponent
16+
17+
EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties());
18+
{
19+
// These fields affect the sensor order or observation size,
20+
// So can't be changed at runtime.
21+
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true);
22+
EditorGUILayout.PropertyField(so.FindProperty("m_ObservableSize"), true);
23+
EditorGUILayout.PropertyField(so.FindProperty("m_MaxNumObservables"), true);
24+
}
25+
EditorGUI.EndDisabledGroup();
26+
27+
so.ApplyModifiedProperties();
28+
}
29+
30+
}
31+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.ml-agents/Runtime/Sensors/BufferSensorComponent.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,32 @@ public string SensorName
1919
get { return m_SensorName; }
2020
set { m_SensorName = value; }
2121
}
22-
23-
public string m_SensorName = "BufferSensor";
22+
[HideInInspector, SerializeField]
23+
private string m_SensorName = "BufferSensor";
2424

2525
/// <summary>
2626
/// This is how many floats each entities will be represented with. This number
2727
/// is fixed and all entities must have the same representation.
2828
/// </summary>
29-
public int ObservableSize;
29+
public int ObservableSize
30+
{
31+
get { return m_ObservableSize; }
32+
set { m_ObservableSize = value; }
33+
}
34+
[HideInInspector, SerializeField]
35+
private int m_ObservableSize;
3036

3137
/// <summary>
3238
/// This is the maximum number of entities the `BufferSensor` will be able to
3339
/// collect.
3440
/// </summary>
35-
public int MaxNumObservables;
41+
public int MaxNumObservables
42+
{
43+
get { return m_MaxNumObservables; }
44+
set { m_MaxNumObservables = value; }
45+
}
46+
[HideInInspector, SerializeField]
47+
private int m_MaxNumObservables;
3648

3749
private BufferSensor m_Sensor;
3850

0 commit comments

Comments
 (0)