(client) chore:支持unity的方式加载资源,调整文件名与定义的分布
This commit is contained in:
40
Client/Assets/Scripts/Data/BehaviorTreeDef.cs
Normal file
40
Client/Assets/Scripts/Data/BehaviorTreeDef.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class BehaviorTreeDef : Define
|
||||
{
|
||||
public BehaviorTreeDef[] childTree;
|
||||
public string className="Selector";
|
||||
public string value;
|
||||
|
||||
|
||||
public override bool Init(XElement xmlDef)
|
||||
{
|
||||
base.Init(xmlDef);
|
||||
|
||||
// 从当前节点获取className和condition属性
|
||||
className = xmlDef.Attribute("className")?.Value ?? className;
|
||||
value = xmlDef.Attribute("value")?.Value;
|
||||
|
||||
var nodes = xmlDef.Elements("Node");
|
||||
if (!nodes.Any())
|
||||
return true; // 没有子节点也是有效的
|
||||
|
||||
List<BehaviorTreeDef> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user