更新文档及优化行为树编辑器

This commit is contained in:
YHH
2025-06-19 10:38:31 +08:00
parent 82cd163adc
commit 8c86d6b696
20 changed files with 1608 additions and 286 deletions

View File

@@ -387,16 +387,12 @@ class HealthComponent extends Component {
this.currentHealth -= damage;
// 发送事件,让其他系统响应
Core.emitter.emit('health:damaged', {
entity: this.entity,
damage: damage,
remainingHealth: this.currentHealth
});
// 注意需要在实际使用中获取EntityManager实例
// 示例entityManager.eventBus.emit('health:damaged', {...});
if (this.currentHealth <= 0) {
Core.emitter.emit('health:died', {
entity: this.entity
});
// 示例entityManager.eventBus.emit('health:died', {...});
console.log('实体死亡');
}
}
}
@@ -406,12 +402,13 @@ class AnimationComponent extends Component {
onAddedToEntity() {
super.onAddedToEntity();
// 监听受伤事件
Core.emitter.addObserver('health:damaged', this.onDamaged, this);
// 监听受伤事件需要在实际使用中获取EntityManager实例
// 示例entityManager.eventBus.on('health:damaged', this.onDamaged, { context: this });
}
onRemovedFromEntity() {
Core.emitter.removeObserver('health:damaged', this.onDamaged, this);
// 事件监听会在组件移除时自动清理
// 如需手动清理保存listenerId并调用eventBus.off()
super.onRemovedFromEntity();
}