Skip to content

Commit a0542fc

Browse files
committed
docs: document bundled public Unity APIs
1 parent c80203a commit a0542fc

51 files changed

Lines changed: 972 additions & 474 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Build/Base/Editor/Drawers/Fixed64Drawer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace FixedMathSharp.Editor
1818
[CustomPropertyDrawer(typeof(Fixed64))]
1919
public class Fixed64Drawer : PropertyDrawer
2020
{
21+
/// <summary>
22+
/// Draws the Fixed64 property field in the Unity inspector.
23+
/// </summary>
2124
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
2225
{
2326
if (!FMSEditorUtility.TryGetFixed64Value(property, out Fixed64 currentValue, out SerializedProperty rawValue))

Build/Base/Editor/Drawers/FixedMatrixDrawer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class FixedMatrixDrawer : PropertyDrawer
3333
new[] { "M41", "M42", "M43", "M44" }
3434
};
3535

36+
/// <summary>
37+
/// Gets the inspector height required for the collapsed or expanded matrix.
38+
/// </summary>
3639
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
3740
{
3841
if (!property.isExpanded)
@@ -43,6 +46,9 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
4346
rowCount * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
4447
}
4548

49+
/// <summary>
50+
/// Draws the matrix as an expandable, read-only grid.
51+
/// </summary>
4652
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
4753
{
4854
EditorGUI.BeginProperty(position, label, property);

Build/Base/Editor/Drawers/FixedNumberAngleDrawer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ namespace FixedMathSharp.Editor
1414
[CustomPropertyDrawer(typeof(FixedNumberAngleAttribute))]
1515
public class FixedNumberAngleDrawer : PropertyDrawer
1616
{
17+
/// <summary>
18+
/// Draws the stored Fixed64 sine value as an editable angle in degrees.
19+
/// </summary>
1720
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1821
{
1922
EditorGUI.BeginProperty(position, label, property);

Build/Base/Editor/Drawers/FixedQuaternionDrawer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ namespace FixedMathSharp.Editor
1414
[CustomPropertyDrawer(typeof(FixedQuaternion)), CanEditMultipleObjects]
1515
public class FixedQuaternionDrawer : PropertyDrawer
1616
{
17+
/// <summary>
18+
/// Draws a FixedQuaternion as Euler angles in degrees, applying edits only outside play mode.
19+
/// </summary>
1720
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1821
{
1922
EditorGUI.BeginProperty(position, label, property);

Build/Base/Editor/Drawers/VectorRotationDrawer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ public class VectorRotationDrawer : PropertyDrawer
1717
private static readonly GUIContent AngleLabel = new("Angle");
1818
private static readonly GUIContent UnsupportedLabel = new("Use with Vector2d");
1919

20+
/// <summary>
21+
/// Gets the single-line height used by the vector rotation field.
22+
/// </summary>
2023
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
2124
{
2225
return EditorGUIUtility.singleLineHeight;
2326
}
2427

28+
/// <summary>
29+
/// Draws a Vector2d direction as an editable angle in degrees.
30+
/// </summary>
2531
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
2632
{
2733
EditorGUI.BeginProperty(position, label, property);

Build/Base/Editor/Utility/FMSEditorUtility.cs

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,69 @@
1313

1414
namespace 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
}

Build/Base/Runtime/Attributes/FixedNumberAngleAttribute.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
namespace FixedMathSharp
1111
{
1212
/// <summary>
13-
/// Attribute to represent a fixed number angle in degrees.
14-
/// Can be used to annotate properties or fields, supporting optional time-scaling and a maximum angle.
13+
/// Displays a Fixed64 sine value as an angle in degrees with optional display scaling and a maximum angle.
1514
/// </summary>
1615
public class FixedNumberAngleAttribute : PropertyAttribute
1716
{
1817
/// <summary>
19-
/// Gets a value indicating whether the angle is scaled by time (e.g., frame rate).
18+
/// Gets the scale applied while displaying and editing the angle.
2019
/// </summary>
2120
public double Timescale { get; private set; }
2221

@@ -29,12 +28,12 @@ public class FixedNumberAngleAttribute : PropertyAttribute
2928
/// <summary>
3029
/// Initializes a new instance of the <see cref="FixedNumberAngleAttribute"/> class.
3130
/// </summary>
32-
/// <param name="timescale">Specifies whether the angle should be scaled by time (e.g., frame rate).</param>
31+
/// <param name="timescale">The scale applied while displaying and editing the angle.</param>
3332
/// <param name="max">The maximum allowable value for the angle in degrees. Default is -1 (no limit).</param>
3433
public FixedNumberAngleAttribute(double timescale = 1d, double max = -1d)
3534
{
3635
Timescale = timescale;
3736
Max = max;
3837
}
3938
}
40-
}
39+
}

Build/Base/Runtime/Attributes/VectorRotationAttribute.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
namespace FixedMathSharp
1111
{
1212
/// <summary>
13-
/// Attribute to represent a fixed number angle in degrees.
14-
/// Can be used to annotate properties or fields, supporting optional time-scaling and a maximum angle.
13+
/// Displays a Vector2d direction as an angle in degrees with optional display scaling.
1514
/// </summary>
1615
public class VectorRotationAttribute : PropertyAttribute
1716
{
1817
public double Timescale { get; private set; }
1918

19+
/// <summary>
20+
/// Initializes a vector rotation attribute with an optional display scale.
21+
/// </summary>
22+
/// <param name="timescale">The scale applied while displaying and editing the angle.</param>
2023
public VectorRotationAttribute(double timescale = 1d)
2124
{
2225
Timescale = timescale;
2326
}
2427
}
25-
}
28+
}

Build/Base/Runtime/Extensions/Fixed3x3.Extensions.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace FixedMathSharp
1616
/// </summary>
1717
public static class Fixed3x3UnityExtensions
1818
{
19+
/// <summary>
20+
/// Converts a FixedMathSharp row-vector basis matrix to a Unity column-vector matrix.
21+
/// </summary>
1922
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2023
public static Matrix4x4 ToMatrix4x4(this Fixed3x3 matrix)
2124
{
@@ -32,6 +35,9 @@ public static Matrix4x4 ToMatrix4x4(this Fixed3x3 matrix)
3235
return unityMatrix;
3336
}
3437

38+
/// <summary>
39+
/// Copies the upper-left Unity basis into a FixedMathSharp row-vector matrix without removing scale or shear.
40+
/// </summary>
3541
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3642
public static Fixed3x3 ToFixed3x3Basis(this Matrix4x4 matrix)
3743
{
@@ -41,12 +47,16 @@ public static Fixed3x3 ToFixed3x3Basis(this Matrix4x4 matrix)
4147
(Fixed64)matrix.m02, (Fixed64)matrix.m12, (Fixed64)matrix.m22);
4248
}
4349

50+
/// <summary>
51+
/// Extracts the normalized rotation represented by a Unity matrix.
52+
/// </summary>
4453
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45-
public static Fixed3x3 ToFixed3x3Rotation(this Matrix4x4 matrix)
46-
{
47-
return matrix.rotation.ToFixedQuaternion().ToMatrix3x3();
48-
}
54+
public static Fixed3x3 ToFixed3x3Rotation(this Matrix4x4 matrix) =>
55+
matrix.rotation.ToFixedQuaternion().ToMatrix3x3();
4956

57+
/// <summary>
58+
/// Gets a Unity transform's world rotation as a FixedMathSharp rotation matrix.
59+
/// </summary>
5060
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5161
public static Fixed3x3 ToFixed3x3WorldRotation(this Transform transform)
5262
{
@@ -56,6 +66,9 @@ public static Fixed3x3 ToFixed3x3WorldRotation(this Transform transform)
5666
return transform.rotation.ToFixedQuaternion().ToMatrix3x3();
5767
}
5868

69+
/// <summary>
70+
/// Gets a Unity transform's local rotation as a FixedMathSharp rotation matrix.
71+
/// </summary>
5972
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6073
public static Fixed3x3 ToFixed3x3LocalRotation(this Transform transform)
6174
{
@@ -65,6 +78,13 @@ public static Fixed3x3 ToFixed3x3LocalRotation(this Transform transform)
6578
return transform.localRotation.ToFixedQuaternion().ToMatrix3x3();
6679
}
6780

81+
/// <summary>
82+
/// Creates a Unity transform whose local rotation is extracted from the matrix.
83+
/// </summary>
84+
/// <param name="matrix">The rotation matrix to apply.</param>
85+
/// <param name="name">The new GameObject's name.</param>
86+
/// <param name="parent">The optional parent transform.</param>
87+
/// <returns>The created transform.</returns>
6888
public static Transform CreateTransformRotationLocal(
6989
this Fixed3x3 matrix,
7090
string name = "Fixed3x3 Rotation Transform",
@@ -76,6 +96,13 @@ public static Transform CreateTransformRotationLocal(
7696
return transform;
7797
}
7898

99+
/// <summary>
100+
/// Creates a Unity transform whose world rotation is extracted from the matrix.
101+
/// </summary>
102+
/// <param name="matrix">The rotation matrix to apply.</param>
103+
/// <param name="name">The new GameObject's name.</param>
104+
/// <param name="parent">The optional parent transform.</param>
105+
/// <returns>The created transform.</returns>
79106
public static Transform CreateTransformRotationWorld(
80107
this Fixed3x3 matrix,
81108
string name = "Fixed3x3 Rotation Transform",
@@ -87,6 +114,9 @@ public static Transform CreateTransformRotationWorld(
87114
return transform;
88115
}
89116

117+
/// <summary>
118+
/// Applies the matrix's normalized rotation to a Unity transform in local space.
119+
/// </summary>
90120
public static void ApplyRotationToTransformLocal(this Fixed3x3 matrix, Transform transform)
91121
{
92122
if (transform == null)
@@ -95,6 +125,9 @@ public static void ApplyRotationToTransformLocal(this Fixed3x3 matrix, Transform
95125
transform.localRotation = ExtractUnityRotation(matrix);
96126
}
97127

128+
/// <summary>
129+
/// Applies the matrix's normalized rotation to a Unity transform in world space.
130+
/// </summary>
98131
public static void ApplyRotationToTransformWorld(this Fixed3x3 matrix, Transform transform)
99132
{
100133
if (transform == null)

0 commit comments

Comments
 (0)