using UnityEngine;
namespace EditorAttributes
{
///
/// A class to use for more advanced validation checks
///
public class ValidationCheck
{
public string ValidationMessage { get; private set; }
public bool PassedCheck { get; private set; }
public bool KillBuild { get; private set; }
public MessageMode Severety { get; private set; }
///
/// Marks the validation as failed
///
/// The message to display in the console
/// The severety of the validation
/// Throw an error during build time and cancel it
/// The validation check object
public static ValidationCheck Fail(string validationMessage, MessageMode severety = MessageMode.Error, bool killBuild = false) => new()
{
PassedCheck = false, ValidationMessage = validationMessage, Severety = severety, KillBuild = killBuild
};
///
/// Marks the validation as passed
///
/// The validation check object
public static ValidationCheck Pass() => new() { PassedCheck = true };
}
///
/// Attribute to create custom validation
///
public class ValidateAttribute : PropertyAttribute
{
public string ValidationMessage { get; private set; }
public string ConditionName { get; private set; }
public bool BuildKiller { get; private set; }
public MessageMode Severety { get; private set; }
///
/// Attribute to create custom validation
///
/// The name of the condition to evaluate
public ValidateAttribute(string conditionName) => ConditionName = conditionName;
///
/// Attribute to create custom validation
///
/// The message to display in the console when validation fails
/// The name of the condition to evaluate
/// The severety of the failed validation
/// Throws an error during build time and cancels it if validation fails
public ValidateAttribute(string validationMessage, string conditionName, MessageMode severety = MessageMode.Error, bool buildKiller = false) : this(conditionName)
{
ValidationMessage = validationMessage;
BuildKiller = buildKiller;
Severety = severety;
}
}
}