Skip to content

Dropdown Reference

[DropdownReference] attribute allows you to select one of the inheritors of the parent type.


Support Types

All references.


Parameters

No parameters


Examples

[SerializeReference]
[DropdownReference]
public Bullet bullet;
Note
  1. Make sure that you have added ApexInspector namespace in your script, to get access to all attributes.
    using ApexInspector;
    
  2. Make sure that you have added [SerializeReference] attribute to the referece field. Otherwise, it will not be displayed in the inspector.

Demo

using ApexInspector;
using UnityEngine;

public class ExampleComponent : MonoBehaviour
{
    [SerializeReference] 
    [DropdownReference]
    public Animal animal;
}
Animal class and inheritors
public abstract class Animal
{
    public abstract void Move(Vector3 direction);
}


public class Leon : Animal
{
    public float valueFloat;

    public override void Move(Vector3 direction)
    {
        // TODO
    }
}


public class Leopard : Animal
{
    public int valueInt;
    public string valueString;

    public override void Move(Vector3 direction)
    {
        // TODO
    }
}


[ReferenceContent("Custom Tiger Label")]
public class Tiger : Animal
{
    public float valueVector3;
    public string valueString;
    public bool valueBool;

    public override void Move(Vector3 direction)
    {
        // TODO
    }
}
Tip

You can change the reference display type. Since this is done in the example for Tiger class. For that you can use [ReferenceContent].

Live-demo

Live demo