using System;
namespace EditorAttributes
{
///
/// Attribute to add a button in the inspector
///
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class ButtonAttribute : Attribute, IConditionalAttribute, IRepetableButton
{
public string ButtonLabel { get; private set; }
public float ButtonHeight { get; private set; }
public bool SerializeParameters { get; private set; }
public int EnumValue { get; private set; }
public bool Negate { get; private set; }
public string ConditionName { get; private set; }
public ConditionResult ConditionResult { get; private set; }
public bool IsRepetable { get; private set; }
public long PressDelay { get; private set; }
public long RepetitionInterval { get; private set; }
///
/// Attribute to add a button in the inspector
///
/// The label displayed on the button
/// The height of the button in pixels
/// Have the button parameters persist between selections
public ButtonAttribute(string buttonLabel = "", float buttonHeight = 18f, bool serializeParameters = true)
{
ConditionName = "";
ButtonLabel = buttonLabel;
ButtonHeight = buttonHeight;
SerializeParameters = serializeParameters;
}
///
/// Attribute to add a button in the inspector
///
/// Makes the button repeat logic on hold
/// How many milliseconds to wait before the logic is executed on hold
/// The interval in milliseconds the logic will repeat
/// The label displayed on the button
/// The height of the button in pixels
/// Have the button parameters persist between selections
public ButtonAttribute(bool isRepetable, long pressDelay = 60, long repetitionInterval = 100, string buttonLabel = "", float buttonHeight = 18f, bool serializeParameters = true)
: this(buttonLabel, buttonHeight, serializeParameters)
{
ConditionName = "";
IsRepetable = isRepetable;
PressDelay = pressDelay;
RepetitionInterval = repetitionInterval;
}
///
/// Attribute to add a button in the inspector
///
/// The name of the condition to evaluate
/// What happens to the button when the condition evaluates to true
/// Negate the evaluated condition
/// The label displayed on the button
/// The height of the button in pixels
/// Have the button parameters persist between selections
public ButtonAttribute(string conditionName, ConditionResult conditionResult, bool negate = false, string buttonLabel = "", float buttonHeight = 18f, bool serializeParameters = true)
: this(buttonLabel, buttonHeight, serializeParameters)
{
ConditionResult = conditionResult;
ConditionName = conditionName;
Negate = negate;
}
///
/// Attribute to add a button in the inspector
///
/// Makes the button repeat logic on hold
/// The name of the condition to evaluate
/// What happens to the button when the condition evaluates to true
/// Negate the evaluated condition
/// How many milliseconds to wait before the logic is executed on hold
/// The interval in milliseconds the logic will repeat
/// The label displayed on the button
/// The height of the button in pixels
/// Have the button parameters persist between selections
public ButtonAttribute(bool isRepetable, string conditionName, ConditionResult conditionResult, bool negate = false, long pressDelay = 60, long repetitionInterval = 100, string buttonLabel = "", float buttonHeight = 18f, bool serializeParameters = true)
: this(conditionName, conditionResult, negate, buttonLabel, buttonHeight, serializeParameters)
{
IsRepetable = isRepetable;
PressDelay = pressDelay;
RepetitionInterval = repetitionInterval;
}
///
/// Attribute to add a button in the inspector
///
/// The name of the condition to evaluate
/// The value of the enum condition
/// What happens to the button when the condition evaluates to true
/// Negate the evaluated condition
/// The label displayed on the button
/// The height of the button in pixels
/// Have the button parameters persist between selections
public ButtonAttribute(string conditionName, object enumValue, ConditionResult conditionResult, bool negate = false, string buttonLabel = "", float buttonHeight = 18f, bool serializeParameters = true)
: this(conditionName, conditionResult, negate, buttonLabel, buttonHeight, serializeParameters) => EnumValue = (int)enumValue;
///
/// Attribute to add a button in the inspector
///
/// Makes the button repeat logic on hold
/// The name of the condition to evaluate
/// The value of the enum condition
/// What happens to the button when the condition evaluates to true
/// Negate the evaluated condition
/// How many milliseconds to wait before the logic is executed on hold
/// The interval in milliseconds the logic will repeat
/// The label displayed on the button
/// The height of the button in pixels
/// Have the button parameters persist between selections
public ButtonAttribute(bool isRepetable, string conditionName, object enumValue, ConditionResult conditionResult, bool negate = false, long pressDelay = 60, long repetitionInterval = 100, string buttonLabel = "", float buttonHeight = 18f, bool serializeParameters = true)
: this(isRepetable, conditionName, conditionResult, negate, pressDelay, repetitionInterval, buttonLabel, buttonHeight, serializeParameters) => EnumValue = (int)enumValue;
}
}