From b9606ac680ad4e215ab41649f49910e2033b1853 Mon Sep 17 00:00:00 2001 From: Woland Date: Thu, 16 Aug 2018 23:13:36 +0200 Subject: [PATCH] NodeEditorGUILayout: Use InputPort style --- Scripts/Editor/NodeEditorGUILayout.cs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index e3f7c60..b52731a 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -13,6 +13,7 @@ namespace XNodeEditor { private static readonly Dictionary> reorderableListCache = new Dictionary>(); private static int reorderableListIndex = -1; + private static GUIContent emptyLabel = new GUIContent(""); /// Make a field for a serialized property. Automatically displays relevant node port. public static void PropertyField(SerializedProperty property, bool includeChildren = true, params GUILayoutOption[] options) { @@ -71,20 +72,18 @@ namespace XNodeEditor { InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType); return; } + + GUIStyle inputStyle = NodeEditorResources.styles.inputPort; switch (showBacking) { case XNode.Node.ShowBackingValue.Unconnected: - // Display a label if port is connected - if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); - // Display an editable property field if port is not connected - else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); + DrawStyledPropertyField(property, label, inputStyle, showBacking: !port.IsConnected, includeChildren); break; case XNode.Node.ShowBackingValue.Never: // Display a label - EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); + EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), inputStyle); break; case XNode.Node.ShowBackingValue.Always: - // Display an editable property field - EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); + DrawStyledPropertyField(property, label, inputStyle, showBacking: true, includeChildren); break; } @@ -173,7 +172,7 @@ namespace XNodeEditor { // 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) { // Display a label - EditorGUILayout.LabelField(content, options); + EditorGUILayout.LabelField(content, NodeEditorResources.styles.inputPort, options); Rect rect = GUILayoutUtility.GetLastRect(); position = rect.position - new Vector2(16, 0); @@ -303,6 +302,16 @@ namespace XNodeEditor { list.DoLayoutList(); } + private static void DrawStyledPropertyField(SerializedProperty property, GUIContent label, GUIStyle style, bool showBacking = true, bool includeChildren = false) { + EditorGUILayout.BeginHorizontal(); + // Display a label + EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), style, GUILayout.MaxWidth(70)); + // Display an editable property field + if(showBacking) + EditorGUILayout.PropertyField(property, emptyLabel, includeChildren, GUILayout.MinWidth(30)); + EditorGUILayout.EndHorizontal(); + } + private static ReorderableList CreateReorderableList(string fieldName, List instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action onCreation) { bool hasArrayData = arrayData != null && arrayData.isArray; XNode.Node node = serializedObject.targetObject as XNode.Node; @@ -467,4 +476,4 @@ namespace XNodeEditor { return list; } } -} \ No newline at end of file +}