Show field based on multiple enum values - Odin

3k Views Asked by At

I want to Show the field in UnityInspector based on specific enum field.

Lets say this is the enum class

  public enum Mode
    {
        None,
        Movement,
        Rotation,
        Scale
    }

I want to enable this field if "Movement or Scale" is selected from the enum dropdown, otherwise hide the field.

        public Vector3 NewValues;

With Odin I can do:

    [ShowIf("tweenMode", TweenMode.Movement)]
    public Vector3 NewValues;

But that will work only on Movement enum. Any idea on how to make it work on multiple enums? Thanks

2

There are 2 best solutions below

1
derHugo On BEST ANSWER

Afaik you can simply do something like

private bool showNewValues => tweenMode == TweenMode.Movement || tweenMode == TweenMode.Rotation;

[ShowIf(nameof(showNewValues))]
public Vector3 NewValues;

See ShowIf

0
Schwapo On

You can use a property like mentioned before. You can also make use of Odin's attribute expressions which where added in version 2.1.0.0

[ShowIf("@tweenMode == TweenMode.Movement || tweenMode == TweenMode.Rotation")]
public Vector3 NewValues;

If you consider that easier / more readable is up to you, but it's another option.