Validator Attirbute
-
Create new class, for example
ExampleAttribute.cs
public class ExampleAttribute { }
-
Inherit from
ValidatorAttribute
class.public class ExampleAttribute : ValidatorAttribute { }
-
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;
}