Skip to content

Commit ee37977

Browse files
update
Adding final touches to the UI updates for the NetworkTransformEditor. Also did a PVP pass for all of the editor related classes.
1 parent 536da81 commit ee37977

File tree

6 files changed

+116
-27
lines changed

6 files changed

+116
-27
lines changed

com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33

44
namespace Unity.Netcode.Editor.Configuration
55
{
6+
/// <summary>
7+
/// A <see cref="ScriptableSingleton{T}"/> of type <see cref="NetcodeForGameObjectsProjectSettings"/>.
8+
/// </summary>
69
[FilePath("ProjectSettings/NetcodeForGameObjects.asset", FilePathAttribute.Location.ProjectFolder)]
710
public class NetcodeForGameObjectsProjectSettings : ScriptableSingleton<NetcodeForGameObjectsProjectSettings>
811
{
912
internal static readonly string DefaultNetworkPrefabsPath = "Assets/DefaultNetworkPrefabs.asset";
13+
/// <summary>
14+
/// The path and name for the DefaultNetworkPrefabs asset.
15+
/// </summary>
1016
[SerializeField] public string NetworkPrefabsPath = DefaultNetworkPrefabsPath;
17+
18+
/// <summary>
19+
/// A temporary network prefabs path used internally.
20+
/// </summary>
1121
public string TempNetworkPrefabsPath;
1222

1323
private void OnEnable()
@@ -19,6 +29,9 @@ private void OnEnable()
1929
TempNetworkPrefabsPath = NetworkPrefabsPath;
2030
}
2131

32+
/// <summary>
33+
/// Used to determine whether the default network prefabs asset should be generated or not.
34+
/// </summary>
2235
[SerializeField]
2336
public bool GenerateDefaultNetworkPrefabs = true;
2437

com.unity.netcode.gameobjects/Editor/Configuration/NetworkPrefabProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace Unity.Netcode.Editor.Configuration
99
/// </summary>
1010
public class NetworkPrefabProcessor : AssetPostprocessor
1111
{
12+
/// <summary>
13+
/// The path to the default network prefabs list.
14+
/// </summary>
1215
public static string DefaultNetworkPrefabsPath
1316
{
1417
get

com.unity.netcode.gameobjects/Editor/Configuration/NetworkPrefabsEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Unity.Netcode.Editor
66
{
7+
/// <summary>
8+
/// The custom editor for the <see cref="NetworkPrefabsList"/> <see cref="ScriptableObject"/>.
9+
/// </summary>
710
[CustomEditor(typeof(NetworkPrefabsList), true)]
811
[CanEditMultipleObjects]
912
public class NetworkPrefabsEditor : UnityEditor.Editor
@@ -82,6 +85,7 @@ private void OnEnable()
8285
m_NetworkPrefabsList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "NetworkPrefabs");
8386
}
8487

88+
/// <inheritdoc />
8589
public override void OnInspectorGUI()
8690
{
8791
using (new EditorGUI.DisabledScope(true))

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

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,101 @@ namespace Unity.Netcode.Editor
88
/// The base Netcode Editor helper class to display derived <see cref="MonoBehaviour"/> based components <br />
99
/// where each child generation's properties will be displayed within a FoldoutHeaderGroup.
1010
/// </summary>
11+
/// <remarks>
12+
/// <see cref="TT"/> Defines the base <see cref="MonoBehaviour"/> derived component type where <see cref="DrawFoldOutGroup"/>'s type T
13+
/// refers to any child derived class of <see cref="TT"/>. This provides the ability to have multiple child generation derived custom
14+
/// editos that each child derivation handles drawing its unique properies from that of its parent class.
15+
/// </remarks>
16+
/// <typeparam name="TT">The base <see cref="MonoBehaviour"/> derived component type</typeparam>
1117
[CanEditMultipleObjects]
1218
public partial class NetcodeEditorBase<TT> : UnityEditor.Editor where TT : MonoBehaviour
1319
{
1420
private const int k_IndentOffset = 15;
21+
protected int IndentOffset { get; private set; } = 0;
22+
protected int IndentLevel { get; private set; } = 0;
1523

1624
/// <inheritdoc cref="UnityEditor.Editor.OnEnable"/>
1725
public virtual void OnEnable()
1826
{
1927
}
2028

2129
/// <summary>
22-
/// Will draw a property field with an indention level using the default or a specified offset per indention.
30+
/// Draws a <see cref="SerializedProperty"/> with the option to provide the font style to use.
2331
/// </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)
32+
/// <param name="property">The serialized property (<see cref="SerializedProperty"/>) to draw within the inspector view.</param>
33+
/// <param name="fontStyle">The font style (<see cref="FontStyle"/>) to use when drawing the label of the property field.</param>
34+
protected void DrawPropertyField(SerializedProperty property, FontStyle fontStyle = FontStyle.Normal)
35+
{
36+
var originalLabelFontStyle = EditorStyles.label.fontStyle;
37+
EditorStyles.label.fontStyle = fontStyle;
38+
EditorGUILayout.PropertyField(property);
39+
EditorStyles.label.fontStyle = originalLabelFontStyle;
40+
}
41+
42+
/// <summary>
43+
/// Draws an indented <see cref="SerializedProperty"/> with the option to provide the font style to use.
44+
/// </summary>
45+
/// <remarks>
46+
/// For additional information:<br />
47+
/// - <see cref="BeginIndent"/><br />
48+
/// - <see cref="EndIndent"/><br />
49+
/// </remarks>
50+
/// <param name="property">The serialized property (<see cref="SerializedProperty"/>) to draw within the inspector view.</param>
51+
/// <param name="fontStyle">The font style (<see cref="FontStyle"/>) to use when drawing the label of the property field.</param>
52+
protected void DrawIndentedPropertyField(SerializedProperty property, FontStyle fontStyle = FontStyle.Normal)
2853
{
2954
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();
55+
EditorGUIUtility.labelWidth = originalWidth - (IndentOffset * IndentLevel);
56+
DrawPropertyField(property, fontStyle);
3557
EditorGUIUtility.labelWidth = originalWidth;
3658
}
3759

60+
/// <summary>
61+
/// Will begin a new indention level for drawing propery fields.
62+
/// </summary>
63+
/// <remarks>
64+
/// You *must* call <see cref="EndIndent"/> when returning back to the previous indention level.<br />
65+
/// For additional information:<br />
66+
/// - <see cref="EndIndent"/><br />
67+
/// - <see cref="DrawIndentedPropertyField"/><br />
68+
/// </remarks>
69+
/// <param name="offset">(optional) The size in pixels of the offset. If no value passed, then it uses a default of 15 pixels.</param>
70+
protected void BeginIndent(int offset = k_IndentOffset)
71+
{
72+
IndentOffset = offset;
73+
IndentLevel++;
74+
GUILayout.BeginHorizontal();
75+
GUILayout.Space(IndentOffset);
76+
GUILayout.BeginVertical();
77+
}
78+
79+
/// <summary>
80+
/// Will end the current indention level when drawing propery fields.
81+
/// </summary>
82+
/// <remarks>
83+
/// For additional information:<br />
84+
/// - <see cref="BeginIndent"/><br />
85+
/// - <see cref="DrawIndentedPropertyField"/><br />
86+
/// </remarks>
87+
protected void EndIndent()
88+
{
89+
if (IndentLevel == 0)
90+
{
91+
Debug.LogWarning($"Invoking {nameof(EndIndent)} when the indent level is already 0!");
92+
return;
93+
}
94+
IndentLevel--;
95+
GUILayout.EndVertical();
96+
GUILayout.EndHorizontal();
97+
}
98+
3899
/// <summary>
39100
/// Helper method to draw the properties of the specified child type <typeparamref name="T"/> component within a FoldoutHeaderGroup.
40101
/// </summary>
41-
/// <typeparam name="T">The specific child type that should have its properties drawn.</typeparam>
102+
/// <remarks>
103+
/// <see cref="T"/> must be a sub-class of the root parent class type <see cref="TT"/>.
104+
/// </remarks>
105+
/// <typeparam name="T">The specific child derived type of <see cref="TT"/> or the type of <see cref="TT"/> that should have its properties drawn.</typeparam>
42106
/// <param name="type">The component type of the <see cref="UnityEditor.Editor.target"/>.</param>
43107
/// <param name="displayProperties">The <see cref="Action"/> to invoke that will draw the type <typeparamref name="T"/> properties.</param>
44108
/// <param name="expanded">The <typeparamref name="T"/> current expanded property value</param>

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,37 +187,50 @@ private void DisplayNetworkTransformProperties()
187187
EditorGUILayout.PropertyField(m_InLocalSpaceProperty);
188188
if (!networkTransform.HideInterpolateValue)
189189
{
190-
EditorGUILayout.PropertyField(m_InterpolateProperty);
191190
if (networkTransform.Interpolate)
192191
{
192+
EditorGUILayout.Space();
193+
}
194+
DrawPropertyField(m_InterpolateProperty, networkTransform.Interpolate ? FontStyle.Bold : FontStyle.Normal);
195+
if (networkTransform.Interpolate)
196+
{
197+
BeginIndent();
193198
if (networkTransform.SynchronizePosition)
194199
{
195-
DrawIndentedPropertyField(m_PositionInterpolationTypeProperty, 1);
200+
DrawIndentedPropertyField(m_PositionInterpolationTypeProperty);
196201
// Only display when using Lerp.
197202
if (networkTransform.PositionInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
198203
{
199-
DrawIndentedPropertyField(m_SlerpPosition, 2);
200-
DrawIndentedPropertyField(m_PositionMaximumInterpolationTimeProperty, 2);
204+
BeginIndent();
205+
DrawIndentedPropertyField(m_SlerpPosition);
206+
DrawIndentedPropertyField(m_PositionMaximumInterpolationTimeProperty);
207+
EndIndent();
201208
}
202209
}
203210
if (networkTransform.SynchronizeRotation)
204211
{
205-
DrawIndentedPropertyField(m_RotationInterpolationTypeProperty, 1);
212+
DrawIndentedPropertyField(m_RotationInterpolationTypeProperty);
206213
// Only display when using Lerp.
207214
if (networkTransform.RotationInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
208215
{
209-
DrawIndentedPropertyField(m_RotationMaximumInterpolationTimeProperty, 2);
216+
BeginIndent();
217+
DrawIndentedPropertyField(m_RotationMaximumInterpolationTimeProperty);
218+
EndIndent();
210219
}
211220
}
212221
if (networkTransform.SynchronizeScale)
213222
{
214-
DrawIndentedPropertyField(m_ScaleInterpolationTypeProperty, 1);
223+
DrawIndentedPropertyField(m_ScaleInterpolationTypeProperty);
215224
// Only display when using Lerp.
216225
if (networkTransform.ScaleInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
217226
{
218-
DrawIndentedPropertyField(m_ScaleMaximumInterpolationTimeProperty, 2);
227+
BeginIndent();
228+
DrawIndentedPropertyField(m_ScaleMaximumInterpolationTimeProperty);
229+
EndIndent();
219230
}
220231
}
232+
EndIndent();
233+
EditorGUILayout.Space();
221234
}
222235
}
223236

pvpExceptions.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
},
88
"PVP-151-1": {
99
"errors": [
10-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: undocumented",
11-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: NetworkPrefabsPath: undocumented",
12-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: TempNetworkPrefabsPath: undocumented",
13-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: GenerateDefaultNetworkPrefabs: undocumented",
14-
"Unity.Netcode.Editor.Configuration.NetworkPrefabProcessor: DefaultNetworkPrefabsPath: undocumented",
15-
"Unity.Netcode.Editor.NetworkPrefabsEditor: undocumented",
16-
"Unity.Netcode.Editor.NetworkPrefabsEditor: void OnInspectorGUI(): undocumented",
17-
"Unity.Netcode.Editor.NetcodeEditorBase<TT>: missing <typeparam name=\"TT\">",
1810
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnUpdate(): undocumented",
1911
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnNetworkSpawn(): undocumented",
2012
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnNetworkDespawn(): undocumented",

0 commit comments

Comments
 (0)