diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 36c3a6e..7336e47 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -25,7 +25,10 @@ namespace XNodeEditor { #endif public virtual void OnHeaderGUI() { - GUILayout.Label(target.name, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); + Type type = target.GetType(); + string tooltip; + type.TryGetAttributeTooltip(out tooltip); + GUILayout.Label(new GUIContent(target.name, tooltip), NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); } /// Draws standard field editors for all public fields diff --git a/Scripts/Editor/NodeEditorReflection.cs b/Scripts/Editor/NodeEditorReflection.cs index 0a0a36a..7ea7aa6 100644 --- a/Scripts/Editor/NodeEditorReflection.cs +++ b/Scripts/Editor/NodeEditorReflection.cs @@ -11,6 +11,7 @@ namespace XNodeEditor { public static class NodeEditorReflection { [NonSerialized] private static Dictionary nodeTint; [NonSerialized] private static Dictionary nodeWidth; + [NonSerialized] private static Dictionary nodeTooltip; /// All available node types public static Type[] nodeTypes { get { return _nodeTypes != null ? _nodeTypes : _nodeTypes = GetNodeTypes(); } } @@ -44,6 +45,14 @@ namespace XNodeEditor { return nodeWidth.TryGetValue(nodeType, out width); } + /// Get custom node tooltip defined with [NodeTooltip(tooltip)] + public static bool TryGetAttributeTooltip(this Type nodeType, out string tooltip) { + if (nodeTooltip == null) { + CacheAttributes(ref nodeTooltip, x => x.tooltip); + } + return nodeTooltip.TryGetValue(nodeType, out tooltip); + } + private static void CacheAttributes(ref Dictionary dict, Func getter) where A : Attribute { dict = new Dictionary(); for (int i = 0; i < nodeTypes.Length; i++) { diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 6744cc5..9102a38 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -385,6 +385,19 @@ namespace XNode { this.width = width; } } + + /// Specify a tooltip for this node type + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class NodeTooltipAttribute : Attribute + { + public string tooltip; + /// Specify a tooltip for this node type + /// The tooltip text + public NodeTooltipAttribute(string tooltip) + { + this.tooltip = tooltip; + } + } #endregion [Serializable] private class NodePortDictionary : Dictionary, ISerializationCallbackReceiver {