-
Notifications
You must be signed in to change notification settings - Fork 4.3k
RaycastPerceptionComponent custom editor #3484
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
827c254
WIP
e25849c
private, property, formerlyserializedas (tags broken)
c5bfdf3
update on property changes
38f9a30
draw gizmos outside of play mode
3af34cd
disable options that affect observation shape in play mode
f9e34ed
handle 2D
51370a3
undo version change
dd77f0b
Merge remote-tracking branch 'origin/master' into develop-raycast-cus…
7e9134c
cleanup, access
7bb20b1
changelog
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using Barracuda; | ||
|
||
namespace MLAgents | ||
{ | ||
internal class RayPerceptionSensorComponentBaseEditor : Editor | ||
{ | ||
bool m_RequireSensorUpdate; | ||
|
||
protected void OnRayPerceptionInspectorGUI(bool is3d) | ||
{ | ||
var so = serializedObject; | ||
so.Update(); | ||
|
||
// Drawing the RayPerceptionSensorComponent | ||
EditorGUI.BeginChangeCheck(); | ||
EditorGUI.indentLevel++; | ||
|
||
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true); | ||
|
||
// Because the number of rays and the tags affect the observation shape, | ||
// they are not editable during play mode. | ||
EditorGUI.BeginDisabledGroup(Application.isPlaying); | ||
{ | ||
EditorGUILayout.PropertyField(so.FindProperty("m_DetectableTags"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_RaysPerDirection"), true); | ||
} | ||
EditorGUI.EndDisabledGroup(); | ||
|
||
EditorGUILayout.PropertyField(so.FindProperty("m_MaxRayDegrees"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_SphereCastRadius"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_RayLength"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_RayLayerMask"), true); | ||
|
||
// Because the number of observation stacks affects the observation shape, | ||
// it is not editable during play mode. | ||
EditorGUI.BeginDisabledGroup(Application.isPlaying); | ||
{ | ||
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationStacks"), true); | ||
} | ||
EditorGUI.EndDisabledGroup(); | ||
|
||
if (is3d) | ||
{ | ||
EditorGUILayout.PropertyField(so.FindProperty("m_StartVerticalOffset"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("m_EndVerticalOffset"), true); | ||
} | ||
|
||
EditorGUILayout.PropertyField(so.FindProperty("rayHitColor"), true); | ||
EditorGUILayout.PropertyField(so.FindProperty("rayMissColor"), true); | ||
|
||
EditorGUI.indentLevel--; | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
m_RequireSensorUpdate = true; | ||
} | ||
|
||
UpdateSensorIfDirty(); | ||
so.ApplyModifiedProperties(); | ||
} | ||
|
||
|
||
void UpdateSensorIfDirty() | ||
{ | ||
if (m_RequireSensorUpdate) | ||
{ | ||
var sensorComponent = serializedObject.targetObject as RayPerceptionSensorComponentBase; | ||
sensorComponent?.UpdateSensor(); | ||
m_RequireSensorUpdate = false; | ||
} | ||
} | ||
} | ||
|
||
[CustomEditor(typeof(RayPerceptionSensorComponent2D))] | ||
[CanEditMultipleObjects] | ||
internal class RayPerceptionSensorComponent2DEditor : RayPerceptionSensorComponentBaseEditor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
OnRayPerceptionInspectorGUI(false); | ||
} | ||
} | ||
|
||
[CustomEditor(typeof(RayPerceptionSensorComponent3D))] | ||
[CanEditMultipleObjects] | ||
internal class RayPerceptionSensorComponent3DEditor : RayPerceptionSensorComponentBaseEditor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
OnRayPerceptionInspectorGUI(true); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 19 additions & 3 deletions
22
com.unity.ml-agents/Runtime/Sensor/RayPerceptionSensorComponent3D.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: attributes should go on the same line if they fit.