mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Minor bugfixes and cleanup
Changed: - Private fields with [Serializable] attributes are now also shown - Nodes can now only be dragged by the title - Output text alignment Fixed: - NodeEditorWindow fields not resetting to null - Field editors
This commit is contained in:
parent
846f7f30b1
commit
372099b03d
@ -7,6 +7,5 @@ public class AddNodeEditor : NodeEditor {
|
|||||||
|
|
||||||
public override void OnNodeGUI() {
|
public override void OnNodeGUI() {
|
||||||
GUILayout.Label("YEAH CUSTOM");
|
GUILayout.Label("YEAH CUSTOM");
|
||||||
base.OnNodeGUI();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,8 @@ public class NodeEditor {
|
|||||||
DrawDefaultNodeGUI();
|
DrawDefaultNodeGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawDefaultNodeGUI() {
|
/// <summary> Draws standard field editors for all public fields </summary>
|
||||||
|
protected void DrawDefaultNodeGUI() {
|
||||||
FieldInfo[] fields = GetInspectorFields(target);
|
FieldInfo[] fields = GetInspectorFields(target);
|
||||||
for (int i = 0; i < fields.Length; i++) {
|
for (int i = 0; i < fields.Length; i++) {
|
||||||
Type fieldType = fields[i].FieldType;
|
Type fieldType = fields[i].FieldType;
|
||||||
@ -58,16 +59,18 @@ public class NodeEditor {
|
|||||||
fieldValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
|
fieldValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(Vector3)) {
|
else if (fieldType == typeof(Vector3)) {
|
||||||
fieldValue = EditorGUILayout.Vector2Field(fieldName, (Vector3)fieldValue);
|
fieldValue = EditorGUILayout.Vector3Field(new GUIContent(fieldName), (Vector3)fieldValue);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(Vector4)) {
|
else if (fieldType == typeof(Vector4)) {
|
||||||
fieldValue = EditorGUILayout.Vector2Field(fieldName, (Vector4)fieldValue);
|
fieldValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(Color)) {
|
else if (fieldType == typeof(Color)) {
|
||||||
fieldValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
|
fieldValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(AnimationCurve)) {
|
else if (fieldType == typeof(AnimationCurve)) {
|
||||||
fieldValue = EditorGUILayout.CurveField(fieldName, fieldValue != null ? (AnimationCurve)fieldValue : new AnimationCurve());
|
AnimationCurve curve = fieldValue != null ? (AnimationCurve)fieldValue : new AnimationCurve();
|
||||||
|
curve = EditorGUILayout.CurveField(fieldName, curve);
|
||||||
|
if (fieldValue != curve) fields[i].SetValue(target, curve);
|
||||||
}
|
}
|
||||||
else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || fieldType == typeof(UnityEngine.Object)) {
|
else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || fieldType == typeof(UnityEngine.Object)) {
|
||||||
fieldValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, fieldType, true);
|
fieldValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, fieldType, true);
|
||||||
@ -78,8 +81,9 @@ public class NodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FieldInfo[] GetInspectorFields(Node node) {
|
private static FieldInfo[] GetInspectorFields(Node node) {
|
||||||
return node.GetType().GetFields().Where(f => f.IsPublic).ToArray();
|
return node.GetType().GetFields().Where(f => f.IsPublic || f.GetCustomAttributes(typeof(SerializeField),false) != null).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool GetAttrib<T>(object[] attribs, out T attribOut) where T : Attribute {
|
private static bool GetAttrib<T>(object[] attribs, out T attribOut) where T : Attribute {
|
||||||
|
|||||||
@ -16,12 +16,13 @@ public partial class NodeEditorWindow {
|
|||||||
private bool IsHoveringNode { get { return hoveredNode != null; } }
|
private bool IsHoveringNode { get { return hoveredNode != null; } }
|
||||||
private bool HasSelectedNode { get { return selectedNode != null; } }
|
private bool HasSelectedNode { get { return selectedNode != null; } }
|
||||||
|
|
||||||
private Node hoveredNode;
|
private Node hoveredNode = null;
|
||||||
private Node selectedNode;
|
|
||||||
private Node draggedNode;
|
[NonSerialized] private Node selectedNode = null;
|
||||||
private NodePort hoveredPort;
|
[NonSerialized] private Node draggedNode = null;
|
||||||
private NodePort draggedOutput;
|
[NonSerialized] private NodePort hoveredPort = null;
|
||||||
private NodePort draggedOutputTarget;
|
[NonSerialized] private NodePort draggedOutput = null;
|
||||||
|
[NonSerialized] private NodePort draggedOutputTarget = null;
|
||||||
|
|
||||||
private Rect nodeRects;
|
private Rect nodeRects;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ public partial class NodeEditorWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsHoveringNode) {
|
else if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
||||||
draggedNode = hoveredNode;
|
draggedNode = hoveredNode;
|
||||||
dragOffset = hoveredNode.position.position - WindowToGridPosition(e.mousePosition);
|
dragOffset = hoveredNode.position.position - WindowToGridPosition(e.mousePosition);
|
||||||
}
|
}
|
||||||
@ -108,9 +109,6 @@ public partial class NodeEditorWindow {
|
|||||||
isPanning = false;
|
isPanning = false;
|
||||||
}
|
}
|
||||||
UpdateHovered();
|
UpdateHovered();
|
||||||
break;
|
|
||||||
case EventType.repaint:
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,9 +169,16 @@ public partial class NodeEditorWindow {
|
|||||||
}
|
}
|
||||||
if (newHoverPort != hoveredPort) {
|
if (newHoverPort != hoveredPort) {
|
||||||
hoveredPort = newHoverPort;
|
hoveredPort = newHoverPort;
|
||||||
Repaint();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else hoveredPort = null;
|
else hoveredPort = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsHoveringTitle(Node node) {
|
||||||
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
|
//Get node position
|
||||||
|
Vector2 nodePos = GridToWindowPosition(node.position.position);
|
||||||
|
Rect windowRect = new Rect(nodePos, new Vector2(node.position.size.x / zoom, 30 / zoom));
|
||||||
|
return windowRect.Contains(mousePos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,13 +12,11 @@ public partial class NodeEditorWindow {
|
|||||||
Matrix4x4 m = GUI.matrix;
|
Matrix4x4 m = GUI.matrix;
|
||||||
Controls();
|
Controls();
|
||||||
|
|
||||||
if (e.type != EventType.MouseMove && e.type != EventType.MouseDrag) {
|
|
||||||
DrawGrid(position, zoom, panOffset);
|
DrawGrid(position, zoom, panOffset);
|
||||||
DrawNodes();
|
DrawNodes();
|
||||||
DrawConnections();
|
DrawConnections();
|
||||||
DrawDraggedConnection();
|
DrawDraggedConnection();
|
||||||
DrawToolbar();
|
DrawToolbar();
|
||||||
}
|
|
||||||
|
|
||||||
GUI.matrix = m;
|
GUI.matrix = m;
|
||||||
}
|
}
|
||||||
@ -135,6 +133,7 @@ public partial class NodeEditorWindow {
|
|||||||
BeginZoomed(position, zoom);
|
BeginZoomed(position, zoom);
|
||||||
if (e.type == EventType.Repaint) portRects.Clear();
|
if (e.type == EventType.Repaint) portRects.Clear();
|
||||||
foreach (Node node in graph.nodes) {
|
foreach (Node node in graph.nodes) {
|
||||||
|
|
||||||
//Get node position
|
//Get node position
|
||||||
Vector2 nodePos = GridToWindowPositionNoClipped(node.position.position);
|
Vector2 nodePos = GridToWindowPositionNoClipped(node.position.position);
|
||||||
|
|
||||||
@ -173,13 +172,6 @@ public partial class NodeEditorWindow {
|
|||||||
nodeEditor.OnNodeGUI();
|
nodeEditor.OnNodeGUI();
|
||||||
|
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
|
|
||||||
if (windowRect.position != nodePos) {
|
|
||||||
nodePos = windowRect.position;
|
|
||||||
node.position.position = WindowToGridPosition(nodePos);
|
|
||||||
//Vector2 newPos = windowRect =
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
EndZoomed(position, zoom);
|
EndZoomed(position, zoom);
|
||||||
EndWindows();
|
EndWindows();
|
||||||
|
|||||||
@ -37,12 +37,19 @@ public partial class NodeEditorWindow {
|
|||||||
outputColor = new GUIStyle((GUIStyle)"flow shader out 4");
|
outputColor = new GUIStyle((GUIStyle)"flow shader out 4");
|
||||||
outputTexture = new GUIStyle((GUIStyle)"flow shader out 5");
|
outputTexture = new GUIStyle((GUIStyle)"flow shader out 5");
|
||||||
|
|
||||||
foreach (GUIStyle style in new GUIStyle[] { inputInt, inputString, inputFloat, inputObject, inputTexture, inputColor, outputInt, outputString, outputFloat, outputObject, outputTexture, outputColor }) {
|
foreach (GUIStyle style in new GUIStyle[] { inputInt, inputString, inputFloat, inputObject, inputTexture, inputColor }) {
|
||||||
style.normal.textColor = Color.black;
|
style.normal.textColor = Color.black;
|
||||||
style.fixedHeight = 18;
|
style.fixedHeight = 18;
|
||||||
style.alignment = TextAnchor.MiddleLeft;
|
style.alignment = TextAnchor.MiddleLeft;
|
||||||
style.onHover.textColor = Color.red;
|
style.onHover.textColor = Color.red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (GUIStyle style in new GUIStyle[] { outputInt, outputString, outputFloat, outputObject, outputTexture, outputColor }) {
|
||||||
|
style.normal.textColor = Color.black;
|
||||||
|
style.fixedHeight = 18;
|
||||||
|
style.alignment = TextAnchor.MiddleRight;
|
||||||
|
style.onHover.textColor = Color.red;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUIStyle GetInputStyle(Type type) {
|
public GUIStyle GetInputStyle(Type type) {
|
||||||
|
|||||||
@ -13,12 +13,16 @@ public partial class NodeEditorWindow {
|
|||||||
if (DropdownButton("View", 50)) { }
|
if (DropdownButton("View", 50)) { }
|
||||||
if (DropdownButton("Settings", 70)) { }
|
if (DropdownButton("Settings", 70)) { }
|
||||||
if (DropdownButton("Tools", 50)) ToolsContextMenu();
|
if (DropdownButton("Tools", 50)) ToolsContextMenu();
|
||||||
|
|
||||||
|
//Draw hover info
|
||||||
|
if (Event.current.type == EventType.Layout || Event.current.type == EventType.Repaint) {
|
||||||
if (IsHoveringNode) {
|
if (IsHoveringNode) {
|
||||||
GUILayout.Space(20);
|
GUILayout.Space(20);
|
||||||
string hoverInfo = hoveredNode.GetType().ToString();
|
string hoverInfo = hoveredNode.GetType().ToString();
|
||||||
if (IsHoveringPort) hoverInfo += " > " + hoveredPort.name;
|
if (IsHoveringPort) hoverInfo += " > " + hoveredPort.name;
|
||||||
GUILayout.Label(hoverInfo);
|
GUILayout.Label(hoverInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make the toolbar extend all throughout the window extension.
|
// Make the toolbar extend all throughout the window extension.
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
|
|||||||
@ -4,7 +4,7 @@ using UnityEngine;
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class NodePort :ISerializationCallbackReceiver{
|
public class NodePort : ISerializationCallbackReceiver{
|
||||||
public enum IO { Input, Output}
|
public enum IO { Input, Output}
|
||||||
|
|
||||||
public int ConnectionCount { get { return connections.Count; } }
|
public int ConnectionCount { get { return connections.Count; } }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user