Element "inside" Element (Enum)

Hi guys,
I’m trying to organize my enum by categories inside unity.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CarBehaviour : MonoBehaviour
{
    public enum InList
    {
        Test1, //I want to display Test1 enum elements inside of it.
        Test2
    }

    public enum Test1
    {
        On,
        Off
    }

    public enum Test2
    {
        True,
        False
    }


    public InList Trigger;

}

That’s what I want:

Thanks for helping me.

I suspect you’ll need to write a custom editor for that.

Use caution with enums. When written to disk by Unity, Unity ONLY writes the underlying integer number. This means that if you insert or reorder any of your enum code, you will get extremely mysterious bugs.

For debuggability, I recommend storing things like what you have in your items above as strings, since those will always work and are plenty performant for 99.9% of things, and you can debug them visually with ease.

ALSO: to play nice with Unity, I think your specific problem case could benefit greatly by learning about ScriptableObjects. They are basically bags of predefined data that are:

  • stored as individual file instances on disk
  • can contain anything just about
  • are editable in the inspector window
  • are draggable into slots on Monobehaviors
  • can contain any arbitrary local-knowledge logic you want
  • are awesome.

There are tons of ScriptableObject tutorials out there to get you started.