处理装饰节点的非子节点关闭时清理子节点的打开状态

This commit is contained in:
gongxh
2025-10-03 18:49:36 +08:00
parent 9a3e7028d2
commit 249022a300
3 changed files with 23 additions and 11 deletions

View File

@@ -81,9 +81,7 @@ export abstract class BTNode implements IBTNode {
// 执行完成时清理
if (status !== Status.RUNNING) {
this._local.openNodes.delete(this);
this.close();
}
return status;
}
@@ -93,6 +91,17 @@ export abstract class BTNode implements IBTNode {
*/
protected open(): void { }
/**
* 清理子节点的打开状态
* 一般用于装饰节点的非子节点关闭时, 用来清理子节点的打开状态
*/
protected cleanupChild(): void {
const child = this.children[0];
if (child && this._local.openNodes.has(child)) {
this._local.openNodes.delete(child);
}
}
/**
* 执行节点逻辑
* 子类必须实现此方法
@@ -100,12 +109,6 @@ export abstract class BTNode implements IBTNode {
*/
public abstract tick(dt: number): Status;
/**
* 清理节点(执行完成时调用)
* 子类重写此方法进行状态清理
*/
protected close(): void { }
public getEntity<T>(): T {
return this._local.getEntity();
}