using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; namespace Data { public class PawnDef : Define { public AttributesDef attributes; public DrawingOrderDef drawingOrder; public BehaviorTreeDef behaviorTree; public string affiliation; } public class MonsterDef:PawnDef { } public class BehaviorTreeDef : Define { public BehaviorTreeDef[] childTree; public string className="Selector"; public string condition; public override bool Init(XElement xmlDef) { base.Init(xmlDef); // 从当前节点获取className和condition属性 className = xmlDef.Attribute("className")?.Value ?? className; condition = xmlDef.Attribute("condition")?.Value; var nodes = xmlDef.Elements("Node"); if (!nodes.Any()) return true; // 没有子节点也是有效的 List children = new(); foreach (var node in nodes) { var childNode = new BehaviorTreeDef(); if (!childNode.Init(node)) return false; children.Add(childNode); } childTree = children.ToArray(); return true; } } public class AffiliationDef : Define { } }