mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +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>
|
||||
/// <param name="portPositions">Port handle positions need to be returned to the NodeEditorWindow </param>
|
||||
public virtual void OnNodeGUI(out Dictionary<NodePort,Vector2> portPositions) {
|
||||
DrawDefaultHeaderGUI();
|
||||
DrawDefaultNodePortsGUI(out portPositions);
|
||||
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>
|
||||
protected void DrawDefaultNodePortsGUI(out Dictionary<NodePort, Vector2> portPositions) {
|
||||
portPositions = new Dictionary<NodePort, Vector2>();
|
||||
@ -145,6 +151,10 @@ public class NodeEditor {
|
||||
fieldInfo.SetValue(target, fieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int GetWidth() {
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
|
||||
@ -4,7 +4,6 @@ using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
/// <summary> User input related UNEC functionality </summary>
|
||||
public partial class NodeEditorWindow {
|
||||
|
||||
public static bool isPanning { get; private set; }
|
||||
|
||||
@ -164,23 +164,21 @@ public partial class NodeEditorWindow {
|
||||
}
|
||||
|
||||
BeginZoomed(position, zoom);
|
||||
//if (e.type == EventType.Repaint) portRects.Clear();
|
||||
|
||||
foreach (Node node in graph.nodes) {
|
||||
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
|
||||
nodeEditor.target = node;
|
||||
|
||||
//Get node position
|
||||
Vector2 nodePos = GridToWindowPositionNoClipped(node.rect.position);
|
||||
|
||||
GUIStyle style = (node == selectedNode) ? (GUIStyle)"flow node 0 on" : (GUIStyle)"flow node 0";
|
||||
GUILayout.BeginArea(new Rect(nodePos,new Vector2(240,4000)));
|
||||
string nodeName = string.IsNullOrEmpty(node.name) ? node.ToString() : node.name;
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.BeginVertical(nodeName, style, GUILayout.Width(200));
|
||||
|
||||
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
|
||||
|
||||
nodeEditor.target = node;
|
||||
style = new GUIStyle(style);
|
||||
style.padding.top = 0;
|
||||
GUILayout.BeginArea(new Rect(nodePos,new Vector2(nodeEditor.GetWidth(), 4000)));
|
||||
GUILayout.BeginVertical(style);
|
||||
|
||||
//Draw node contents
|
||||
Dictionary<NodePort, Vector2> portHandlePoints;
|
||||
nodeEditor.OnNodeGUI(out portHandlePoints);
|
||||
if (e.type == EventType.Repaint) {
|
||||
@ -194,10 +192,7 @@ public partial class NodeEditorWindow {
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
if (e.type == EventType.Repaint) node.rect.size = GUILayoutUtility.GetLastRect().size;
|
||||
//if (e.type == EventType.Repaint) node.rect.size = GUILayoutUtility.GetLastRect().size;
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
EndZoomed(position, zoom);
|
||||
|
||||
@ -22,7 +22,7 @@ public static class NodeEditorResources {
|
||||
public static Styles _styles = null;
|
||||
|
||||
public class Styles {
|
||||
public GUIStyle inputStyle, outputStyle;
|
||||
public GUIStyle inputStyle, outputStyle, headerStyle;
|
||||
|
||||
public Styles() {
|
||||
GUIStyle baseStyle = new GUIStyle("Label");
|
||||
@ -35,6 +35,10 @@ public static class NodeEditorResources {
|
||||
outputStyle = new GUIStyle(baseStyle);
|
||||
outputStyle.alignment = TextAnchor.UpperRight;
|
||||
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>
|
||||
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>
|
||||
/// <param name="from">Output</param> <param name="to">Input</param>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user