Hello,
I have been searching for a solution to this question for quite a while, unfortunately, to no avail:
How does one retrieve a script's [[Tooltip()] property from within a Custom Inspector?
I wish to retrieve the value of a tooltip defined within a script using Unity 4.6+'s [Tooltip()] attribute. In its place, I am writing what you see below, which seems redundant:
**The script (C#):**
using UnityEngine;
public class Example : MonoBehaviour
{
[Tooltip("Here is a tooltip")]
public float testFloat;
}
**The inspector (C#):**
using UnityEditor;
[CustomEditor(typeof(Example))]
public class ExampleEditor : Editor
{
private void OnEnable()
{
Target = (Example) target;
}
public override void OnInspectorGUI()
{
Target.testFloat = EditorGUILayout.FloatField(new GUIContent("Test Float", "Here is a tooltip"), Target.testFloat);
}
}
Replacing "Here is a tooltip" in the custom inspector with a call to the field's [Tooltip()] property will not only save time and code, but will make the script far more maintainable.
Thank you greatly in advance!
↧