Game Development Reference
In-Depth Information
The property drawers
The editor only has a basic way of looking at the properties in the
Inspector
pane based
on the classes and objects used in your game. If you are using an existing Unity class,
such as a string, color, or curve, Unity already has readymade property drawers (or visual
handles) to manage these with their own editor windows in some cases (such as the curve
editor). The majority of these are also built on the extensible framework that Unity ex-
poses and is available to you as well.
Other classes such as vectors and numbers have a basic implementation, which is usually
fine, but sometimes you would just prefer it in a different way.
This is where the property drawers come in. They can either replace the existing property
viewer for a single field or for a type of object entirely. If you want a slider to alter a value
between two values, add a
PropertyDrawer
attribute to the property to show a slider
instead of just
int
or
float
as follows:
[Range (0, 100)]
public float health = 100;
The preceding code example shows a range slider instead of a single float value as you
can see here:
Tip
For a more advanced example, check out the post on the Unity blog, which shows several
different patterns to use your property drawers and even create them. The post is available
While building the property drawers, you will use the
EditorGUI
controls to draw the
elements on the screen. The
EditorGUI
class provides a rich collection of controls that
can be used. For the list of available controls, visit
https://docs.unity3d.com/Documenta-