@@ -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>
0 commit comments