private static NodeConfigInfo ConvertToNodeInfo(NodeEditorView nodeView) { NodeConfigInfo nodeConfigInfo = new NodeConfigInfo(); nodeConfigInfo.nodeId = nodeView.NodeId; nodeConfigInfo.positionInGraph = nodeView.PositionInGraph; nodeConfigInfo.nodeClassTypeName = nodeView.ReflectionInfo.Type.FullName; nodeConfigInfo.flowOutPortInfoList = new List <FlowOutPortConfigInfo>(); nodeConfigInfo.inputPortInfoList = new List <InputPortConfigInfo>(); //flow out info for (int i = 0; i < nodeView.flowOutPortViews.Length; i++) { FlowOutPortEditorView flowOutPort = nodeView.flowOutPortViews[i]; nodeConfigInfo.flowOutPortInfoList.Add(ConvertToFlowOutPortInfo(flowOutPort)); } //input info for (int i = 0; i < nodeView.inputPortViewList.Count; i++) { InputPortEditorView inputPort = nodeView.inputPortViewList[i]; nodeConfigInfo.inputPortInfoList.Add(ConvertToInputPortInfo(inputPort)); } return(nodeConfigInfo); }
private static NodeEditorView ParseNodeInfo(NodeConfigInfo nodeConfigInfo, GraphEditorWindow graph) { string nodeTypeName = nodeConfigInfo.nodeClassTypeName; Type nodeType = Type.GetType(nodeTypeName + ",Assembly-CSharp"); if (nodeType == null) { Debug.LogErrorFormat("无法载入类型{0} ,该节点被跳过", nodeTypeName); return(null); } NodeReflectionInfo reflectionInfo = new NodeReflectionInfo(nodeType); NodeEditorView nodeView = new NodeEditorView(nodeConfigInfo.positionInGraph, graph, nodeConfigInfo.nodeId, reflectionInfo); return(nodeView); }
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); } } }