DarkRewar / BaseTool

A big library of basic tools that you might need in your Unity projects.
MIT License
41 stars 6 forks source link

Add EnableIf and DisableIf #95 #97

Closed DarkRewar closed 4 months ago

DarkRewar commented 4 months ago

EnableIfAttribute

This attribute can mark its field as readonly in the inspector if the condition is false.

using BaseTool;
using UnityEngine;

public class MyClass : MonoBehaviour
{
    public bool IsStrong = true;

    [EnableIf(nameof(IsStrong))]
    public float Strength = 10f;

    [EnableIf("!IsStrong")]
    public float NonStrength = 10f;
}

DisableIfAttribute

This attribute can mark its field as readonly in the inspector if the condition is true.

using BaseTool;
using UnityEngine;

public class MyClass : MonoBehaviour
{
    public bool IsStrong = true;

    [DisableIf("!IsStrong")]
    public float Strength = 10f;

    [DisableIf(nameof(IsStrong))]
    public float NonStrength = 10f;
}