Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Any chance of some more Property Attributes?

Discussion in '2017.2 Beta' started by CDF, Jul 29, 2017.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,284
    Would love if some more attributes could be added into the new beta.
    I find myself using these a lot:

    [Min(0)]
    value must be greater than 0

    [Max(100)]
    value must be less than 100

    [EnumFlag(typeof(MyEnum))]
    int value is mask enum (System.Flags)

    [Help("Don't toggle this", MessageType.Warning)]
    draws a help box with message above the field

    [Layer]
    int value is a game object layer

    at the very least, imo, a "Min" attribute should be standard, ensuring a value is greater than 0 is my daily life.
     
    Last edited: Jul 29, 2017
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    A label attribute would be greatly welcome but for the rest simply use OnValidate()

    Code (CSharp):
    1.     void OnValidate()
    2.     {
    3.         if (value < 0) value = 0;
    4.     }
    For example. It is called whenever someone diddles with stuff in the inspector, and is precisely for your problem.
     
  3. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    960
    We've had these in the project for so long that I forgot they were not in fact standard! :p