Example #1
0
        public void Init()
        {
            //初始化入口节点
            GraphInfo graphInfo         = GraphInfo.GetRootAsGraphInfo(byteBuffer);
            int       entranceNodeCount = graphInfo.EntranceNodeIdsLength;

            for (int i = 0; i < entranceNodeCount; i++)
            {
                int nodeId = graphInfo.EntranceNodeIds(i);
                EntranceNodeBase entranceNode = DeserializeNode(nodeId) as EntranceNodeBase;
                if (entranceNode == null)
                {
                    Debug.LogError(string.Format("节点 {0} 不是入口节点", nodeId));
                    continue;
                }

                if (onClickNode == null)
                {
                    onClickNode = entranceNode as OnClickNode;
                }

                if (onJoyStickDragNode == null)
                {
                    onJoyStickDragNode = entranceNode as OnJoyStickDragNode;
                }

                if (onJoyStickDownNode == null)
                {
                    onJoyStickDownNode = entranceNode as OnJoyStickDownNode;
                }

                if (onJoyStickUpNode == null)
                {
                    onJoyStickUpNode = entranceNode as OnJoyStickUpNode;
                }
            }
        }
Example #2
0
        public static NodeBase DeserializeNode(ByteBuffer bb, int nodeId)
        {
            NodeBase  resultNode = null;
            GraphInfo graphInfo  = GraphInfo.GetRootAsGraphInfo(bb);

            int nodeCount = graphInfo.NodesLength;

            for (int i = 0; i < nodeCount; i++)
            {
                NodeInfo?nodeInfo = graphInfo.Nodes(i);
                if (!nodeInfo.HasValue)
                {
                    continue;
                }

                if (nodeInfo.Value.NodeId != nodeId)
                {
                    continue;
                }

                string          nodeClassName = nodeInfo.Value.NodeClassTypeName;
                Func <NodeBase> nodeFactory;
                if (nodeFactoryDictionary.TryGetValue(nodeClassName, out nodeFactory))
                {
                    resultNode = nodeFactory();
                }

                if (resultNode == null)
                {
                    UnityEngine.Debug.LogErrorFormat("无法实例化节点 {0},是否添加了新节点,但是没有生成静态代码?", nodeClassName);
                    return(null);
                }

                Type nodeType = resultNode.GetType();

                resultNode.nodeId = nodeInfo.Value.NodeId;
                resultNode.isCreateSequenceNode = nodeType == typeof(CreateSequenceNode);

                //处理input
                //使用静态生成代码来处理
                int inputFieldCount = nodeInfo.Value.InputPortInfosLength;
                for (int j = 0; j < inputFieldCount; j++)
                {
                    NodeInputFieldInfo nodeInputFieldInfo = nodeInfo.Value.InputPortInfos(j).Value;
//                    WriteNodeInputVariableField(resultNode, nodeType, nodeInfo.Value.InputPortInfos(j).Value);
                    Action <NodeBase, NodeInputFieldInfo> parseFunction;
                    if (inputPortParseFuncDictionary.TryGetValue(nodeType, out parseFunction))
                    {
                        parseFunction(resultNode, nodeInputFieldInfo);
                    }
                    else
                    {
                        UnityEngine.Debug.LogErrorFormat("无法处理节点 {0} 的input port,是否添加了新节点,但是没有生成静态代码?", nodeClassName);
                    }
                }

                //处理flow out
                WriteFlowOutField(resultNode, nodeType, nodeInfo.Value);

                //处理outputPortFuncs
                //使用静态生成代码来处理
                Action <NodeBase> outputFuncsInitAction;
                if (nodeOutputInitFuncDictionary.TryGetValue(nodeType, out outputFuncsInitAction))
                {
                    outputFuncsInitAction(resultNode);
                }

                //还原EntranceNode或者CreateSequenceNode的右侧节点id
                EntranceNodeBase entranceNodeBase = resultNode as EntranceNodeBase;
                if (entranceNodeBase != null)
                {
                    int[] rightSideNodeIds = new int[nodeInfo.Value.RightSideNodeIdsLength];
                    for (int j = 0; j < rightSideNodeIds.Length; j++)
                    {
                        rightSideNodeIds[j] = nodeInfo.Value.RightSideNodeIds(j);
                    }

                    entranceNodeBase.rightSideNodeIds = rightSideNodeIds;
                }
                else
                {
                    CreateSequenceNode createSequenceNode = resultNode as CreateSequenceNode;
                    if (createSequenceNode != null)
                    {
                        int[] rightSideNodeIds = new int[nodeInfo.Value.RightSideNodeIdsLength];
                        for (int j = 0; j < rightSideNodeIds.Length; j++)
                        {
                            rightSideNodeIds[j] = nodeInfo.Value.RightSideNodeIds(j);
                        }

                        createSequenceNode.rightSideNodeIds = rightSideNodeIds;
                    }
                }
            }

            return(resultNode);
        }