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:
parent
151b0e6267
commit
5b1026e698
Binary file not shown.
@ -4,16 +4,16 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class TestNode : Node {
|
public class TestNode : Node {
|
||||||
|
|
||||||
public int i;
|
public int myInt;
|
||||||
public float f;
|
[Input(false)] public float myFloat;
|
||||||
public double d;
|
public double myDouble;
|
||||||
public long l;
|
public long myLong;
|
||||||
public bool b;
|
public bool myBool;
|
||||||
public string s;
|
[Input(true)] public string myString;
|
||||||
public Rect r;
|
public Rect myRect;
|
||||||
public Vector2 v2;
|
[Input(true)] public Vector2 myVec2;
|
||||||
public Vector3 v3;
|
[Input(true)] public Vector3 myVec3;
|
||||||
public Vector4 v4;
|
public Vector4 myVec4;
|
||||||
public Color col;
|
public Color myColor;
|
||||||
public AnimationCurve a;
|
public AnimationCurve myCurve;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public partial class NodeEditorWindow {
|
|||||||
DrawConnections();
|
DrawConnections();
|
||||||
DrawDraggedConnection();
|
DrawDraggedConnection();
|
||||||
DrawNodes();
|
DrawNodes();
|
||||||
|
DrawTooltip();
|
||||||
|
|
||||||
GUI.matrix = m;
|
GUI.matrix = m;
|
||||||
}
|
}
|
||||||
@ -193,4 +194,14 @@ public partial class NodeEditorWindow {
|
|||||||
if (onValidate != null && nodeHash != selectedNode.GetHashCode()) onValidate.Invoke(selectedNode, null);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -11,8 +11,8 @@ public class NodeEditorGUILayout {
|
|||||||
|
|
||||||
private static double tempValue;
|
private static double tempValue;
|
||||||
|
|
||||||
public static object PortField(string label, object value, NodePort port, bool fallback, out Vector2 portPosition) {
|
public static object PortField(string label, object value, System.Type type, NodePort port, bool fallback, out Vector2 portPosition) {
|
||||||
if (fallback) value = PropertyField(label, value);
|
if (fallback) value = PropertyField(label, value, type);
|
||||||
else EditorGUILayout.LabelField(label);
|
else EditorGUILayout.LabelField(label);
|
||||||
|
|
||||||
Rect rect = GUILayoutUtility.GetLastRect();
|
Rect rect = GUILayoutUtility.GetLastRect();
|
||||||
@ -50,15 +50,15 @@ public class NodeEditorGUILayout {
|
|||||||
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) {
|
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) {
|
||||||
NodePort port = target.GetPortByFieldName(fieldName);
|
NodePort port = target.GetPortByFieldName(fieldName);
|
||||||
Vector2 portPos;
|
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);
|
portPositions.Add(port, portPos);
|
||||||
} else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) {
|
} else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) {
|
||||||
NodePort port = target.GetPortByFieldName(fieldName);
|
NodePort port = target.GetPortByFieldName(fieldName);
|
||||||
Vector2 portPos;
|
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);
|
portPositions.Add(port, portPos);
|
||||||
} else {
|
} else {
|
||||||
fieldValue = PropertyField(fieldPrettyName, fieldValue);
|
fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
@ -68,7 +68,7 @@ public class NodeEditorGUILayout {
|
|||||||
return fieldValue;
|
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);
|
if (value is int) return IntField(label, (int) value);
|
||||||
else if (value is float) return FloatField(label, (float) value);
|
else if (value is float) return FloatField(label, (float) value);
|
||||||
else if (value is double) return DoubleField(label, (double) 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 Vector4) return Vector4Field(label, (Vector4) value);
|
||||||
else if (value is Color) return ColorField(label, (Color) value);
|
else if (value is Color) return ColorField(label, (Color) value);
|
||||||
else if (value is AnimationCurve) return CurveField(label, (AnimationCurve) 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;
|
else return value;
|
||||||
}
|
}
|
||||||
public static Rect GetRect(string label) {
|
public static Rect GetRect(string label) {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public static class NodeEditorResources {
|
|||||||
public static Styles _styles = null;
|
public static Styles _styles = null;
|
||||||
|
|
||||||
public class Styles {
|
public class Styles {
|
||||||
public GUIStyle inputPort, outputPort, nodeHeader, nodeBody;
|
public GUIStyle inputPort, outputPort, nodeHeader, nodeBody, tooltip;
|
||||||
|
|
||||||
public Styles() {
|
public Styles() {
|
||||||
GUIStyle baseStyle = new GUIStyle("Label");
|
GUIStyle baseStyle = new GUIStyle("Label");
|
||||||
@ -49,6 +49,12 @@ public static class NodeEditorResources {
|
|||||||
nodeBody.normal.background = NodeEditorResources.nodeBody;
|
nodeBody.normal.background = NodeEditorResources.nodeBody;
|
||||||
nodeBody.border = new RectOffset(32, 32, 32, 32);
|
nodeBody.border = new RectOffset(32, 32, 32, 32);
|
||||||
nodeBody.padding = new RectOffset(16, 16, 4, 6);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user