Deadcows / MyBox

MyBox is a set of attributes, tools and extensions for Unity
http://deadcow.ru
MIT License
1.94k stars 244 forks source link

Bug: Conditional attributes don't work with list or array #218

Closed angelsalascalvo closed 1 year ago

angelsalascalvo commented 1 year ago

Hello, I wanted to report that the conditional field does not work for variables of type list or array. I am using the latest version 1.7.0

public enum EnumType {
    button,
    fader,
}
public EnumType type;

[ConditionalField(nameof(type), false, EnumType.button)]
public List<float> positions;

Thank you very much for the utility library!

Deadcows commented 1 year ago

This is mentioned in the docs here with a helper type as a workaround. In your case you should probably do something like this

[Serializable]
public class FloatsCollection : CollectionWrapper<float> {}

[ConditionalField(nameof(type), false, EnumType.button)]
public FloatsCollection positions;

And access actual points collection with positions.Value

angelsalascalvo commented 1 year ago

👍 Thanks!