mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Fixed node headers
This commit is contained in:
parent
6a92f18618
commit
5f4da093f3
@ -13,10 +13,16 @@ public class NodeEditor {
|
|||||||
/// <summary> Draws the node GUI.</summary>
|
/// <summary> Draws the node GUI.</summary>
|
||||||
/// <param name="portPositions">Port handle positions need to be returned to the NodeEditorWindow </param>
|
/// <param name="portPositions">Port handle positions need to be returned to the NodeEditorWindow </param>
|
||||||
public virtual void OnNodeGUI(out Dictionary<NodePort,Vector2> portPositions) {
|
public virtual void OnNodeGUI(out Dictionary<NodePort,Vector2> portPositions) {
|
||||||
|
DrawDefaultHeaderGUI();
|
||||||
DrawDefaultNodePortsGUI(out portPositions);
|
DrawDefaultNodePortsGUI(out portPositions);
|
||||||
DrawDefaultNodeBodyGUI();
|
DrawDefaultNodeBodyGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void DrawDefaultHeaderGUI() {
|
||||||
|
|
||||||
|
GUILayout.Label(target.name, NodeEditorResources.styles.headerStyle, GUILayout.Height(30));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Draws standard editors for all fields marked with <see cref="Node.InputAttribute"/> or <see cref="Node.OutputAttribute"/> </summary>
|
/// <summary> Draws standard editors for all fields marked with <see cref="Node.InputAttribute"/> or <see cref="Node.OutputAttribute"/> </summary>
|
||||||
protected void DrawDefaultNodePortsGUI(out Dictionary<NodePort, Vector2> portPositions) {
|
protected void DrawDefaultNodePortsGUI(out Dictionary<NodePort, Vector2> portPositions) {
|
||||||
portPositions = new Dictionary<NodePort, Vector2>();
|
portPositions = new Dictionary<NodePort, Vector2>();
|
||||||
@ -145,6 +151,10 @@ public class NodeEditor {
|
|||||||
fieldInfo.SetValue(target, fieldValue);
|
fieldInfo.SetValue(target, fieldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual int GetWidth() {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
|||||||
@ -4,7 +4,6 @@ using UnityEngine;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/// <summary> User input related UNEC functionality </summary>
|
|
||||||
public partial class NodeEditorWindow {
|
public partial class NodeEditorWindow {
|
||||||
|
|
||||||
public static bool isPanning { get; private set; }
|
public static bool isPanning { get; private set; }
|
||||||
|
|||||||
@ -164,23 +164,21 @@ public partial class NodeEditorWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BeginZoomed(position, zoom);
|
BeginZoomed(position, zoom);
|
||||||
//if (e.type == EventType.Repaint) portRects.Clear();
|
|
||||||
foreach (Node node in graph.nodes) {
|
foreach (Node node in graph.nodes) {
|
||||||
|
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
|
||||||
|
nodeEditor.target = node;
|
||||||
|
|
||||||
//Get node position
|
//Get node position
|
||||||
Vector2 nodePos = GridToWindowPositionNoClipped(node.rect.position);
|
Vector2 nodePos = GridToWindowPositionNoClipped(node.rect.position);
|
||||||
|
|
||||||
GUIStyle style = (node == selectedNode) ? (GUIStyle)"flow node 0 on" : (GUIStyle)"flow node 0";
|
GUIStyle style = (node == selectedNode) ? (GUIStyle)"flow node 0 on" : (GUIStyle)"flow node 0";
|
||||||
GUILayout.BeginArea(new Rect(nodePos,new Vector2(240,4000)));
|
style = new GUIStyle(style);
|
||||||
string nodeName = string.IsNullOrEmpty(node.name) ? node.ToString() : node.name;
|
style.padding.top = 0;
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginArea(new Rect(nodePos,new Vector2(nodeEditor.GetWidth(), 4000)));
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.BeginVertical(style);
|
||||||
GUILayout.BeginVertical(nodeName, style, GUILayout.Width(200));
|
|
||||||
|
|
||||||
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
|
|
||||||
|
|
||||||
nodeEditor.target = node;
|
|
||||||
|
|
||||||
|
//Draw node contents
|
||||||
Dictionary<NodePort, Vector2> portHandlePoints;
|
Dictionary<NodePort, Vector2> portHandlePoints;
|
||||||
nodeEditor.OnNodeGUI(out portHandlePoints);
|
nodeEditor.OnNodeGUI(out portHandlePoints);
|
||||||
if (e.type == EventType.Repaint) {
|
if (e.type == EventType.Repaint) {
|
||||||
@ -194,10 +192,7 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
GUILayout.FlexibleSpace();
|
//if (e.type == EventType.Repaint) node.rect.size = GUILayoutUtility.GetLastRect().size;
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
if (e.type == EventType.Repaint) node.rect.size = GUILayoutUtility.GetLastRect().size;
|
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
}
|
}
|
||||||
EndZoomed(position, zoom);
|
EndZoomed(position, zoom);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public static class NodeEditorResources {
|
|||||||
public static Styles _styles = null;
|
public static Styles _styles = null;
|
||||||
|
|
||||||
public class Styles {
|
public class Styles {
|
||||||
public GUIStyle inputStyle, outputStyle;
|
public GUIStyle inputStyle, outputStyle, headerStyle;
|
||||||
|
|
||||||
public Styles() {
|
public Styles() {
|
||||||
GUIStyle baseStyle = new GUIStyle("Label");
|
GUIStyle baseStyle = new GUIStyle("Label");
|
||||||
@ -35,6 +35,10 @@ public static class NodeEditorResources {
|
|||||||
outputStyle = new GUIStyle(baseStyle);
|
outputStyle = new GUIStyle(baseStyle);
|
||||||
outputStyle.alignment = TextAnchor.UpperRight;
|
outputStyle.alignment = TextAnchor.UpperRight;
|
||||||
outputStyle.padding.right = 10;
|
outputStyle.padding.right = 10;
|
||||||
|
|
||||||
|
headerStyle = new GUIStyle();
|
||||||
|
headerStyle.alignment = TextAnchor.MiddleCenter;
|
||||||
|
headerStyle.fontStyle = FontStyle.Bold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public abstract class Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Initialize node. Called on creation. </summary>
|
/// <summary> Initialize node. Called on creation. </summary>
|
||||||
protected virtual void Init() { }
|
protected virtual void Init() { name = GetType().Name; }
|
||||||
|
|
||||||
/// <summary> Called whenever a connection is being made between two <see cref="NodePort"/>s</summary>
|
/// <summary> Called whenever a connection is being made between two <see cref="NodePort"/>s</summary>
|
||||||
/// <param name="from">Output</param> <param name="to">Input</param>
|
/// <param name="from">Output</param> <param name="to">Input</param>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user