/// <summary> /// 控制节点添加子控制节点 /// </summary> /// <param name="nodeName"></param> /// <param name="node"></param> public void AddNode2Contol(string nodeName, BaseNode node) { BaseNode temp = FindControlNode(childNode, nodeName); temp.AddNode(node); node.parentNode = temp; }
/// <summary> /// 根据json解析怪物行为,并生成行为树 /// </summary> /// <param name="behaviours"></param> /// <returns></returns> public bool AnalysisAction(List <ControlNodeData> behaviours) { foreach (var item in behaviours) { SwithControlNode(item.controlNodeType, ref temp); temp.nodeName = item.controlNodeName; temp.priority = item.priority; if (item.parentNodeName == "root") { rootNode.AddNode(temp); } else { rootNode.AddNode2Contol(item.parentNodeName, temp); } for (int i = 0; i < item.nodes.Count; i++) { //根据行为类名 string 反射出对应行为类,比将其作为行为节点 加载到对应的控制节点下 Type type = Type.GetType(rootNode.GetType().Namespace + "." + item.nodes[i].ToString(), true, true); var action = Activator.CreateInstance(type) as BaseNode; temp.AddNode(action); } } //-------------------- //测试用 rootNode.excute(); //-------------------- return(true); }
//public TreeNode ProClass(int key, Dictionary<int, List<string>> rTreesMsg) //{ // TreeNode rTree = (TreeNode)Activator.CreateInstance(Type.GetType(configTest.NodeName[int.Parse(rTreesMsg[key][1])])); // rTree.ID = key; // rTree.Priority = int.Parse(rTreesMsg[key][2]); // if (rTreesMsg[key][3] != "") // { // List<string> cNodes = new List<string>(rTreesMsg[key][3].Split('.')); // for (int i = 0; i < cNodes.Count; i++) // { // rTree.AddNode(/*this.ProClass(int.Parse(cNodes[i]), rTreesMsg)*/); // } // } // return rTree; //} public static BaseNode CreateTree(BaseNode rBase, int nTreeID, List <string> rTreesMsg) { if (rTreesMsg[3] != "") { List <string> cNodes = new List <string>(rTreesMsg[3].Split('.')); for (int i = 0; i < cNodes.Count; i++) { int ID = int.Parse(cNodes[i]); rBase.AddNode(CreateNode(nTreeID, ID, configTest.TreeDic[nTreeID][ID]) /*this.ProClass(int.Parse(cNodes[i]), rTreesMsg)*/); } } return(rBase); }