-
-
Save AShim3D/c7ff56210d1370054b3f to your computer and use it in GitHub Desktop.
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 characters
using System; | |
using UnityEngine; | |
public class MinMaxSliderAttribute : PropertyAttribute { | |
public readonly float max; | |
public readonly float min; | |
public MinMaxSliderAttribute (float min, float max) { | |
this.min = min; | |
this.max = max; | |
} | |
} |
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 characters
using UnityEngine; | |
using UnityEditor; | |
[CustomPropertyDrawer (typeof (MinMaxSliderAttribute))] | |
class MinMaxSliderDrawer : PropertyDrawer { | |
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) { | |
if (property.propertyType == SerializedPropertyType.Vector2) { | |
Vector2 range = property.vector2Value; | |
float min = range.x; | |
float max = range.y; | |
MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute; | |
EditorGUI.BeginChangeCheck (); | |
EditorGUI.MinMaxSlider (label, position, ref min, ref max, attr.min, attr.max); | |
if (EditorGUI.EndChangeCheck ()) { | |
range.x = min; | |
range.y = max; | |
property.vector2Value = range; | |
} | |
} else { | |
EditorGUI.LabelField (position, label, "Use only with Vector2"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment