Customizing Inspectors

DataMaster lets you customize the inspector for catalog items without writing your own inspector code. This is done by adding attributes to your fields defined in your catalog .cs file.

Changing the inspector based on item type

Showing or Hiding Fields

You can customize whether a field should render or be hidden in an inspector based on the item. The following attributes let you change field visibility.

DMEnum

Toggles field visibility based on the value of an enum field.

public class RPGItemDefinition : DataMasterCatalogItem
{
    public ItemType Type;

    // Render in the inspector only if the Type field is equal to ItemType.Weapon
    [DMEnum("Type", ItemType.Weapon)]
    public float AttackDamage;

    // Render in the inspector only if the Type field is equal to ItemType.Armor
    [DMEnum("Type", ItemType.Armor)]
    public float Defense;
}

DMBool

Toggles field visibility based on the value of a boolean field.

public class RoguelikeDungeonDefinition : DataMasterCatalogItem
{
    public bool SpawnBossOnFloor;

    // Render in the inspector only if the SpawnBossOnFloor field is true.
    [DMBool("SpawnBossOnFloor")]
    public BossEnemy BossPrefab;
}