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

NodeEditorGUILayout: Use InputPort style

This commit is contained in:
Woland 2018-08-16 23:13:36 +02:00
parent 8adc4fd459
commit b9606ac680

View File

@ -13,6 +13,7 @@ namespace XNodeEditor {
private static readonly Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>> reorderableListCache = new Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>>(); private static readonly Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>> reorderableListCache = new Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>>();
private static int reorderableListIndex = -1; private static int reorderableListIndex = -1;
private static GUIContent emptyLabel = new GUIContent("");
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary> /// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
public static void PropertyField(SerializedProperty property, bool includeChildren = true, params GUILayoutOption[] options) { 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); InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType);
return; return;
} }
GUIStyle inputStyle = NodeEditorResources.styles.inputPort;
switch (showBacking) { switch (showBacking) {
case XNode.Node.ShowBackingValue.Unconnected: case XNode.Node.ShowBackingValue.Unconnected:
// Display a label if port is connected DrawStyledPropertyField(property, label, inputStyle, showBacking: !port.IsConnected, includeChildren);
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));
break; break;
case XNode.Node.ShowBackingValue.Never: case XNode.Node.ShowBackingValue.Never:
// Display a label // Display a label
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), inputStyle);
break; break;
case XNode.Node.ShowBackingValue.Always: case XNode.Node.ShowBackingValue.Always:
// Display an editable property field DrawStyledPropertyField(property, label, inputStyle, showBacking: true, includeChildren);
EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
break; 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 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) {
// Display a label // Display a label
EditorGUILayout.LabelField(content, options); EditorGUILayout.LabelField(content, NodeEditorResources.styles.inputPort, options);
Rect rect = GUILayoutUtility.GetLastRect(); Rect rect = GUILayoutUtility.GetLastRect();
position = rect.position - new Vector2(16, 0); position = rect.position - new Vector2(16, 0);
@ -303,6 +302,16 @@ namespace XNodeEditor {
list.DoLayoutList(); 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<XNode.NodePort> instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) { private static ReorderableList CreateReorderableList(string fieldName, List<XNode.NodePort> instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) {
bool hasArrayData = arrayData != null && arrayData.isArray; bool hasArrayData = arrayData != null && arrayData.isArray;
XNode.Node node = serializedObject.targetObject as XNode.Node; XNode.Node node = serializedObject.targetObject as XNode.Node;
@ -467,4 +476,4 @@ namespace XNodeEditor {
return list; return list;
} }
} }
} }