using UnityEngine;
namespace EditorAttributes
{
public enum ReferenceFixMode
{
None,
Auto,
Self,
Children,
Parents,
Scene,
Custom
}
///
/// Attribute that validates a null field in the inspector
///
public class RequiredAttribute : PropertyAttribute
{
public ReferenceFixMode FixMode { get; private set; }
public bool ThrowValidationError { get; private set; }
public bool BuildKiller { get; private set; }
public string CustomFixFunctionName { get; private set; }
///
/// Attribute that validates a null field in the inspector
///
/// Throws an error in the console if validation fails
/// Throws an error during build time and cancels it if validation fails (unless build validation is disabled in the project settings)
/// Specifies how the field should be auto-referenced by the Fix button
public RequiredAttribute(bool throwValidationError = false, bool buildKiller = false, ReferenceFixMode fixMode = ReferenceFixMode.None)
{
FixMode = fixMode;
BuildKiller = buildKiller;
ThrowValidationError = throwValidationError;
}
///
/// Attribute that validates a null field in the inspector
///
/// The name of the custom function to run by the Fix button
/// Throws an error in the console if validation fails
/// Throws an error during build time and cancels it if validation fails (unless build validation is disabled in the project settings)
public RequiredAttribute(string customFixFunctionName, bool throwValidationError = false, bool buildKiller = false)
{
FixMode = ReferenceFixMode.Custom;
BuildKiller = buildKiller;
ThrowValidationError = throwValidationError;
CustomFixFunctionName = customFixFunctionName;
}
}
}