コード例 #1
0
ファイル: BaseNode.cs プロジェクト: mengtest/CZNode
        /// <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;
            }
        }
コード例 #2
0
ファイル: BaseNode.cs プロジェクト: mengtest/CZNode
        /// <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();
        }