A Unity Extension to expose C# properties in the the Unity Inspector for MonoBehaviours
see reference to the original author
You can install this extension in various ways depending on your personal preference.
Add the source files \UnityPropertyInspector
to your Assets\
folder
Use the appropriate *.unitypackage from the release section
Copy the *.dlls from the release section into your Assets\
folder.
Please note: You may need to compile your own .DLLs in case the precompiled versions do not match your required Unity version.
You may want to build your own .DLLs from source to declutter your code base.
Visual Studio
- Check out the repository
- Set the correct path for the
UnityEngine.dll
andUnityEditor.dll
i 64EB n the project references to your installed Unity version (usually installed underC:\Program Files\Unity\Editor\Data\Managed\
) - Set the target framework in the solution properties to the appropriate Unity target (i.e. either Unity .NET 3.5 subset or Unity .NET 3.5 full)
- Clean solution
- Build
The Unity Editor exposes public fields in the inspector window, but does not handle properties.
Some developers circumvent this limitation by polling changes in the "Update()
-loop". The result is poorly maintainable and unperformant code.
Don't:
public class MyMonoBehaviour : MonoBehaviour {
public int health;
//called per frame
void Update() {
SetHealthbar(health);
}
}
Do:
public class MyMonoBehaviour : ExposedMonoBehaviour {
[SerializeField,HideInInspector] private int _health; //auto properties are not serialized by unity! Use fields instead
[ExposeProperty]
public int Health {
get {
return _health;
}
set {
_health = value;
SetHealthbar(value); //called only once
}
}
}