mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Made the tooltip type info more readable
This commit is contained in:
parent
199ac1ba78
commit
b9e06be096
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user