1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 17:26:02 +08:00

Fixed field editor bug, added tooltip.

This commit is contained in:
Thor Brigsted 2017-10-14 18:18:25 +02:00
parent 151b0e6267
commit 5b1026e698
5 changed files with 37 additions and 20 deletions

Binary file not shown.

View File

@ -4,16 +4,16 @@ using UnityEngine;
public class TestNode : Node {
public int i;
public float f;
public double d;
public long l;
public bool b;
public string s;
public Rect r;
public Vector2 v2;
public Vector3 v3;
public Vector4 v4;
public Color col;
public AnimationCurve a;
public int myInt;
[Input(false)] public float myFloat;
public double myDouble;
public long myLong;
public bool myBool;
[Input(true)] public string myString;
public Rect myRect;
[Input(true)] public Vector2 myVec2;
[Input(true)] public Vector3 myVec3;
public Vector4 myVec4;
public Color myColor;
public AnimationCurve myCurve;
}

View File

@ -15,6 +15,7 @@ public partial class NodeEditorWindow {
DrawConnections();
DrawDraggedConnection();
DrawNodes();
DrawTooltip();
GUI.matrix = m;
}
@ -193,4 +194,14 @@ public partial class NodeEditorWindow {
if (onValidate != null && nodeHash != selectedNode.GetHashCode()) onValidate.Invoke(selectedNode, null);
}
}
private void DrawTooltip() {
if (hoveredPort != null) {
GUIContent content = new GUIContent(hoveredPort.type.ToString());
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content);
Rect rect = new Rect(Event.current.mousePosition - (size), size);
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
Repaint();
}
}
}

View File

@ -11,8 +11,8 @@ public class NodeEditorGUILayout {
private static double tempValue;
public static object PortField(string label, object value, NodePort port, bool fallback, out Vector2 portPosition) {
if (fallback) value = PropertyField(label, value);
public static object PortField(string label, object value, System.Type type, NodePort port, bool fallback, out Vector2 portPosition) {
if (fallback) value = PropertyField(label, value, type);
else EditorGUILayout.LabelField(label);
Rect rect = GUILayoutUtility.GetLastRect();
@ -50,15 +50,15 @@ public class NodeEditorGUILayout {
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) {
NodePort port = target.GetPortByFieldName(fieldName);
Vector2 portPos;
fieldValue = PortField(fieldPrettyName, fieldValue, port, inputAttrib.fallback, out portPos);
fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, inputAttrib.fallback, out portPos);
portPositions.Add(port, portPos);
} else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) {
NodePort port = target.GetPortByFieldName(fieldName);
Vector2 portPos;
fieldValue = PortField(fieldPrettyName, fieldValue, port, outputAttrib.fallback, out portPos);
fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, outputAttrib.fallback, out portPos);
portPositions.Add(port, portPos);
} else {
fieldValue = PropertyField(fieldPrettyName, fieldValue);
fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType);
}
if (EditorGUI.EndChangeCheck()) {
@ -68,7 +68,7 @@ public class NodeEditorGUILayout {
return fieldValue;
}
public static object PropertyField(string label, object value) {
public static object PropertyField(string label, object value, System.Type type) {
if (value is int) return IntField(label, (int) value);
else if (value is float) return FloatField(label, (float) value);
else if (value is double) return DoubleField(label, (double) value);
@ -82,7 +82,7 @@ public class NodeEditorGUILayout {
else if (value is Vector4) return Vector4Field(label, (Vector4) value);
else if (value is Color) return ColorField(label, (Color) value);
else if (value is AnimationCurve) return CurveField(label, (AnimationCurve) value);
else if (value == null || value.GetType().IsSubclassOf(typeof(UnityEngine.Object)) || value.GetType() == typeof(UnityEngine.Object)) return ObjectField(label, (UnityEngine.Object) value);
else if (type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object)) return ObjectField(label, (UnityEngine.Object) value);
else return value;
}
public static Rect GetRect(string label) {

View File

@ -26,7 +26,7 @@ public static class NodeEditorResources {
public static Styles _styles = null;
public class Styles {
public GUIStyle inputPort, outputPort, nodeHeader, nodeBody;
public GUIStyle inputPort, outputPort, nodeHeader, nodeBody, tooltip;
public Styles() {
GUIStyle baseStyle = new GUIStyle("Label");
@ -49,6 +49,12 @@ public static class NodeEditorResources {
nodeBody.normal.background = NodeEditorResources.nodeBody;
nodeBody.border = new RectOffset(32, 32, 32, 32);
nodeBody.padding = new RectOffset(16, 16, 4, 6);
tooltip = new GUIStyle("helpBox");
tooltip.alignment = TextAnchor.MiddleCenter;
//tooltip.border = new RectOffset(0, 0, 0, 0);
//tooltip.normal.background
//tooltip.padding = new RectOffset(0, 0, 0, 0);
}
}