Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show if not working #387

Open
fawad0dev opened this issue May 14, 2024 · 1 comment
Open

Show if not working #387

fawad0dev opened this issue May 14, 2024 · 1 comment

Comments

@fawad0dev
Copy link

fawad0dev commented May 14, 2024

public enum RCType
    {
        Int,
        Float,
        Bool,
        String,
        Long,
        Json
    }
    [Serializable]
    class ValueDetail<T>
    {
        public T Value;
        public T defaultValue;
    }
    [SerializeField] RCValue[] rCValues;
    [Serializable]
    class RCValue
    {
        public string key;
        public RCType valueType;
        [ShowIf(nameof(IsInt))] public ValueDetail<int> intValue;
        [ShowIf(nameof(IsInt))] public UnityEvent<int> onIntValueFetched;
        [ShowIf(nameof(IsFloat))] public ValueDetail<float> floatValue;
        [ShowIf(nameof(IsFloat))] public UnityEvent<float> onFloatValueFetched;
        [ShowIf(nameof(IsBool))] public ValueDetail<bool> boolValue;
        [ShowIf(nameof(IsBool))] public UnityEvent<bool> onBoolValueFetched;
        [ShowIf(nameof(valueType), RCType.String)] public ValueDetail<string> stringValue;
        [ShowIf(nameof(valueType), RCType.String)] public UnityEvent<string> onStringValueFetched;
        [ShowIf(nameof(valueType), RCType.Long)] public ValueDetail<long> longValue;
        [ShowIf(nameof(valueType), RCType.Long)] public UnityEvent<long> onLongValueFetched;
        [ShowIf(nameof(valueType), RCType.Json)] public ValueDetail<string> jsonValue;
        [ShowIf(nameof(valueType), RCType.Json)] public UnityEvent<string> onJsonValueFetched;
        bool IsInt() => valueType == RCType.Int;
        bool IsFloat() => valueType == RCType.Float;
        bool IsBool() => valueType == RCType.Bool;
        bool IsString() => valueType == RCType.String;
        bool IsLong() => valueType == RCType.Long;
        bool IsJson() => valueType == RCType.Json;
    }

it is still showing all fields
image

@TylerTemp
Copy link

ShowIf is a meta-attribute, which only works under NaughtyInspector. And NaughtyInspector, only works for UnityEngine.Object

[Serializable]
class RCValue {}

unfortunately, RCValue (even with Serializable) is not a UnityEngine.Object, so in NaughtyAttributes, it won't work.

Related to #107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants