示例#1
0
        public uint CreateActionNode(ActionNode.Do func)
        {
            ActionNode newNode = new ActionNode(func);

            newNode.SetID(++m_nodeID);
            uint a = newNode.GetID();

            m_nodeDic.Add(a, newNode);
            return(a);
        }
示例#2
0
        STreeNode GetTreeNode(Node node)
        {
            STreeNode mine     = new STreeNode();
            var       nodeName = node.ToString();

            // leaf node
            if (nodeName == "ActionNode")
            {
                ActionNode a = (ActionNode)node;
                mine.id    = a.GetID();
                mine.name  = a.GetFunction().GetMethodInfo().Name;
                mine.state = a.NodeState;
                mine.Type  = "ActionNode";
            }
            // decorator node
            else if (nodeName == "Inverter" || nodeName == "Repeater" || nodeName == "RepeatTillFail" || nodeName == "Limiter" || nodeName == "Succeeder")
            {
                DecoratorNode d = (DecoratorNode)node;

                mine.id       = d.GetID();
                mine.name     = d.ToString();
                mine.state    = d.NodeState;
                mine.Type     = "DecoratorNode";
                mine.children = new List <STreeNode>()
                {
                    GetTreeNode(d.ChildNode)
                };
            }
            // composite node
            else if (nodeName == "Selector" || nodeName == "Sequence")
            {
                CompositeNode c = (CompositeNode)node;

                mine.id       = c.GetID();
                mine.name     = c.ToString();
                mine.state    = c.NodeState;
                mine.Type     = "CompositeNode";
                mine.children = new List <STreeNode>();
                foreach (Node childNode in c.ChildNodeList)
                {
                    mine.children.Add(GetTreeNode(childNode));
                }
            }

            return(mine);
        }