/// <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); }