In this section, we will explore a way to create custom GUI for our properties using Property Drawers.
A Property
Drawer allows you to control how the GUI of a Serializable
class or property is displayed in the Inspector window. This approach significantly reduces the amount of work you have to do for the GUI customization because you don't need to write an entire custom inspector. Instead, you can just apply appropriate attributes to variables in your scripts to tell the editor how you want those properties to be drawn.
Unity has several built-in Property Drawers. In the following example, we will use the Range
attribute:
using UnityEngine; public class DrawerExample : MonoBehaviour { [Range (0, 100)] public int intValue = 50; }
This is the result of the preceding code:

Using the Range
attribute, we rendered a slider that moves between 0 and 100 instead of the common int field without creating a custom inspector...