Expose properties in inspector

Author: Mift (mift)

Note: An updated version of this script package (which only calls a property's setter when the value has actually changed) can be found here: ExposePropertiesInInspector_SetOnlyWhenChanged

Description
The code here provided is intended for those that want to hold their variables private and let them access only through get/set accessors, so further processing becomes possible.

The Sausage
Create a new c# Script named "ExposePropertyAttribute" and paste following code :

The magic
Now create another script in the "Assets/Editor" folder named "ExposeProperties" and paste following code:

Note
As you probably have seen in the code above, only following types are currently exposed, but it should be easy enough to implement other ones:

- Integer - Float - Boolean - String - Vector2 - Vector3 - Enum - UnityEngine.Object

Example component
Now create your type, i.e. MyType. Properties MUST have both getter and setter accessors AND [ExposeProperty] attribute set otherwise the property will not be shown.

In order for the property to maintain values when you hit play, you must add [SerializeField] to the field that the property is changing. Unfortunately, this exposes the field to the Editor (editing this value does not call the property getter/setter), so you have to explicitly hide it with [HideInInspector].

The custom editor
Finally, create a custom editor Script in "Assets/Editor" for the type which properties you want to see exposed. I.e.:

Conclusion
Well, thats pretty much the basic system, Im sure some ppl that might touch this "sauce code" will be able to make it better ( and prettier ). It does what I need it for, so Im not gonna improve it.