-
Notifications
You must be signed in to change notification settings - Fork 450
feat: NetworkTransform Custom Editor Inspector UI #1101
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
6 commits
Select commit
Hold shift + click to select a range
fefa891
wip
0xFA11 0bdb073
mvp
0xFA11 e3d9221
polish
0xFA11 1d1209a
Merge branch 'develop' into feat/NetTransUI
0xFA11 30cd47f
Merge branch 'develop' into feat/NetTransUI
0xFA11 683d775
Merge branch 'develop' into feat/NetTransUI
0xFA11 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
118 changes: 118 additions & 0 deletions
118
com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.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,118 @@ | ||
using Unity.Netcode.Prototyping; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Unity.Netcode.Editor | ||
{ | ||
[CustomEditor(typeof(NetworkTransform))] | ||
public class NetworkTransformEditor : UnityEditor.Editor | ||
{ | ||
private SerializedProperty m_SyncPositionXProperty; | ||
private SerializedProperty m_SyncPositionYProperty; | ||
private SerializedProperty m_SyncPositionZProperty; | ||
private SerializedProperty m_SyncRotationXProperty; | ||
private SerializedProperty m_SyncRotationYProperty; | ||
private SerializedProperty m_SyncRotationZProperty; | ||
private SerializedProperty m_SyncScaleXProperty; | ||
private SerializedProperty m_SyncScaleYProperty; | ||
private SerializedProperty m_SyncScaleZProperty; | ||
private SerializedProperty m_PositionThresholdProperty; | ||
private SerializedProperty m_RotAngleThresholdProperty; | ||
private SerializedProperty m_ScaleThresholdProperty; | ||
private SerializedProperty m_InLocalSpaceProperty; | ||
private SerializedProperty m_InterpolateProperty; | ||
|
||
private static int s_ToggleOffset = 45; | ||
private static float s_MaxRowWidth = EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth + 5; | ||
private static GUIContent s_PositionLabel = EditorGUIUtility.TrTextContent("Position"); | ||
private static GUIContent s_RotationLabel = EditorGUIUtility.TrTextContent("Rotation"); | ||
private static GUIContent s_ScaleLabel = EditorGUIUtility.TrTextContent("Scale"); | ||
|
||
public void OnEnable() | ||
{ | ||
m_SyncPositionXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionX)); | ||
m_SyncPositionYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionY)); | ||
m_SyncPositionZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionZ)); | ||
m_SyncRotationXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleX)); | ||
m_SyncRotationYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleY)); | ||
m_SyncRotationZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleZ)); | ||
m_SyncScaleXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleX)); | ||
m_SyncScaleYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleY)); | ||
m_SyncScaleZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleZ)); | ||
m_PositionThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.PositionThreshold)); | ||
m_RotAngleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.RotAngleThreshold)); | ||
m_ScaleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleThreshold)); | ||
m_InLocalSpaceProperty = serializedObject.FindProperty(nameof(NetworkTransform.InLocalSpace)); | ||
m_InterpolateProperty = serializedObject.FindProperty(nameof(NetworkTransform.Interpolate)); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
EditorGUILayout.LabelField("Syncing", EditorStyles.boldLabel); | ||
{ | ||
GUILayout.BeginHorizontal(); | ||
|
||
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); | ||
var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); | ||
|
||
rect = EditorGUI.PrefixLabel(rect, ctid, s_PositionLabel); | ||
rect.width = s_ToggleOffset; | ||
|
||
m_SyncPositionXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncPositionXProperty.boolValue); | ||
rect.x += s_ToggleOffset; | ||
m_SyncPositionYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncPositionYProperty.boolValue); | ||
rect.x += s_ToggleOffset; | ||
m_SyncPositionZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncPositionZProperty.boolValue); | ||
|
||
GUILayout.EndHorizontal(); | ||
} | ||
{ | ||
GUILayout.BeginHorizontal(); | ||
|
||
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); | ||
var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); | ||
|
||
rect = EditorGUI.PrefixLabel(rect, ctid, s_RotationLabel); | ||
rect.width = s_ToggleOffset; | ||
|
||
m_SyncRotationXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncRotationXProperty.boolValue); | ||
rect.x += s_ToggleOffset; | ||
m_SyncRotationYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncRotationYProperty.boolValue); | ||
rect.x += s_ToggleOffset; | ||
m_SyncRotationZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncRotationZProperty.boolValue); | ||
|
||
GUILayout.EndHorizontal(); | ||
} | ||
{ | ||
GUILayout.BeginHorizontal(); | ||
|
||
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); | ||
var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); | ||
|
||
rect = EditorGUI.PrefixLabel(rect, ctid, s_ScaleLabel); | ||
rect.width = s_ToggleOffset; | ||
|
||
m_SyncScaleXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncScaleXProperty.boolValue); | ||
rect.x += s_ToggleOffset; | ||
m_SyncScaleYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncScaleYProperty.boolValue); | ||
rect.x += s_ToggleOffset; | ||
m_SyncScaleZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncScaleZProperty.boolValue); | ||
|
||
GUILayout.EndHorizontal(); | ||
} | ||
|
||
EditorGUILayout.Space(); | ||
EditorGUILayout.LabelField("Thresholds", EditorStyles.boldLabel); | ||
EditorGUILayout.PropertyField(m_PositionThresholdProperty); | ||
EditorGUILayout.PropertyField(m_RotAngleThresholdProperty); | ||
EditorGUILayout.PropertyField(m_ScaleThresholdProperty); | ||
|
||
EditorGUILayout.Space(); | ||
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel); | ||
EditorGUILayout.PropertyField(m_InLocalSpaceProperty); | ||
EditorGUILayout.PropertyField(m_InterpolateProperty); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.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
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.
@SamuelBellomo — I put this flag here for the future (also into the UI). IIRC, we wanted to expose only a bool flag for interpolation over the UI, hope this makes sense :)