Deadcows / MyBox

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

Feature Request: MultiConditionalFields part 2 #220

Closed Tommigun1980 closed 1 year ago

Tommigun1980 commented 1 year ago

https://github.com/Deadcows/MyBox/issues/59 is a request for MultiConditionalFields but the fix doesn't seem to work unless the types that are compared can be inverted.

As an example let's say that queryType must be Option2 and someFlag must true.

These don't work: [ConditionalField(new[] { nameof(queryType), nameof(someFlag) }, null, new object[] { QueryType.Option2, true })]

[ConditionalField(new[] { nameof(queryType), nameof(someFlag) }, new bool[] { false, true }, new object[] { QueryType.Option2 })]

[ConditionalField(new[] { nameof(queryType), nameof(someFlag) }, null, new object[] { QueryType.Option2 }, new object[] { true })]

It seems to me that the fix only works when the types can be inverted, no?

Thank you again for a really fantastic project!!

Deadcows commented 1 year ago

I know it's really confusing to do complex checks. Hopefully, when I'm done with MyBox 2.0 you'll be able to simply put several ConditionalField attributes on top of one field.

But for now.. Actually, it looks like your first attempt should work. At least this quick test works for me

public enum MyEnum
{
    A, B, C
}

public MyEnum EnumCondition;
public bool BoolCondition;

[ConditionalField(new[] { nameof(EnumCondition), nameof(BoolCondition) }, null, new object[] { MyEnum.B, true })]
public string WhenB_and_True;

Can you please try it again and confirm, that both queryType and someFlag are shown in inspector. And also tell me if tested field is always shown or in contrary is always hidden?

Tommigun1980 commented 1 year ago

Hi @Deadcows and thanks for the reply!

You are absolutely correct, my first attempt does work, I must have failed my testing. Thanks so much and sorry for the false report.