Game Development Reference
In-Depth Information
Note
The property drawers can only use the default layouts in the EditorGUI class. For per-
formance reasons, they cannot use the automatic controller found in the Editor-
GUILayout class, which is used in EditorWindows .
For more information on property drawers, see the Unity reference guide at ht-
tps://docs.unity3d.com/Documentation/ScriptReference/PropertyDrawer.html .
Tip
If you want to see some more creative uses of the property drawers, check out the simple
little GitHub repository at https://github.com/tenpn/ChestOfPropertyDrawers .
Property drawers examples
Using the Entity script in Assets\Scripts\Classes , let's see the effect of
adding some simple property drawers to our NPCs in the Inspector pane (because the
NPC class is derived from the Entity class).
Built-in property drawers
Starting simply, we can decorate some of the properties of the Entity class in our game
with the Range attribute by adding the following code to the Entity class:
public string Name;
[Range(10, 100)]
public int Age;
public string Faction;
public string Occupation;
[Range(1, 10)]
public int Level;
The preceding code has the following effect on the editor inspector:
Search WWH ::




Custom Search