Note Attribute
The NoteAttribute is a custom attribute used for creating Inspector notes in Unity, helpful in streamlining design processes.
Usage
To use the NoteAttribute, follow these steps:
- Attach the
NoteAttributeto a serialized field in a MonoBehaviour script or a ScriptableObject. - Provide the note description as a string parameter when creating an instance of the
NoteAttribute. - Optionally, you can specify the line height for the note by providing a
uintvalue as the second parameter. A value of 0 indicates auto-sizing.
In this example, the NoteAttribute is attached to the myField serialized field in the MyScript MonoBehaviour. The provided note description will be displayed in the Unity Inspector for the myField field.
public class MyScript : MonoBehaviour
{
[Note("This is a note for the field.")]
public int myField;
[Note(3, "This is a note with a custom line height.")]
public int myField;
}-
Save your script and go back to the Unity Editor. Open the Inspector for the object that contains the script you just modified.
-
In the Inspector, you will now see a note above the associated field.
Customization
You can customize the appearance and behavior of the note drawer by modifying the following constants in the NoteDrawer class:
AUTO_MAX_HEIGHT: Maximum number of lines for the note text area (auto-sizing only).AUTO_MIN_HEIGHT: Minimum number of lines for the note text area (auto-sizing only).
You can also modify the GetNoteStyle method to change the visual style of the note box.
Notes
-
The
NoteAttributeis purely for preview purposes in the Unity Inspector and does not affect the runtime behavior of your game or application. -
If you find the
NoteAttributehelpful, please consider giving it a star on the GitHub repository. Your support is greatly appreciated!
License
The NoteAttribute is provided as-is under the terms of the MIT License. Feel free to modify and adapt it to suit your needs.
