Exemple #1
0
        public static void AngleProperty(SerializedProperty prop, string label, SerializedProperty unitProp, params GUILayoutOption[] layout)
        {
            AngularUnit unit = unitProp.hasMultipleDifferentValues ? AngularUnit.Radians : (AngularUnit)unitProp.enumValueIndex;

            using ( Horizontal ) {
                // value field
                using (EditorGUI.ChangeCheckScope chChk = new EditorGUI.ChangeCheckScope()) {
                    EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
                    float newValue = EditorGUILayout.FloatField(label, prop.floatValue * unit.FromRadians()) * unit.ToRadians();
                    if (chChk.changed)
                    {
                        prop.floatValue = newValue;
                    }
                    EditorGUI.showMixedValue = false;
                }

                // unit suffix
                GUILayout.Label(unit.Suffix(), layout);
            }
        }
 public static float FromRadians(this AngularUnit unit) => 1f / unit.ToRadians();