Created
January 18, 2023 07:35
-
-
Save petersvp/251f9128b5102a8b8a102337725ae220 to your computer and use it in GitHub Desktop.
Revisions
-
petersvp created this gist
Jan 18, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #if UNITY_EDITOR /// <summary> /// Float field with NAN button so you can use optional floats in your Unity components /// </summary> public sealed class NaNField : PropertyAttribute {} [CustomPropertyDrawer(typeof(NaNField))] public sealed class NaNFloatField : PropertyDrawer { const int buttonWidth = 40; public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var fieldpos = position; fieldpos.width -= buttonWidth; float f = property.floatValue; f = EditorGUI.FloatField(fieldpos, label, property.floatValue); property.floatValue = f; var buttonpos = position; buttonpos.x = position.width - buttonWidth + 18; buttonpos.width = buttonWidth; if (GUI.Button(buttonpos, "NaN")) property.floatValue = float.NaN; } } #endif