Skip to content

Commit f3851d6

Browse files
authored
feat: NetworkTransform Custom Editor Inspector UI (#1101)
* wip * mvp * polish
1 parent f8f53f3 commit f3851d6

File tree

3 files changed

+137
-5
lines changed

3 files changed

+137
-5
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using Unity.Netcode.Prototyping;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace Unity.Netcode.Editor
6+
{
7+
[CustomEditor(typeof(NetworkTransform))]
8+
public class NetworkTransformEditor : UnityEditor.Editor
9+
{
10+
private SerializedProperty m_SyncPositionXProperty;
11+
private SerializedProperty m_SyncPositionYProperty;
12+
private SerializedProperty m_SyncPositionZProperty;
13+
private SerializedProperty m_SyncRotationXProperty;
14+
private SerializedProperty m_SyncRotationYProperty;
15+
private SerializedProperty m_SyncRotationZProperty;
16+
private SerializedProperty m_SyncScaleXProperty;
17+
private SerializedProperty m_SyncScaleYProperty;
18+
private SerializedProperty m_SyncScaleZProperty;
19+
private SerializedProperty m_PositionThresholdProperty;
20+
private SerializedProperty m_RotAngleThresholdProperty;
21+
private SerializedProperty m_ScaleThresholdProperty;
22+
private SerializedProperty m_InLocalSpaceProperty;
23+
private SerializedProperty m_InterpolateProperty;
24+
25+
private static int s_ToggleOffset = 45;
26+
private static float s_MaxRowWidth = EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth + 5;
27+
private static GUIContent s_PositionLabel = EditorGUIUtility.TrTextContent("Position");
28+
private static GUIContent s_RotationLabel = EditorGUIUtility.TrTextContent("Rotation");
29+
private static GUIContent s_ScaleLabel = EditorGUIUtility.TrTextContent("Scale");
30+
31+
public void OnEnable()
32+
{
33+
m_SyncPositionXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionX));
34+
m_SyncPositionYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionY));
35+
m_SyncPositionZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionZ));
36+
m_SyncRotationXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleX));
37+
m_SyncRotationYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleY));
38+
m_SyncRotationZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleZ));
39+
m_SyncScaleXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleX));
40+
m_SyncScaleYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleY));
41+
m_SyncScaleZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleZ));
42+
m_PositionThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.PositionThreshold));
43+
m_RotAngleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.RotAngleThreshold));
44+
m_ScaleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleThreshold));
45+
m_InLocalSpaceProperty = serializedObject.FindProperty(nameof(NetworkTransform.InLocalSpace));
46+
m_InterpolateProperty = serializedObject.FindProperty(nameof(NetworkTransform.Interpolate));
47+
}
48+
49+
public override void OnInspectorGUI()
50+
{
51+
EditorGUILayout.LabelField("Syncing", EditorStyles.boldLabel);
52+
{
53+
GUILayout.BeginHorizontal();
54+
55+
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField);
56+
var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect);
57+
58+
rect = EditorGUI.PrefixLabel(rect, ctid, s_PositionLabel);
59+
rect.width = s_ToggleOffset;
60+
61+
m_SyncPositionXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncPositionXProperty.boolValue);
62+
rect.x += s_ToggleOffset;
63+
m_SyncPositionYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncPositionYProperty.boolValue);
64+
rect.x += s_ToggleOffset;
65+
m_SyncPositionZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncPositionZProperty.boolValue);
66+
67+
GUILayout.EndHorizontal();
68+
}
69+
{
70+
GUILayout.BeginHorizontal();
71+
72+
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField);
73+
var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect);
74+
75+
rect = EditorGUI.PrefixLabel(rect, ctid, s_RotationLabel);
76+
rect.width = s_ToggleOffset;
77+
78+
m_SyncRotationXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncRotationXProperty.boolValue);
79+
rect.x += s_ToggleOffset;
80+
m_SyncRotationYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncRotationYProperty.boolValue);
81+
rect.x += s_ToggleOffset;
82+
m_SyncRotationZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncRotationZProperty.boolValue);
83+
84+
GUILayout.EndHorizontal();
85+
}
86+
{
87+
GUILayout.BeginHorizontal();
88+
89+
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField);
90+
var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect);
91+
92+
rect = EditorGUI.PrefixLabel(rect, ctid, s_ScaleLabel);
93+
rect.width = s_ToggleOffset;
94+
95+
m_SyncScaleXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncScaleXProperty.boolValue);
96+
rect.x += s_ToggleOffset;
97+
m_SyncScaleYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncScaleYProperty.boolValue);
98+
rect.x += s_ToggleOffset;
99+
m_SyncScaleZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncScaleZProperty.boolValue);
100+
101+
GUILayout.EndHorizontal();
102+
}
103+
104+
EditorGUILayout.Space();
105+
EditorGUILayout.LabelField("Thresholds", EditorStyles.boldLabel);
106+
EditorGUILayout.PropertyField(m_PositionThresholdProperty);
107+
EditorGUILayout.PropertyField(m_RotAngleThresholdProperty);
108+
EditorGUILayout.PropertyField(m_ScaleThresholdProperty);
109+
110+
EditorGUILayout.Space();
111+
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel);
112+
EditorGUILayout.PropertyField(m_InLocalSpaceProperty);
113+
EditorGUILayout.PropertyField(m_InterpolateProperty);
114+
115+
serializedObject.ApplyModifiedProperties();
116+
}
117+
}
118+
}

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.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.netcode.gameobjects/Prototyping/NetworkTransform.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public void NetworkSerialize(NetworkSerializer serializer)
128128
}
129129
}
130130

131+
public bool SyncPositionX = true, SyncPositionY = true, SyncPositionZ = true;
132+
public bool SyncRotAngleX = true, SyncRotAngleY = true, SyncRotAngleZ = true;
133+
public bool SyncScaleX = true, SyncScaleY = true, SyncScaleZ = true;
134+
135+
public float PositionThreshold, RotAngleThreshold, ScaleThreshold;
136+
131137
/// <summary>
132138
/// Sets whether this transform should sync in local space or in world space.
133139
/// This is important to set since reparenting this transform could have issues,
@@ -137,11 +143,8 @@ public void NetworkSerialize(NetworkSerializer serializer)
137143
[Tooltip("Sets whether this transform should sync in local space or in world space")]
138144
public bool InLocalSpace = false;
139145

140-
public bool SyncPositionX = true, SyncPositionY = true, SyncPositionZ = true;
141-
public bool SyncRotAngleX = true, SyncRotAngleY = true, SyncRotAngleZ = true;
142-
public bool SyncScaleX = true, SyncScaleY = true, SyncScaleZ = true;
143-
144-
public float PositionThreshold, RotAngleThreshold, ScaleThreshold;
146+
// todo: revisit after MTT-876
147+
public bool Interpolate = true;
145148

146149
/// <summary>
147150
/// The base amount of sends per seconds to use when range is disabled

0 commit comments

Comments
 (0)