/// <summary>Creates a new <see cref="UnitsAttribute"/>.</summary> public UnitsAttribute(float[] multipliers, string[] suffixes, int unitIndex = 0) { #if UNITY_EDITOR SetUnits(multipliers, new CompactUnitConversionCache[suffixes.Length], unitIndex); for (int i = 0; i < suffixes.Length; i++) { DisplayConverters[i] = new CompactUnitConversionCache(suffixes[i]); } #endif }
/************************************************************************************************************************/ /// <summary>[Editor-Only] /// Draws a <see cref="EditorGUI.FloatField(Rect, GUIContent, float)"/> with an alternate string when it is not /// selected (for example, "1" might become "1s" to indicate "seconds"). /// </summary> /// <remarks> /// This method treats most <see cref="EventType"/>s normally, but for <see cref="EventType.Repaint"/> it /// instead draws a text field with the converted string. /// </remarks> public static float DoSpecialFloatField(Rect area, GUIContent label, float value, CompactUnitConversionCache toString) { if (label != null && !string.IsNullOrEmpty(label.text)) { if (Event.current.type != EventType.Repaint) { return(EditorGUI.FloatField(area, label, value)); } var dragArea = new Rect(area.x, area.y, EditorGUIUtility.labelWidth, area.height); EditorGUIUtility.AddCursorRect(dragArea, MouseCursor.SlideArrow); var text = toString.Convert(value, area.width - EditorGUIUtility.labelWidth); EditorGUI.TextField(area, label, text); } else { var indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (Event.current.type != EventType.Repaint) { value = EditorGUI.FloatField(area, value); } else { EditorGUI.TextField(area, toString.Convert(value, area.width)); } EditorGUI.indentLevel = indentLevel; } return(value); }