mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Added support for [Header] attribute
This commit is contained in:
parent
63c3ae2f7d
commit
984fe730c0
@ -45,6 +45,11 @@ namespace XNodeEditor {
|
|||||||
SpaceAttribute spaceAttribute;
|
SpaceAttribute spaceAttribute;
|
||||||
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out spaceAttribute)) spacePadding = spaceAttribute.height;
|
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out spaceAttribute)) spacePadding = spaceAttribute.height;
|
||||||
|
|
||||||
|
//GUI Values are from https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/ScriptAttributeGUI/Implementations/DecoratorDrawers.cs
|
||||||
|
float headerPadding = 0;
|
||||||
|
HeaderAttribute headerAttribute;
|
||||||
|
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out headerAttribute)) headerPadding = EditorGUIUtility.singleLineHeight * 1.5f;
|
||||||
|
|
||||||
// If property is an input, display a regular property field and put a port handle on the left side
|
// If property is an input, display a regular property field and put a port handle on the left side
|
||||||
if (port.direction == XNode.NodePort.IO.Input) {
|
if (port.direction == XNode.NodePort.IO.Input) {
|
||||||
// Get data from [Input] attribute
|
// Get data from [Input] attribute
|
||||||
@ -64,6 +69,14 @@ namespace XNodeEditor {
|
|||||||
GUILayout.Space(spacePadding);
|
GUILayout.Space(spacePadding);
|
||||||
spacePadding = 0;
|
spacePadding = 0;
|
||||||
}
|
}
|
||||||
|
if (headerPadding > 0 && useLayoutSpace)
|
||||||
|
{
|
||||||
|
Rect position = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight * 1.5f);
|
||||||
|
position.yMin += (EditorGUIUtility.singleLineHeight * 0.5f) + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
position = EditorGUI.IndentedRect(position);
|
||||||
|
GUI.Label(position, headerAttribute.header, EditorStyles.boldLabel);
|
||||||
|
headerPadding = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (dynamicPortList) {
|
if (dynamicPortList) {
|
||||||
Type type = GetType(property);
|
Type type = GetType(property);
|
||||||
@ -89,7 +102,7 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position - new Vector2(16, -spacePadding);
|
rect.position = rect.position - new Vector2(16, -(spacePadding + headerPadding));
|
||||||
// If property is an output, display a text label and put a port handle on the right side
|
// If property is an output, display a text label and put a port handle on the right side
|
||||||
} else if (port.direction == XNode.NodePort.IO.Output) {
|
} else if (port.direction == XNode.NodePort.IO.Output) {
|
||||||
// Get data from [Output] attribute
|
// Get data from [Output] attribute
|
||||||
@ -109,6 +122,14 @@ namespace XNodeEditor {
|
|||||||
GUILayout.Space(spacePadding);
|
GUILayout.Space(spacePadding);
|
||||||
spacePadding = 0;
|
spacePadding = 0;
|
||||||
}
|
}
|
||||||
|
if (headerPadding > 0 && useLayoutSpace)
|
||||||
|
{
|
||||||
|
Rect position = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight * 1.5f);
|
||||||
|
position.yMin += (EditorGUIUtility.singleLineHeight * 0.5f) + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
position = EditorGUI.IndentedRect(position);
|
||||||
|
GUI.Label(position, headerAttribute.header, EditorStyles.boldLabel);
|
||||||
|
headerPadding = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (dynamicPortList) {
|
if (dynamicPortList) {
|
||||||
Type type = GetType(property);
|
Type type = GetType(property);
|
||||||
@ -134,7 +155,7 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position + new Vector2(rect.width, spacePadding);
|
rect.position = rect.position + new Vector2(rect.width, spacePadding + headerPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.size = new Vector2(16, 16);
|
rect.size = new Vector2(16, 16);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user