Hi everyone!
I am messing around with the custom inspectors, but I noticed a vast lexicon around the topic, and now I don’t know the best way to create one with advanced controls with serialized properties. For instance: When should I use property drawers, or just a custom inspector that extends Editor? Or, why certain controls are so hard to implement, like the min max slider with a serialized float variable? Anyway, its all too confusing for me now…
Here’s a MinMaxSlider implementation I did some time ago.
To create a custom slider in a custom editor inspector is very easy.
Assuming you have already saved ‘target’ to a variable called ‘source’ in OnEnable()…
const string tooltip = "This is a slider";
const string sliderLabel = "POWER";
float minValue = 1.0f;
float maxValue = 3.7f;
void OnInspectorGUI()
{
source.myVariable = EditorGUILayout.Slider(new GUIContent(sliderLabel, tooltip), source.myVariable, minValue, maxValue);
}