예제 #1
0
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // First get the attribute since it contains the range for the slider
            if (attribute is DefaultRangeAttribute)
            {
                DefaultRangeAttribute range = (DefaultRangeAttribute)attribute;

                // Now draw the property as a Slider or an IntSlider based on whether it's a float or integer.
                if (property.propertyType == SerializedPropertyType.Float)
                {
                    DisplayCheckboxAndControl(property, range, position, SetToDefaultFloat, DisplayFloatSlider, ref isEnabled, ref sliderValue);
                }
                else if (property.propertyType == SerializedPropertyType.Integer)
                {
                    DisplayCheckboxAndControl(property, range, position, SetToDefaultInt, DisplayIntSlider, ref isEnabled, ref sliderValue);
                }
                else
                {
                    EditorGUI.LabelField(position, label.text, "Use DefaultRange with float or int.");
                }
            }
        }
예제 #2
0
 static void SetToDefaultInt(SerializedProperty property, DefaultRangeAttribute range)
 {
     property.floatValue = Mathf.RoundToInt(range.defaultNumber);
 }
예제 #3
0
 static void SetToDefaultFloat(SerializedProperty property, DefaultRangeAttribute range)
 {
     property.floatValue = range.defaultNumber;
 }
예제 #4
0
 static void DisplayIntSlider(SerializedProperty property, DefaultRangeAttribute range, Rect position, ref float value)
 {
     value = EditorGUI.IntSlider(position, Mathf.RoundToInt(value), Mathf.RoundToInt(range.min), Mathf.RoundToInt(range.max));
 }
예제 #5
0
 static void DisplayFloatSlider(SerializedProperty property, DefaultRangeAttribute range, Rect position, ref float value)
 {
     value = EditorGUI.Slider(position, value, range.min, range.max);
 }