Hi.
I’m trying to implement a custom property drawer for displaying tooltips when I mouse over certain variables in the Inspector. So far, my code looks like this (I’ve gotten this code here)
Assets/Scripts/TooltipAttribute.cs:
using UnityEngine;
public class TooltipAttribute : PropertyAttribute
{
public readonly string text;
public TooltipAttribute(string text)
{
this.text = text;
}
}
Assets/Scripts/TooltipAttribute.cs:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(TooltipAttribute))]
public class TooltipDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
{
var atr = (TooltipAttribute) attribute;
var content = new GUIContent(label.text, atr.text);
EditorGUI.PropertyField(position, prop, content, true);
}
}
Then, you simply use it like this:
[Tooltip("The 'Use' text as well as the 'Examine' description")]
public NoteState m_State = new NoteState();
The tooltips work as intended unless you are adding a tooltip to an expandable field. In that case, the expanded field is written ontop of everything else:
Is there a solution to this? I have tried overloading GetPropertyHeight() but I haven’t had any success with that either.
Thanks in advance // Simon