using System.Collections.Generic; namespace ColdMint.scripts.behaviorTree; /// /// Behavior tree node template /// 行为树节点模板 /// public abstract class BehaviorTreeNodeTemplate : IBehaviorTreeNode { private readonly List _children = new List(); public void AddChild(IBehaviorTreeNode child) { _children.Add(child); child.Parent = this; } public void RemoveChild(IBehaviorTreeNode child) { _children.Remove(child); child.Parent = null; } /// /// Gets the child node of the specified type /// 获取指定类型的子节点 /// /// /// /// protected T? GetChild(T? defaultT) { if (_children.Count == 0) { return defaultT; } foreach (var behaviorTreeNode in _children) { if (behaviorTreeNode is T t) { return t; } } return defaultT; } public abstract int Execute(bool isPhysicsProcess, double delta); public IBehaviorTreeNode? Parent { get; set; } public IBehaviorTreeNode[] Children => _children.ToArray(); }