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…?
I think you imagined it. You need to create a custom editor if you want to do clever things like that!
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.
Thanks for the detailed answer! :-) I found the long way with the Editor extensions in my searches. I was just wondering if there is a simpler solution for the simpler end of the spectrum.
I think you imagined it. You need to create a custom editor if you want to do clever things like that!
– syclamothVery likely that I did. For the record though what I'm trying to do isn't very clever. I'm referring to the simpler cases.
– amirabiri