Is there a simple way to tell the inspector to use a particular control for editing a given variable?
i.e something along the lines of:
[Slider(min = 0, max = 100)]
public int Something;
For some reason I think I remember seeing that somewhere, but I’ve tried searching and could only find complicated ways to do that. Or did I imagine seeing it…?
save
September 20, 2011, 12:22am
2
Sure would be nice, haven’t seen such thing (might be a future update, who knows).
You could although do this:
1. Create a folder named Editor, in that folder create this script (JavaScript) named customInspectorHelper :
#pragma strict
@CustomEditor(customInspector)
class customInspectorHelper extends Editor {
var serObj : SerializedObject;
var sliderVal : SerializedProperty;
function OnEnable () {
serObj = new SerializedObject (target);
sliderVal = serObj.FindProperty("sliderVal");
}
function OnInspectorGUI () {
serObj.Update ();
GUILayout.Label("Pimp My Inspector");
sliderVal.intValue = EditorGUILayout.IntSlider ("Slider Value", sliderVal.intValue, 0, 100);
serObj.ApplyModifiedProperties();
}
}
This will add features to the Inspector for the component customInspector which you create in step 2.
2. Create another script (JavaScript) outside of the Editor-folder named customInspector :
#pragma strict
class customInspector extends MonoBehaviour {
public var sliderVal : int = 0;
//functions goes here
}
This is the script that goes on the actual GameObject. A couple of lines more than your actual request but it’s really clean if you think about it.
[Range(0,100)]
public int Something;