/// <summary> Make a field for a serialized property. Manual node port override. </summary> public static void PropertyField(SerializedProperty property, GUIContent label, XNode.NodeLinkPort con) { Rect rect = new Rect(); XNode.Node node = con.Node; XNode.NodeLinkDefinition link = con.Link; XNode.Node.InputAttribute inputAttribute = link.InputAttribute; XNode.Node.OutputAttribute outputAttribute = link.OutputAttribute; List <PropertyAttribute> propertyAttributes = NodeEditorUtilities.GetCachedPropertyAttribs(node.GetType(), property.name); float spacePadding = 0; foreach (var attr in propertyAttributes) { if (attr is SpaceAttribute) { spacePadding += (attr as SpaceAttribute).height; } } if (inputAttribute != null) { EditorGUILayout.LabelField(label ?? new GUIContent(property.displayName)); rect = GUILayoutUtility.GetLastRect(); 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 else if (outputAttribute != null) { // Get data from [Output] attribute bool dynamicPortList = outputAttribute.dynamicPortList; XNode.Node.ShowBackingValue showBacking = outputAttribute.backingValue; EditorGUILayout.LabelField(label ?? new GUIContent(property.displayName), NodeEditorResources.OutputPort, GUILayout.MinWidth(30)); rect = GUILayoutUtility.GetLastRect(); rect.position = rect.position + new Vector2(rect.width, spacePadding); } rect.size = new Vector2(16, 16); NodeEditor editor = NodeEditor.GetEditor(node, NodeEditorWindow.current); Color backgroundColor = editor.GetTint(); Color col = NodeEditorWindow.current.graphEditor.GetLinkColor(link); DrawPortHandle(rect, backgroundColor, col); // Register the handle position Vector2 portPos = rect.center; NodeEditor.linkPositions[con] = portPos; }
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary> public static void PropertyField(SerializedProperty property, GUIContent label, bool includeChildren = true, params GUILayoutOption[] options) { if (property == null) { throw new NullReferenceException(); } XNode.Node node = property.serializedObject.targetObject as XNode.Node; XNode.NodeLinkDefinition link = XNode.NodeDataCache.GetLinkCacheInfo(node.GetType(), property.name); XNode.NodePort port = node.GetPort(property.name); if (link != null) { PropertyField(property, label, new XNode.NodeLinkPort(node, link)); } else { PropertyField(property, label, port, includeChildren); } }
/// <summary> Returned color is used to color ports </summary> public virtual Color GetLinkColor(XNode.NodeLinkDefinition link) { return(GetTypeColor(link.LinkType)); }