Code (csharp): [ SerializeField ] private float m_DisplayInInspector = 2 . 0f ; public float ExampleProperty { get { return m_DisplayInInspector ; } set { m_DisplayInInspector = Mathf . Clamp ( value , 0 . 0f, 2 . 0f ) ; } } /// <summary> /// Automatically called every time a value is updated /// </summary> protected void OnValidate ( ) { ExampleProperty = m_DisplayInInspector ; // Feed value through property for validation }

There is another work-around that doesn't need Reflection, and it requires almost no extra code. I think I first saw it in a video about editor scripting, but it might be gone now, along with most of the rest of video.unity3d.comThe trick is to mark a private property to be serialized so that it shows up in the inspector, and then use the OnValidate message method to run the value through the property. So for example, this property limits the value to be below 2:Unity then simply uses its standard Reflection magic to display and edit the value, while the code is still properly encapsulated.Of course, it relies on the OnValidate message from Monobehaviour, so you can't use it for assets(ScriptableObjects).