Skip to content

Commit a51365f

Browse files
update
Moving the property field draw method into the NetcodeEditorBase class in case we wanted to expose it at a later date and/or want to use it for another I-view control.
1 parent 15a6f9f commit a51365f

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

com.unity.netcode.gameobjects/Editor/NetcodeEditorBase.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,30 @@ namespace Unity.Netcode.Editor
1111
[CanEditMultipleObjects]
1212
public partial class NetcodeEditorBase<TT> : UnityEditor.Editor where TT : MonoBehaviour
1313
{
14+
private const int k_IndentOffset = 15;
15+
1416
/// <inheritdoc cref="UnityEditor.Editor.OnEnable"/>
1517
public virtual void OnEnable()
1618
{
1719
}
1820

21+
/// <summary>
22+
/// Will draw a property field with an indention level using the default or a specified offset per indention.
23+
/// </summary>
24+
/// <param name="property">The serialized property to draw as a default field</param>
25+
/// <param name="indentLevel">The indention level.</param>
26+
/// <param name="offset">Optional indention level offset.</param>
27+
protected internal void DrawIndentedPropertyField(SerializedProperty property, int indentLevel, int offset = k_IndentOffset)
28+
{
29+
var originalWidth = EditorGUIUtility.labelWidth;
30+
EditorGUIUtility.labelWidth = originalWidth - (indentLevel * offset);
31+
EditorGUILayout.BeginHorizontal();
32+
EditorGUILayout.Space(indentLevel * offset, false);
33+
EditorGUILayout.PropertyField(property, GUILayout.ExpandWidth(true));
34+
EditorGUILayout.EndHorizontal();
35+
EditorGUIUtility.labelWidth = originalWidth;
36+
}
37+
1938
/// <summary>
2039
/// Helper method to draw the properties of the specified child type <typeparamref name="T"/> component within a FoldoutHeaderGroup.
2140
/// </summary>

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class NetworkTransformEditor : NetcodeEditorBase<NetworkTransform>
4343
private SerializedProperty m_AuthorityMode;
4444

4545
private static int s_ToggleOffset = 45;
46-
private static int s_IndentOffset = 15;
46+
4747
private static float s_MaxRowWidth = EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth + 5;
4848
private static GUIContent s_PositionLabel = EditorGUIUtility.TrTextContent("Position");
4949
private static GUIContent s_RotationLabel = EditorGUIUtility.TrTextContent("Rotation");
@@ -192,30 +192,30 @@ private void DisplayNetworkTransformProperties()
192192
{
193193
if (networkTransform.SynchronizePosition)
194194
{
195-
DrawIndentedPropertyField(1, m_PositionInterpolationTypeProperty);
195+
DrawIndentedPropertyField(m_PositionInterpolationTypeProperty, 1);
196196
// Only display when using Lerp.
197197
if (networkTransform.PositionInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
198198
{
199-
DrawIndentedPropertyField(2, m_SlerpPosition);
200-
DrawIndentedPropertyField(2, m_PositionMaximumInterpolationTimeProperty);
199+
DrawIndentedPropertyField(m_SlerpPosition, 2);
200+
DrawIndentedPropertyField(m_PositionMaximumInterpolationTimeProperty, 2);
201201
}
202202
}
203203
if (networkTransform.SynchronizeRotation)
204204
{
205-
DrawIndentedPropertyField(1, m_RotationInterpolationTypeProperty);
205+
DrawIndentedPropertyField(m_RotationInterpolationTypeProperty, 1);
206206
// Only display when using Lerp.
207207
if (networkTransform.RotationInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
208208
{
209-
DrawIndentedPropertyField(2, m_RotationMaximumInterpolationTimeProperty);
209+
DrawIndentedPropertyField(m_RotationMaximumInterpolationTimeProperty, 2);
210210
}
211211
}
212212
if (networkTransform.SynchronizeScale)
213213
{
214-
DrawIndentedPropertyField(1, m_ScaleInterpolationTypeProperty);
214+
DrawIndentedPropertyField(m_ScaleInterpolationTypeProperty, 1);
215215
// Only display when using Lerp.
216216
if (networkTransform.ScaleInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
217217
{
218-
DrawIndentedPropertyField(2, m_ScaleMaximumInterpolationTimeProperty);
218+
DrawIndentedPropertyField(m_ScaleMaximumInterpolationTimeProperty, 2);
219219
}
220220
}
221221
}
@@ -250,17 +250,6 @@ private void DisplayNetworkTransformProperties()
250250
#endif // COM_UNITY_MODULES_PHYSICS2D
251251
}
252252

253-
private void DrawIndentedPropertyField(int indentLevel, SerializedProperty property)
254-
{
255-
var originalWidth = EditorGUIUtility.labelWidth;
256-
EditorGUIUtility.labelWidth = originalWidth - (indentLevel * s_IndentOffset) - 2;
257-
EditorGUILayout.BeginHorizontal();
258-
EditorGUILayout.Space(indentLevel * s_IndentOffset, false);
259-
EditorGUILayout.PropertyField(property, GUILayout.ExpandWidth(true));
260-
EditorGUILayout.EndHorizontal();
261-
EditorGUIUtility.labelWidth = originalWidth;
262-
}
263-
264253
/// <inheritdoc/>
265254
public override void OnInspectorGUI()
266255
{

0 commit comments

Comments
 (0)