コード例 #1
0
        private static InputPortConfigInfo ConvertToInputPortInfo(InputPortEditorView inputPort)
        {
            InputPortConfigInfo inputPortConfigInfo = new InputPortConfigInfo();

            InputPortReflectionInfo inputPortReflectionInfo = inputPort.inputPortReflectionInfo;

            inputPortConfigInfo.portName = inputPortReflectionInfo.inputPortAttribute.portName;

            if (inputPort.connectedPortList.Count > 0)
            {
                inputPortConfigInfo.targetNodeId = inputPort.connectedPortList[0].NodeView.NodeId;
                OutputPortEditorView outputPortView = inputPort.connectedPortList[0] as OutputPortEditorView;
                if (outputPortView == null)
                {
                    Debug.LogErrorFormat("节点{0}的input端口{1} 连接的接口类型不是OutputPortEditorView", inputPort.NodeView.NodeId,
                                         inputPort.portId);
                    return(null);
                }

                inputPortConfigInfo.targetPortName = outputPortView.outputPortReflectionInfo.PortName;
            }
            else
            {
                inputPortConfigInfo.targetNodeId   = -1;
                inputPortConfigInfo.targetPortName = string.Empty;

                inputPortConfigInfo.nodeVariableGenericTypeName = inputPortReflectionInfo.inputValueType.FullName;
                inputPortConfigInfo.nodeVariableValue           = inputPortReflectionInfo.GetNodeVariableValueString();
            }

            return(inputPortConfigInfo);
        }
コード例 #2
0
        private static void UpdateNodeViewData(NodeConfigInfo nodeConfigInfo, NodeEditorView nodeView, GraphEditorData data)
        {
            //flow in port--处理流出节点的时候顺便就处理了

            //flow out port
            for (int i = 0; i < nodeConfigInfo.flowOutPortInfoList.Count; i++)
            {
                FlowOutPortConfigInfo flowOutPortConfigInfo = nodeConfigInfo.flowOutPortInfoList[i];
                FlowOutPortEditorView flowOutPortView       =
                    GetFlowOutPortViewByPortName(nodeView.flowOutPortViews, flowOutPortConfigInfo.flowOutPortName);
                if (flowOutPortView == null)
                {
                    Debug.LogFormat("节点{0}中找不到流出端口 <{1}> 了,该端口的连接被忽略", nodeView.ReflectionInfo.Type,
                                    flowOutPortConfigInfo.flowOutPortName);
                    continue;
                }

                for (int j = 0; j < flowOutPortConfigInfo.targetNodeList.Count; j++)
                {
                    int            targetNodeId   = flowOutPortConfigInfo.targetNodeList[j];
                    NodeEditorView targetNodeView = data.GetNode(targetNodeId);
                    if (targetNodeView == null)
                    {
                        Debug.LogErrorFormat("无法找到节点{0},可能是配置损坏/更改了类名...", targetNodeId);
                        continue;
                    }

                    if (targetNodeView.flowInPortView == null)
                    {
                        Debug.LogErrorFormat("节点类型{0}没有流入节点,是否节点性质发生了改变?", nodeView.ReflectionInfo.Type.FullName);
                        continue;
                    }

                    ConnectionLineView connectionLineView =
                        new ConnectionLineView(flowOutPortView, targetNodeView.flowInPortView, data);
                    data.connectionLineList.Add(connectionLineView);
                }
            }

            //output port -- 不用配置

            //input port
            for (int i = 0; i < nodeConfigInfo.inputPortInfoList.Count; i++)
            {
                InputPortConfigInfo inputPortConfigInfo = nodeConfigInfo.inputPortInfoList[i];
                InputPortEditorView inputPortView       =
                    GetInputPortViewByPortName(nodeView.inputPortViewList, inputPortConfigInfo.portName);

                if (inputPortView == null)
                {
                    Debug.LogFormat("节点{0}中无法找到接口名字为 <{1}> 的NodeInputVariable Field,该接口配置被跳过",
                                    nodeView.ReflectionInfo.Type.FullName, inputPortConfigInfo.portName);
                    continue;
                }

                //没有连接到其他节点的情况
                if (string.IsNullOrEmpty(inputPortConfigInfo.targetPortName))
                {
                    //设置默认值
                    Type valueType = Type.GetType(inputPortConfigInfo.nodeVariableGenericTypeName);
                    if (valueType == null)
                    {
                        valueType = Type.GetType(inputPortConfigInfo.nodeVariableGenericTypeName + ",UnityEngine");
                        if (valueType == null)
                        {
                            valueType = Type.GetType(inputPortConfigInfo.nodeVariableGenericTypeName + ",Assembly-CSharp");
                        }
                    }

                    if (valueType == null)
                    {
                        Debug.LogErrorFormat("工程中找不到类型: {0}", inputPortConfigInfo.nodeVariableGenericTypeName);
                        continue;
                    }

                    SetNodeInputVariableValue(inputPortView.inputPortReflectionInfo, valueType,
                                              inputPortConfigInfo.nodeVariableValue, nodeView);
                }
                //连接到其他节点的情况
                else
                {
                    NodeEditorView connectedToNodeView = data.GetNode(inputPortConfigInfo.targetNodeId);
                    if (connectedToNodeView == null)
                    {
                        Debug.LogErrorFormat("节点 {0} 的input接口 {1} 找不到连接的节点{2}", nodeView.NodeId, inputPortConfigInfo.portName,
                                             inputPortConfigInfo.targetNodeId);
                        continue;
                    }

                    OutputPortEditorView connectedToOutputPortView =
                        GetOutputPortViewByPortName(connectedToNodeView.outputPortViewList, inputPortConfigInfo.targetPortName);
                    if (connectedToOutputPortView == null)
                    {
                        Debug.LogFormat("找不到节点{0}中 接口名字为 <{1}> 的output接口,该接口的连接被跳过", connectedToNodeView.NodeId,
                                        inputPortConfigInfo.targetPortName);
                        continue;
                    }

                    ConnectionLineView connectionLineView =
                        new ConnectionLineView(inputPortView, connectedToOutputPortView, data);
                    data.connectionLineList.Add(connectionLineView);
                }
            }
        }