Last active
October 11, 2016 11:57
-
-
Save romainPechot/09d74b3591c723030914159dae232f54 to your computer and use it in GitHub Desktop.
Progress Bar Attribute/Drawer for Unity float Inspector
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; | |
public class ProgressBarAttribute : PropertyAttribute | |
{ | |
public string name = "Float"; | |
public ProgressBarAttribute(string name) | |
{ | |
this.name = name; | |
}// ProgressBarAttribute() | |
}// ProgressBarAttribute : PropertyAttribute |
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; | |
// put it in an Editor folder | |
[CustomPropertyDrawer(typeof(ProgressBarAttribute))] | |
public class ProgressBarAttributeDrawer : PropertyDrawer | |
{ | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
// make sure we are drawing a float | |
if(property.propertyType == SerializedPropertyType.Float) | |
{ | |
float value = property.floatValue; | |
ProgressBarAttribute progressBarAttribute = (ProgressBarAttribute)attribute; | |
EditorGUI.ProgressBar(position, value, string.Format("{0} = {1:0.000}", progressBarAttribute.name, value)); | |
} | |
else EditorGUI.HelpBox(position, "ProgressBarAttribute can only be applied to a Float !", MessageType.Warning); | |
}// OnGUI() | |
}// ProgressBarAttributeDrawer : PropertyDrawer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment