Skip to content

Commit

Permalink
Fixed #144 - Added virtual GetPortTooltip in NodeGraphEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
Siccity committed Jun 29, 2019
1 parent 9588408 commit d0e1cd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Scripts/Editor/NodeEditorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,10 @@ private bool ShouldBeCulled(XNode.Node node) {
}

private void DrawTooltip() {
if (hoveredPort != null && NodeEditorPreferences.GetSettings().portTooltips) {
Type type = hoveredPort.ValueType;
GUIContent content = new GUIContent();
content.text = type.PrettyName();
if (hoveredPort.IsOutput) {
object obj = hoveredPort.node.GetValue(hoveredPort);
content.text += " = " + (obj != null ? obj.ToString() : "null");
}
if (hoveredPort != null && NodeEditorPreferences.GetSettings().portTooltips && graphEditor != null) {
string tooltip = graphEditor.GetPortTooltip(hoveredPort);
if (string.IsNullOrEmpty(tooltip)) return;
GUIContent content = new GUIContent(tooltip);
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content);
Rect rect = new Rect(Event.current.mousePosition - (size), size);
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
Expand Down
11 changes: 11 additions & 0 deletions Scripts/Editor/NodeGraphEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public virtual Color GetTypeColor(Type type) {
return NodeEditorPreferences.GetTypeColor(type);
}

public virtual string GetPortTooltip(XNode.NodePort port) {
Type portType = port.ValueType;
string tooltip = "";
tooltip = portType.PrettyName();
if (port.IsOutput) {
object obj = port.node.GetValue(port);
tooltip += " = " + (obj != null ? obj.ToString() : "null");
}
return tooltip;
}

/// <summary> Deal with objects dropped into the graph through DragAndDrop </summary>
public virtual void OnDropObjects(UnityEngine.Object[] objects) {
Debug.Log("No OnDropItems override defined for " + GetType());
Expand Down

0 comments on commit d0e1cd5

Please sign in to comment.