1313
1414namespace FixedMathSharp . Editor
1515{
16+ /// <summary>
17+ /// Provides Unity editor controls for FixedMathSharp values.
18+ /// </summary>
1619 public static class FMSEditorUtility
1720 {
1821 private const float MatrixRowLabelWidth = 24f ;
1922 private const float MatrixCellSpacing = 2f ;
2023
2124 #region EditorGUI
2225
23- public static void DoubleField ( Rect position , GUIContent label , ref Fixed64 value , double scale = 1d )
24- {
26+ /// <summary>
27+ /// Draws a positioned double field backed by a Fixed64 value.
28+ /// </summary>
29+ /// <param name="scale">The display scale applied while editing the value.</param>
30+ public static void DoubleField ( Rect position , GUIContent label , ref Fixed64 value , double scale = 1d ) =>
2531 value = ( Fixed64 ) ( EditorGUI . DoubleField ( position , label , ( double ) value * scale ) / scale ) ;
26- }
2732
28- public static void DoubleField ( Rect position , string label , ref Fixed64 value , double scale = 1d )
29- {
33+ /// <summary>
34+ /// Draws a positioned, string-labeled double field backed by a Fixed64 value.
35+ /// </summary>
36+ /// <param name="scale">The display scale applied while editing the value.</param>
37+ public static void DoubleField ( Rect position , string label , ref Fixed64 value , double scale = 1d ) =>
3038 value = ( Fixed64 ) ( EditorGUI . DoubleField ( position , label , ( double ) value * scale ) / scale ) ;
31- }
3239
40+ /// <summary>
41+ /// Draws a Fixed64 field rounded to two decimals and capped by a nonzero maximum.
42+ /// </summary>
43+ /// <param name="max">The maximum value, or zero for no maximum.</param>
44+ /// <returns>The edited and capped value.</returns>
3345 public static Fixed64 FixedNumberField ( Rect position , Fixed64 value , Fixed64 max )
3446 {
3547 Fixed64 result = ( Fixed64 ) EditorGUI . DoubleField ( position , Math . Round ( ( double ) value , 2 , MidpointRounding . AwayFromZero ) ) ;
3648 return max == Fixed64 . Zero || result <= max ? result : max ;
3749 }
3850
51+ /// <summary>
52+ /// Draws a positioned Fixed64 field rounded to two decimals.
53+ /// </summary>
3954 public static Fixed64 FixedNumberField ( Rect position , Fixed64 value )
4055 {
4156 Fixed64 result = ( Fixed64 ) EditorGUI . DoubleField ( position , Math . Round ( ( double ) value , 2 , MidpointRounding . AwayFromZero ) ) ;
4257 return result ;
4358 }
4459
45- public static Fixed64 FixedNumberField ( Rect position , long value )
46- {
47- return FixedNumberField ( position , GUIContent . none , value ) ;
48- }
49-
50- public static Fixed64 FixedNumberField ( Rect position , GUIContent label , long value )
51- {
52- return ( Fixed64 ) EditorGUI . DoubleField ( position , label , Math . Round ( Fixed64 . ToDouble ( value ) , 4 , MidpointRounding . AwayFromZero ) ) ;
53- }
54-
60+ /// <summary>
61+ /// Draws a positioned Fixed64 field from its raw stored value.
62+ /// </summary>
63+ /// <param name="value">The Fixed64 raw value.</param>
64+ /// <returns>The edited Fixed64 value.</returns>
65+ public static Fixed64 FixedNumberField ( Rect position , long value ) =>
66+ FixedNumberField ( position , GUIContent . none , value ) ;
67+
68+ /// <summary>
69+ /// Draws a positioned, labeled Fixed64 field from its raw stored value.
70+ /// </summary>
71+ /// <param name="value">The Fixed64 raw value.</param>
72+ /// <returns>The edited Fixed64 value.</returns>
73+ public static Fixed64 FixedNumberField ( Rect position , GUIContent label , long value ) =>
74+ ( Fixed64 ) EditorGUI . DoubleField ( position , label , Math . Round ( Fixed64 . ToDouble ( value ) , 4 , MidpointRounding . AwayFromZero ) ) ;
75+
76+ /// <summary>
77+ /// Draws positioned X, Y, and Z fields for a Vector3d value.
78+ /// </summary>
5579 public static void Vector3dField ( Rect position , GUIContent label , ref Vector3d vector )
5680 {
5781 float labelWidth = EditorGUIUtility . labelWidth ;
@@ -75,12 +99,13 @@ public static void Vector3dField(Rect position, GUIContent label, ref Vector3d v
7599 EditorGUIUtility . labelWidth = labelWidth ;
76100 }
77101
78- public static Fixed64 GetFixed64Value ( SerializedProperty property )
79- {
80- return TryGetFixed64Value ( property , out Fixed64 value , out _ )
102+ /// <summary>
103+ /// Reads a Fixed64 from a serialized property, returning zero when it cannot be read.
104+ /// </summary>
105+ public static Fixed64 GetFixed64Value ( SerializedProperty property ) =>
106+ TryGetFixed64Value ( property , out Fixed64 value , out _ )
81107 ? value
82108 : Fixed64 . Zero ;
83- }
84109
85110 internal static bool TryGetFixed64Value ( SerializedProperty property , out Fixed64 value , out SerializedProperty rawValue )
86111 {
@@ -114,6 +139,9 @@ internal static void SetFixed64Value(SerializedProperty property, SerializedProp
114139 }
115140 }
116141
142+ /// <summary>
143+ /// Draws a labeled, read-only row of Fixed64 matrix values.
144+ /// </summary>
117145 public static void DrawReadOnlyMatrixRow ( Rect position , string rowLabel , params Fixed64 [ ] values )
118146 {
119147 Rect rowLabelRect = new Rect ( position . x , position . y , MatrixRowLabelWidth , position . height ) ;
@@ -135,11 +163,15 @@ public static void DrawReadOnlyMatrixRow(Rect position, string rowLabel, params
135163
136164 #region EditorGUILayout
137165
138- public static void FixedNumberField ( string Label , ref Fixed64 fixedNumber )
139- {
166+ /// <summary>
167+ /// Draws an automatically laid-out Fixed64 field.
168+ /// </summary>
169+ public static void FixedNumberField ( string Label , ref Fixed64 fixedNumber ) =>
140170 fixedNumber = ( Fixed64 ) EditorGUILayout . DoubleField ( Label , ( double ) fixedNumber ) ;
141- }
142171
172+ /// <summary>
173+ /// Draws an automatically laid-out Fixed64 serialized-property field.
174+ /// </summary>
143175 public static void FixedNumberField ( string label , ref SerializedProperty property )
144176 {
145177 if ( ! TryGetFixed64Value ( property , out Fixed64 currentValue , out SerializedProperty rawValue ) )
@@ -154,6 +186,9 @@ public static void FixedNumberField(string label, ref SerializedProperty propert
154186 SetFixed64Value ( property , rawValue , newFixedValue ) ;
155187 }
156188
189+ /// <summary>
190+ /// Draws an automatically laid-out slider for a Fixed64 serialized property.
191+ /// </summary>
157192 public static void FixedNumberField ( string label , ref SerializedProperty property , float min , float max )
158193 {
159194 if ( ! TryGetFixed64Value ( property , out Fixed64 currentValue , out SerializedProperty rawValue ) )
@@ -169,15 +204,17 @@ public static void FixedNumberField(string label, ref SerializedProperty propert
169204 SetFixed64Value ( property , rawValue , newFixedValue ) ;
170205 }
171206
172- public static void Vector2dField ( string Label , ref Vector2d vector )
173- {
207+ /// <summary>
208+ /// Draws an automatically laid-out Vector2d field.
209+ /// </summary>
210+ public static void Vector2dField ( string Label , ref Vector2d vector ) =>
174211 vector = EditorGUILayout . Vector2Field ( Label , vector . ToVector2 ( ) ) . ToVector2d ( ) ;
175- }
176212
177- public static void Vector3dField ( string Label , ref Vector3d vector )
178- {
213+ /// <summary>
214+ /// Draws an automatically laid-out Vector3d field.
215+ /// </summary>
216+ public static void Vector3dField ( string Label , ref Vector3d vector ) =>
179217 vector = EditorGUILayout . Vector3Field ( Label , vector . ToVector3 ( ) ) . ToVector3d ( ) ;
180- }
181218
182219 #endregion
183220 }
0 commit comments