-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[change] public SensorComponent fields to properties, add custom editor #3564
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using MLAgents.Sensors; | ||
|
||
namespace MLAgents.Editor | ||
{ | ||
[CustomEditor(typeof(CameraSensorComponent))] | ||
[CanEditMultipleObjects] | ||
internal class CameraSensorComponentEditor : UnityEditor.Editor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
var so = serializedObject; | ||
so.Update(); | ||
|
||
// Drawing the CameraSensorComponent | ||
EditorGUI.BeginChangeCheck(); | ||
|
||
EditorGUILayout.PropertyField(so.FindProperty("m_Camera"), true); | ||
EditorGUI.BeginDisabledGroup(Application.isPlaying); | ||
{ | ||
// These fields affect the sensor order or observation size, | ||
// So can't be changed at runtime. | ||
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_Width"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_Height"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_Grayscale"), true); | ||
} | ||
EditorGUI.EndDisabledGroup(); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_Compression"), true); | ||
|
||
var requireSensorUpdate = EditorGUI.EndChangeCheck(); | ||
so.ApplyModifiedProperties(); | ||
|
||
if (requireSensorUpdate) | ||
{ | ||
UpdateSensor(); | ||
} | ||
} | ||
|
||
void UpdateSensor() | ||
{ | ||
var sensorComponent = serializedObject.targetObject as CameraSensorComponent; | ||
sensorComponent?.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using MLAgents.Sensors; | ||
namespace MLAgents.Editor | ||
{ | ||
[CustomEditor(typeof(RenderTextureSensorComponent))] | ||
[CanEditMultipleObjects] | ||
internal class RenderTextureSensorComponentEditor : UnityEditor.Editor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
var so = serializedObject; | ||
so.Update(); | ||
|
||
// Drawing the RenderTextureComponent | ||
EditorGUI.BeginChangeCheck(); | ||
|
||
EditorGUI.BeginDisabledGroup(Application.isPlaying); | ||
{ | ||
EditorGUILayout.PropertyField(so.FindProperty("m_RenderTexture"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_Grayscale"), true); | ||
} | ||
EditorGUI.EndDisabledGroup(); | ||
|
||
EditorGUILayout.PropertyField(so.FindProperty("m_Compression"), true); | ||
|
||
var requireSensorUpdate = EditorGUI.EndChangeCheck(); | ||
so.ApplyModifiedProperties(); | ||
|
||
if (requireSensorUpdate) | ||
{ | ||
UpdateSensor(); | ||
} | ||
} | ||
|
||
void UpdateSensor() | ||
{ | ||
var sensorComponent = serializedObject.targetObject as RenderTextureSensorComponent; | ||
sensorComponent?.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 |
---|---|---|
|
@@ -45,9 +45,7 @@ enum BehaviorType | |
/// <summary> | ||
/// The team ID for this behavior. | ||
/// </summary> | ||
[HideInInspector] | ||
[SerializeField] | ||
[FormerlySerializedAs("m_TeamID")] | ||
[HideInInspector, SerializeField, FormerlySerializedAs("m_TeamID")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do that ?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a simple find-and-replace for the ones for HideInInspector+ SerializeField+ FormerlySerializedAs. That's as much effort as I want to put into it for this PR. |
||
public int TeamId; | ||
|
||
[FormerlySerializedAs("m_useChildSensors")] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make more sense to store "m_SensorName" and such in private const in case they are used somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, not quite sure what you mean. The user needs to assign a unique name to each sensor so that we can sort them deterministically, so the name here can't be const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think he means the string, make it a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here or in the component? We currently only use them in one place, and it's kinda redundant because of reflection.
We could do something like this:
https://stackoverflow.com/a/33059272/224264
although to use
nameof
we'd need to make the fields internal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only use it here, I think it is fine.