From b9e06be096cddb82ad6a3a4d329f7465894bf4b1 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Mon, 30 Oct 2017 01:33:06 +0100 Subject: [PATCH] Made the tooltip type info more readable --- Scripts/Editor/NodeEditorGUI.cs | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 4256666..e1f8e42 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -228,11 +229,47 @@ public partial class NodeEditorWindow { private void DrawTooltip() { if (hoveredPort != null) { - GUIContent content = new GUIContent(hoveredPort.type.ToString()); + Type type = hoveredPort.type; + GUIContent content = new GUIContent(); + content.text = TypeToString(type); Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content); Rect rect = new Rect(Event.current.mousePosition - (size), size); EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip); Repaint(); } } + + private string TypeToString(Type type) { + if (type == typeof(float)) return "float"; + else if (type == typeof(int)) return "int"; + else if (type == typeof(long)) return "long"; + else if (type == typeof(double)) return "double"; + else if (type == typeof(string)) return "string"; + else if (type == typeof(bool)) return "bool"; + else if (type.IsGenericType) { + string s = ""; + Type genericType = type.GetGenericTypeDefinition(); + if (genericType == typeof(List<>)) s = "List"; + else s = type.GetGenericTypeDefinition().ToString(); + + Type[] types = type.GetGenericArguments(); + string[] stypes = new string[types.Length]; + for (int i = 0; i < types.Length; i++) { + stypes[i] = TypeToString(types[i]); + } + return s + "<" + string.Join(", ", stypes) + ">"; + } else if (type.IsArray) { + string rank = ""; + for (int i = 1; i < type.GetArrayRank(); i++) { + rank += ","; + } + Type elementType = type.GetElementType(); + if (!elementType.IsArray) return TypeToString(elementType) + "[" + rank + "]"; + else { + string s = TypeToString(elementType); + int i = s.IndexOf('['); + return s.Substring(0,i) + "["+rank+"]" + s.Substring(i); + } + } else return hoveredPort.type.ToString(); + } } \ No newline at end of file