Not sure if this has been done before or if it’s built in to Unity (if not, it should be), did some searching and nothing turned up…
I rolled a simple PropertyDrawer and PropertyAttribute script which allows you to use the HelpBox you see in various places inside the Unity IDE, to decorate your inspector properties. Using a [HelpAttribute] you can set the text content and icon image to show help text \and usage information or instructions above any property in the inspector.
I thought it might be useful to the community for use in Asset Store assets or personal projects. Unity has an awesome community and hopefully you’ll accept my first addition.
Nice! What do you think of using a scrollbar in a note instead of trying to resize the notes height? I was messing with your code trying to get the help notes to resize better. Would likely take a bunch of code to get them to resize correctly which ruins the simplicity of your code.
Yeah, I know what you’re saying but I think using a scrollbar would require a CustomEditor rather than using the unity built in EditorGUI.HelpBox. The resizing was a pain and in the end I just settled for the pre-calculated constants rather than trying to get an accurate resizing function. I just try and keep to text to a minimum and to the point, but if it gets big I throw a couple of newlines at the end of the text to expand it.
I think the more elegant way to go would be calculating the size with GUIContent but couldn’t figure it out, or should I say didn’t have time to spend on it. Something along the lines of:
I think you would need to get access to the GUIStyle used by the inspector to know the font size etc… Maybe someone from Unity GUI dev team can shed some light?
@ShawnFeatherly , you got me hooked on fixing this one ;). I’ve updated the HelpAttribute.cs script in the repo to do a better job of computing the height at runtime.
I also commented up the code to help peeps (who may require it) to understand what’s going on a little better. I still had to leave some pre-calculated stuff in there for the custom MultilineAttribute handling and the minimum height and margin etc… But it’s definitely a big improvement.
After I did that, the error was replaced with this instead:
The line is:
[HelpBox("NOTE! If your new material is on other objects already, you will NOT be able to change back without also affecting those other objects.", HelpBoxMessageType.Info)]
Thanks for the great scripts, perfect timing too! Do you know how I would go about hiding the variable in the inspector, or is it even possible? Everything I do hides the message if the variable isn’t visible (setting static, using [HideInInspector])…
It depends on a visible variable. If you need a help box without any variables visible in the inspector, I think you’ll need to write a custom inspector instead.
Is there anything built in that lets me add a class level description to a class that is visible in the inspector - i.e not at the property level but at the class level?
This is a hack, but you could add the HelpBox attribute to the first serialized property in your class so it appears at the top of the inspector, and put your class level description in it.
Otherwise I think you’ll need to write a custom inspector. A short one would do. Something like:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MyClass), true)]
[CanEditMultipleObjects]
public class MyClassEditor : Editor {
public override void OnInspectorGUI() {
EditorGUILayout.HelpBox("Class level info.", MessageType.None);
DrawDefaultInspector();
}
}