1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Fix for [Space] attribute.

Code is a bit messy.
This commit is contained in:
Simon Rodriguez 2018-12-15 15:31:12 +01:00
parent 5b11e81027
commit f3090111be

View File

@ -43,6 +43,10 @@ namespace XNodeEditor {
else { else {
Rect rect = new Rect(); Rect rect = new Rect();
float spacePadding = 0;
SpaceAttribute spaceAttribute;
if(NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out spaceAttribute)) spacePadding = spaceAttribute.height;
// 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
@ -55,6 +59,7 @@ namespace XNodeEditor {
} }
if (instancePortList) { if (instancePortList) {
if (spacePadding > 0) EditorGUILayout.Space();
Type type = GetType(property); Type type = GetType(property);
XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple; XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType); InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType);
@ -63,11 +68,14 @@ namespace XNodeEditor {
switch (showBacking) { switch (showBacking) {
case XNode.Node.ShowBackingValue.Unconnected: case XNode.Node.ShowBackingValue.Unconnected:
// Display a label if port is connected // Display a label if port is connected
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); if (port.IsConnected) {
if (spacePadding > 0) { EditorGUILayout.Space(); spacePadding = 0; }
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName));
// Display an editable property field if port is not connected // Display an editable property field if port is not connected
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); } else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
break; break;
case XNode.Node.ShowBackingValue.Never: case XNode.Node.ShowBackingValue.Never:
if (spacePadding > 0) { EditorGUILayout.Space(); spacePadding = 0; }
// Display a label // Display a label
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName));
break; break;
@ -78,7 +86,7 @@ namespace XNodeEditor {
} }
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.position = rect.position - new Vector2(16, 0); rect.position = rect.position - new Vector2(16, -spacePadding);
// 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
@ -91,6 +99,7 @@ namespace XNodeEditor {
} }
if (instancePortList) { if (instancePortList) {
if (spacePadding > 0) EditorGUILayout.Space();
Type type = GetType(property); Type type = GetType(property);
XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple; XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType); InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType);
@ -99,11 +108,14 @@ namespace XNodeEditor {
switch (showBacking) { switch (showBacking) {
case XNode.Node.ShowBackingValue.Unconnected: case XNode.Node.ShowBackingValue.Unconnected:
// Display a label if port is connected // Display a label if port is connected
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30)); if (port.IsConnected) {
if (spacePadding > 0) { EditorGUILayout.Space(); spacePadding = 0; }
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30));
// Display an editable property field if port is not connected // Display an editable property field if port is not connected
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); } else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
break; break;
case XNode.Node.ShowBackingValue.Never: case XNode.Node.ShowBackingValue.Never:
if (spacePadding > 0) { EditorGUILayout.Space(); spacePadding = 0; }
// Display a label // Display a label
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30)); EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30));
break; break;
@ -114,7 +126,7 @@ namespace XNodeEditor {
} }
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.position = rect.position + new Vector2(rect.width, 0); rect.position = rect.position + new Vector2(rect.width, spacePadding);
} }
rect.size = new Vector2(16, 16); rect.size = new Vector2(16, 16);