/// <summary> /// 图运行时节点信息 /// </summary> /// <returns></returns> private static byte[] ConvertToRuntimeInfo(List <NodeEditorView> nodeViewList, List <GraphVariableInfo> graphVariableInfoList, int graphId) { FlatBufferBuilder fbb = new FlatBufferBuilder(1024); Offset <NodeInfo>[] nodeInfoOffsets = new Offset <NodeInfo> [nodeViewList.Count]; List <int> commonNodeIdList = new List <int>(); List <int> entranceNodeIdList = new List <int>(); for (int i = 0; i < nodeViewList.Count; i++) { NodeEditorView nodeView = nodeViewList[i]; Offset <NodeInfo> nodeInfoOffset = ConvertToRuntimeNodeInfo(fbb, nodeView); nodeInfoOffsets[i] = nodeInfoOffset; if (nodeView.CheckNodeIsCommonNode()) { commonNodeIdList.Add(nodeView.NodeId); } if (nodeView.ReflectionInfo.IsEntranceNode) { entranceNodeIdList.Add(nodeView.NodeId); } } VectorOffset nodeVectorOffset = GraphInfo.CreateNodesVector(fbb, nodeInfoOffsets); //common node ids GraphInfo.StartCommonNodeIdsVector(fbb, commonNodeIdList.Count); for (int i = commonNodeIdList.Count - 1; i >= 0; i--) { fbb.AddInt(commonNodeIdList[i]); } VectorOffset commonNodeVectorOffset = fbb.EndVector(); //entrance node ids GraphInfo.StartEntranceNodeIdsVector(fbb, entranceNodeIdList.Count); for (int i = entranceNodeIdList.Count - 1; i >= 0; i--) { fbb.AddInt(entranceNodeIdList[i]); } VectorOffset entranceNodeVectorOffset = fbb.EndVector(); //graph variable infos int graphVariableCount = graphVariableInfoList.Count; Offset <FlatNode.Runtime.Flat.GraphVariableInfo>[] graphVariableInfoOffsets = new Offset <FlatNode.Runtime.Flat.GraphVariableInfo> [graphVariableCount]; for (int i = 0; i < graphVariableCount; i++) { graphVariableInfoOffsets[i] = ConvertToRuntimeGraphVariableInfo(fbb, graphVariableInfoList[i]); } VectorOffset graphVariableInfoVectorOffset = GraphInfo.CreateGraphVariableInfosVector(fbb, graphVariableInfoOffsets); GraphInfo.StartGraphInfo(fbb); GraphInfo.AddGraphId(fbb, graphId); GraphInfo.AddCommonNodeIds(fbb, commonNodeVectorOffset); GraphInfo.AddEntranceNodeIds(fbb, entranceNodeVectorOffset); GraphInfo.AddNodes(fbb, nodeVectorOffset); GraphInfo.AddGraphVariableInfos(fbb, graphVariableInfoVectorOffset); Offset <GraphInfo> offset = GraphInfo.EndGraphInfo(fbb); fbb.Finish(offset.Value); return(fbb.SizedByteArray()); }
/// <summary> /// 检查一个节点是否是通用节点。 /// 通用节点是指该节点不会从技能入口流入到或者取值不会从能够从技能入口流入到的节点取值。 /// 递归所有左Flow In节点和Input节点,如果能够访问到入口节点,则该节点不是通用节点。 /// </summary> /// <returns></returns> public bool CheckNodeIsCommonNode(HashSet <NodeEditorView> checkedNodeSet = null) { if (ReflectionInfo.Type.IsSubclassOf(typeof(EntranceNodeBase))) { return(false); } if (checkedNodeSet == null) { checkedNodeSet = new HashSet <NodeEditorView>(); } if (flowInPortView != null && flowInPortView.connectedPortList.Count > 0) { List <PortEditorView> connectionPortList = flowInPortView.connectedPortList; for (int i = 0; i < connectionPortList.Count; i++) { NodeEditorView nodeView = connectionPortList[i].NodeView; if (checkedNodeSet.Contains(nodeView)) { continue; } if (nodeView.ReflectionInfo.Type.IsSubclassOf(typeof(EntranceNodeBase))) { return(false); } checkedNodeSet.Add(nodeView); if (!nodeView.CheckNodeIsCommonNode(checkedNodeSet)) { return(false); } } } if (inputPortViewList.Count > 0) { for (int i = 0; i < inputPortViewList.Count; i++) { List <PortEditorView> connectionPortList = inputPortViewList[i].connectedPortList; for (int j = 0; j < connectionPortList.Count; j++) { NodeEditorView nodeView = connectionPortList[j].NodeView; if (checkedNodeSet.Contains(nodeView)) { continue; } if (nodeView.ReflectionInfo.Type.IsSubclassOf(typeof(EntranceNodeBase))) { return(false); } checkedNodeSet.Add(nodeView); if (!nodeView.CheckNodeIsCommonNode(checkedNodeSet)) { return(false); } } } } return(true); }