Skip to content

Validator Attirbute

  1. Create new class, for example ExampleAttribute.cs

    public class ExampleAttribute
    {
    
    }
    

  2. Inherit from ValidatorAttribute class.

    public class ExampleAttribute : ValidatorAttribute
    {
    
    }
    

  3. Optionaly add Required/Optional parameters.

    public class ExampleAttribute : ValidatorAttribute
    {
        // Required parameter.
        public readonly string text;
    
        // Constructor with required parameter.
        public ExampleAttribute(string text)
        {
            this.text = text;
        }
    
        // Optional parameter.
        public float SomeValue { get; set; }
    }
    


Example

public class ExampleComponent : MonoBehaviour
{
    // Required parameter.
    [Example("Some Text")]
    public float value;

    // Required and optional parameter.
    [Example("Some Text", Value = 10.0f)]
    public float value;
}