public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //UnityEngine.Assertions.Assert.IsTrue(property.propertyType == SerializedPropertyType.Vector2, "Devi usare un vector2 per MinMax"); IntervalAttribute interval = attribute as IntervalAttribute; position = EditorGUI.PrefixLabel(position, label); switch (property.propertyType) { case SerializedPropertyType.Vector2: { Rect left = new Rect(position.x, position.y, 50, position.height); Rect value = new Rect(left.xMax, position.y, position.width - left.width * 2 - 4, position.height); Rect right = new Rect(position.xMax - left.width - 2, position.y, left.width, position.height); float min = property.vector2Value.x; float max = property.vector2Value.y; EditorGUI.MinMaxSlider(value, ref min, ref max, interval.min, interval.max); property.vector2Value = new Vector2(min, max); EditorGUI.LabelField(left, min.ToString("F3")); EditorGUI.LabelField(right, max.ToString("F3")); } break; case SerializedPropertyType.Float: { float value = property.floatValue; value = EditorGUI.Slider(position, value, interval.min, interval.max); property.floatValue = value; } break; default: { GUI.Label(position, "You can use Interval only on a Vector2!"); } break; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { IntervalAttribute assert = attribute as IntervalAttribute; if (assert != null) { label.tooltip = "Min, Max : " + assert._min.ToString() + ", " + assert._max.ToString(); if (property.propertyType == SerializedPropertyType.Vector2) { EditorGUI.BeginProperty(position, label, property); Rect test = position; position.height = EditorGUIUtility.singleLineHeight; var value = property.vector2Value; EditorGUI.MinMaxSlider(label, position, ref value.x, ref value.y, assert._min, assert._max); Rect floatfield = position; var labelWidth = EditorGUIUtility.labelWidth - 30; floatfield.width = (floatfield.width - labelWidth) / 4; floatfield.x += labelWidth; floatfield.y += EditorGUIUtility.singleLineHeight; value.x = EditorGUI.FloatField(floatfield, value.x); floatfield.x += floatfield.width * 3; value.y = EditorGUI.FloatField(floatfield, value.y); value.x = Mathf.Clamp(value.x, assert._min, assert._max); value.y = Mathf.Clamp(value.y, assert._min, assert._max); if (value.x > value.y) { value.x = value.y; } property.vector2Value = value; EditorGUI.EndProperty(); } else { EditorGUI.LabelField(position, label.text, "Use Interval with Vector2"); } } }