- Home /
Having Text Or Notes In The Inspector?
Is there a way(like I see in many plug-ins) to have text or notes in the inspector amongst all the variables? For example I have a couple of lines of text above of variable to remind people what options they have for this variable?
Thanks In Advance!
I don't know about a way to do this, but it's been a wish of $$anonymous$$e for some time: http://feedback.unity3d.com/unity/all-categories/1/hot/active/show-comments-for-variables-in-t
Answer by MasterChiefLegend · Apr 07, 2015 at 12:31 AM
I think you just mean the built in Attributes Unity have already set up?
See
http://docs.unity3d.com/ScriptReference/TooltipAttribute.html
and
http://docs.unity3d.com/ScriptReference/HeaderAttribute.html
Example code snippet:
[Header("Button Settings")]
[Tooltip("Arbitary text message")]
public string OnClickText = "";
[Tooltip("Useful GameObject you might need. Note there is a Sender property that is this class.")]
public GameObject Object;
Answer by ShawnFeatherly · Sep 30, 2016 at 08:49 PM
For a general note on the component, create a new variable that has a [TextArea]
Attribute.
[TextArea]
[Tooltip("Doesn't do anything. Just comments shown in inspector")]
public string Notes = "This component shouldn't be removed, it does important stuff.";
Answer by usergame · Mar 27, 2017 at 09:54 AM
I realize this question is a few years old but I was recently looking to do the same and didn't like the dummy variable suggestion, so I wrote my own really simple PropertyDrawer and HelpAttribute. More information at the forum post:
Hope this helps someone out who is still looking for a more elegant solution.
Answer by AlanMattano · Dec 12, 2015 at 04:27 PM
After adding attributes to your script as MasterChiefLegend mention, you can create text notes in the inspector following these steps:
Here it is the GitHub link:
Allowed to place info in the inspector in a simple way:
Answer by Loius · Apr 24, 2013 at 05:28 PM
[CustomEditor(typeof(YourType))] is what you're looking for.
http://docs.unity3d.com/Documentation/ScriptReference/Editor.html
GUILayout.Label("Remember that one thing about this variable!");
x = EditorGUILayout.IntField(whatever);
That scripting reference page appears to be extremely overkill for what I want. Is this the only way to achieve this?
I was gonna say yes and go off on a tangent about auto-creating editors, but then i found this which is new in Unity 4 and might be just what you're looking for;
http://blogs.unity3d.com/2012/09/07/property-drawers-in-unity-4/
Hmmm, the reason I want this 'comment' above my variables is just to save time and for convenience. If all of that is required it would have the opposite effect :(
This lets you add comments to a dummy variable, then you just put the dummy in the list of your real properties. I've only played with drawers today, but it's not immediately apparent to me how to go about drawing the actual property (i.e. how to draw the actual int field without a huge if-else block).
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
public class CommentAttribute : PropertyAttribute {
public readonly string tooltip;
public readonly string comment;
public CommentAttribute( string comment, string tooltip ) {
this.tooltip = tooltip;
this.comment = comment;
}
}
[CustomPropertyDrawer(typeof(CommentAttribute))]
public class CommentDrawer : PropertyDrawer {
const int textHeight = 20;
CommentAttribute commentAttribute { get { return (CommentAttribute)attribute; } }
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) {
return textHeight;
}
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label) {
EditorGUI.LabelField(position,new GUIContent(commentAttribute.comment,commentAttribute.tooltip));
}
}
public class PropDraw : $$anonymous$$onoBehaviour {
[Comment("This is the description","And this is the tooltip")]
public int thisIsADummy;
}
#endif
Your answer
Follow this Question
Related Questions
How to indent EditorGUILayout.BeginToggleGroup() 1 Answer
C# public - dropdown selection? 3 Answers
Inspector cannot find script instance 1 Answer
Inspector: Animator: Animations drop down not appearing? 1 Answer
c# enum wont show in inspector 3 Answers