You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using UnityEngine;
|
|
using System.Reflection;
|
|
using System.Collections.Generic;
|
|
|
|
namespace NaughtyAttributes.Editor
|
|
{
|
|
public static class ButtonUtility
|
|
{
|
|
public static bool IsEnabled(Object target, MethodInfo method)
|
|
{
|
|
EnableIfAttributeBase enableIfAttribute = method.GetCustomAttribute<EnableIfAttributeBase>();
|
|
if (enableIfAttribute == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
List<bool> conditionValues = PropertyUtility.GetConditionValues(target, enableIfAttribute.Conditions);
|
|
if (conditionValues.Count > 0)
|
|
{
|
|
bool enabled = PropertyUtility.GetConditionsFlag(conditionValues, enableIfAttribute.ConditionOperator, enableIfAttribute.Inverted);
|
|
return enabled;
|
|
}
|
|
else
|
|
{
|
|
string message = enableIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
|
|
Debug.LogWarning(message, target);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool IsVisible(Object target, MethodInfo method)
|
|
{
|
|
ShowIfAttributeBase showIfAttribute = method.GetCustomAttribute<ShowIfAttributeBase>();
|
|
if (showIfAttribute == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
List<bool> conditionValues = PropertyUtility.GetConditionValues(target, showIfAttribute.Conditions);
|
|
if (conditionValues.Count > 0)
|
|
{
|
|
bool enabled = PropertyUtility.GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, showIfAttribute.Inverted);
|
|
return enabled;
|
|
}
|
|
else
|
|
{
|
|
string message = showIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
|
|
Debug.LogWarning(message, target);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|