/// <summary> 绘制双向接口 </summary> protected void GenerateBothPort(SerializedProperty iterator, PortAttribute attribute, NodePort nodePort, Direction direction) { Port.Capacity capacity = attribute.Capacity == NodePort.PortCapacity.Single ? Port.Capacity.Single : Port.Capacity.Multi; BasePort port = InstantiatePort(Orientation.Horizontal, direction, capacity, nodePort.DataType) as BasePort; port.userData = nodePort; port.name = NodePort.GetBothName(iterator.name, nodePort.Direction); if (!string.IsNullOrEmpty(attribute.PortName)) { port.portName = attribute.PortName; } else { port.portName = iterator.displayName; } if (AttributeCache.TryGetFieldAttribute(NodeData.GetType(), iterator.name, out NodeTooltipAttribute tooltipAttribute)) { port.tooltip = tooltipAttribute.Tooltip; } PortDic[port.name] = port; switch (port.direction) { case Direction.Input: inputContainer.Add(port); break; case Direction.Output: outputContainer.Add(port); port.onConnect += (Edge edge) => { if (GraphView.Inited) { (edge.output.userData as NodePort).Connect(edge.input.userData as NodePort); EditorUtility.SetDirty(NodeData); } }; port.onDisconnect += (Edge edge) => { (edge.output.userData as NodePort).Disconnect(edge.input.userData as NodePort); EditorUtility.SetDirty(NodeData); }; break; } }
public new static BasePort Create <TEdge>( Orientation orientation, UnityEditor.Experimental.GraphView.Direction direction, Port.Capacity capacity, System.Type type) where TEdge : Edge, new() { BaseEdgeConnectListener connectorListener = new BaseEdgeConnectListener(); BasePort ele = new BasePort(orientation, direction, capacity, type) { m_EdgeConnector = (EdgeConnector) new EdgeConnector <TEdge>((IEdgeConnectorListener)connectorListener) }; ele.AddManipulator((IManipulator)ele.m_EdgeConnector); return(ele); }
public override Port InstantiatePort(Orientation orientation, Direction direction, Port.Capacity capacity, Type type) { return(BasePort.Create <BaseEdge>(orientation, direction, capacity, type)); }
/// <summary> 生成接口 </summary> protected virtual void GeneratePort() { SerializedProperty iterator = SerializedObject.GetIterator(); iterator.NextVisible(true); do { if (_ignoreFields.Contains(iterator.name)) { continue; } if (AttributeCache.TryGetFieldAttribute(NodeData.GetType(), iterator.name, out PortAttribute portAttribute)) { Port.Capacity capacity = portAttribute.Capacity == NodePort.PortCapacity.Single ? Port.Capacity.Single : Port.Capacity.Multi; if (portAttribute.Direction != NodePort.PortDirection.Both) { Direction direction = portAttribute.Direction == NodePort.PortDirection.Input ? Direction.Input : Direction.Output; NodePort nodePort = NodeData.GetPort(iterator.name); BasePort port = InstantiatePort(Orientation.Horizontal, direction, capacity, nodePort.DataType) as BasePort; port.userData = nodePort; port.name = iterator.name; if (!string.IsNullOrEmpty(portAttribute.PortName)) { port.portName = portAttribute.PortName; } else { port.portName = iterator.displayName; } if (AttributeCache.TryGetFieldAttribute(NodeData.GetType(), iterator.name, out NodeTooltipAttribute tooltipAttribute)) { port.tooltip = tooltipAttribute.Tooltip; } PortDic[port.name] = port; switch (port.direction) { case Direction.Input: inputContainer.Add(port); break; case Direction.Output: outputContainer.Add(port); port.onConnect += (Edge edge) => { if (GraphView.Inited) { (edge.output.userData as NodePort).Connect(edge.input.userData as NodePort); EditorUtility.SetDirty(NodeData); } }; port.onDisconnect += (Edge edge) => { (edge.output.userData as NodePort).Disconnect(edge.input.userData as NodePort); EditorUtility.SetDirty(NodeData); }; break; } } else { NodePort nodePortIn = NodeData.GetPort(NodePort.GetBothName(iterator.name, NodePort.PortDirection.Input)); GenerateBothPort(iterator, portAttribute, nodePortIn, Direction.Input); NodePort nodePortOut = NodeData.GetPort(NodePort.GetBothName(iterator.name, NodePort.PortDirection.Output)); GenerateBothPort(iterator, portAttribute, nodePortOut, Direction.Output); } } } while (iterator.NextVisible(false)); RefreshPorts(); }