示例#1
0
        public BTreeData(JSON js)
        {
            _id = js.ToString("name");

            List <BTNodeData> listOfNodes = new List <BTNodeData>();

            JSON[] nodeList = js.ToArray <JSON>("bTree");
            for (int i = 0; i < nodeList.Length; ++i)
            {
                BTNodeData nodeData = BTNodeData.CreateNodeData(nodeList[i]);
                listOfNodes.Add(nodeData);
            }

            JSON[] connectionList = js.ToArray <JSON>("connections");
            for (int i = 0; i < connectionList.Length; ++i)
            {
                int        inNodeId  = connectionList[i].ToInt("inNodeId");
                int        outNodeId = connectionList[i].ToInt("outNodeId");
                BTNodeData inNode    = listOfNodes[inNodeId];
                BTNodeData outNode   = listOfNodes[outNodeId];
                if (inNode.type == BTNodeData.TYPE.ROOT || inNode.type == BTNodeData.TYPE.DECORATOR)
                {
                    (inNode as BTDecoratorNodeData).AddChild(outNode);
                    if (inNode.type == BTNodeData.TYPE.ROOT)
                    {
                        _btRootData = outNode;
                    }
                }
                else if (inNode.type == BTNodeData.TYPE.COMPOSITE)
                {
                    (inNode as BTCompositeNodeData).AddChild(outNode);
                }
            }
        }
示例#2
0
        public static BTNodeData CreateNodeData(JSON js)
        {
            string baseTypeStr = js.ToString("baseType");
            TYPE   baseType    = (TYPE)Enum.Parse(typeof(TYPE), baseTypeStr);

            if (baseType == TYPE.ACTION)
            {
                return(BTActionNodeData.CreateActionNodeData(js));
            }
            else if (baseType == TYPE.DECORATOR)
            {
                return(BTDecoratorNodeData.CreateDecoratorNodeData(js));
            }
            else if (baseType == TYPE.COMPOSITE)
            {
                return(BTCompositeNodeData.CreateCompositeNodeData(js));
            }
            else if (baseType == TYPE.ROOT)
            {
                BTNodeData rootNodeData = BTDecoratorNodeData.CreateRootNodeData(js);
                rootNodeData.type = TYPE.ROOT;
                return(rootNodeData);
            }
            else
            {
                UnityEngine.Debug.Log("Error: Invalid Node Type: " + baseTypeStr);
            }
            return(null);
        }
示例#3
0
        public BTDecoratorNodeData(JSON js) : base(js, TYPE.DECORATOR)
        {
            JSON paramsJS = js.ToJSON("nodeParams");

            if (paramsJS.Contains("child"))
            {
                JSON       childNodeJS = paramsJS.ToJSON("child");
                BTNodeData childNode   = BTNodeData.CreateNodeData(childNodeJS);
                if (childNode != null)
                {
                    AddChild(childNode);
                }
            }
        }
示例#4
0
        public BTCompositeNodeData(JSON js) : base(js, TYPE.COMPOSITE)
        {
            _children = new List <BTNodeData>();

            JSON paramsJS = js.ToJSON("nodeParams");

            JSON[] childrenJS = paramsJS.ToArray <JSON>("children");
            for (int i = 0; i < childrenJS.Length; ++i)
            {
                JSON       nodeJS    = childrenJS[i];
                BTNodeData childNode = BTNodeData.CreateNodeData(nodeJS);
                if (childNode != null)
                {
                    AddChild(childNode);
                }
            }
        }
示例#5
0
        public static BTNode CreateActionNode(BTNodeData btNodeData, BTree bTree, BTNode parent)
        {
            if (btNodeData is BTMoveToPointNodeData)
            {
                return(new BTMoveToPointNode(btNodeData as BTMoveToPointNodeData, bTree, parent));
            }
            else if (btNodeData is BTScaleNodeData)
            {
                return(new BTScaleNode(btNodeData as BTScaleNodeData, bTree, parent));
            }
            else if (btNodeData is BTWaitNodeData)
            {
                return(new BTWaitNode(btNodeData as BTWaitNodeData, bTree, parent));
            }

            return(null);
        }
示例#6
0
        public static BTNode CreateCompositeNode(BTNodeData btNodeData, BTree bTree, BTNode parent)
        {
            if (btNodeData is BTSequenceNodeData)
            {
                return(new BTSequenceNode(btNodeData as BTSequenceNodeData, bTree, parent));
            }
            else if (btNodeData is BTSelectorNodeData)
            {
                return(new BTSelectorNode(btNodeData as BTSelectorNodeData, bTree, parent));
            }
            else if (btNodeData is BTParallelNodeData)
            {
                return(new BTParallelNode(btNodeData as BTParallelNodeData, bTree, parent));
            }
            else if (btNodeData is BTDynamicSelectorNodeData)
            {
                return(new BTDynamicSelectorNode(btNodeData as BTDynamicSelectorNodeData, bTree, parent));
            }

            return(null);
        }
示例#7
0
 public void AddChild(BTNodeData btNode)
 {
     _children.Add(btNode);
 }
示例#8
0
 public void AddChild(BTNodeData btNode)
 {
     _child = btNode;
 }