Selecting a custom class type from inspector

Let’s say I have some classes defined like this:

public class ClassA: BaseClass { ... }
public class ClassB: BaseClass { ... }
public class ClassC: BaseClass { ... }

Now I want to be able to select one of these classes from a drop down menu in the inspector, and have it stored as either a string (i.e, “ClassA”), or as System.Type. Is that possible? I know I can simply use serializable strings and convert them, but I was hoping to find a less error-prone approach.

Edit:
Looks like I found what I wanted here: Bitbucket

4 Likes

here is solution

maybe it help you

anyone still needing this you can create an enum for the dropdown, and serialize the enum or make it public:

public class dropdownexample: MonoBehaviour
{
//serialize dropdown
    public ActivationType activationType;

    private void Start()
    {
        if (activationType == ActivationType.Start)
        {
            ActivateFunction();
        }
    }

    private void Awake()
    {
        if (activationType == ActivationType.Awake)
        {
            ActivateFunction();
        }
    }

    private void Update()
    {
        if (activationType == ActivationType.Update)
        {
            ActivateFunction();
        }
    }

    // Other methods and functionality

    private void ActivateFunction()
    {
        Debug.Log("Function activated!");
    }

//dropdown emun
    public enum ActivationType
    {
        None,
        Start,
        Awake,
        Update
    }
}

Glad that works for you. Please don’t raise ancient threads like this. Nobody was continuing to ask.

1 Like