Feature/ecs behavior tree (#188)
* feat(behavior-tree): 完全 ECS 化的行为树系统 * feat(editor-app): 添加行为树可视化编辑器 * chore: 移除 Cocos Creator 扩展目录 * feat(editor-app): 行为树编辑器功能增强 * fix(editor-app): 修复 TypeScript 类型错误 * feat(editor-app): 使用 FlexLayout 重构面板系统并优化资产浏览器 * feat(editor-app): 改进编辑器UI样式并修复行为树执行顺序 * feat(behavior-tree,editor-app): 添加装饰器系统并优化编辑器性能 * feat(behavior-tree,editor-app): 添加属性绑定系统 * feat(editor-app,behavior-tree): 优化编辑器UI并改进行为树功能 * feat(editor-app,behavior-tree): 添加全局黑板系统并增强资产浏览器功能 * feat(behavior-tree,editor-app): 添加运行时资产导出系统 * feat(behavior-tree,editor-app): 添加SubTree系统和资产选择器 * feat(behavior-tree,editor-app): 优化系统架构并改进编辑器文件管理 * fix(behavior-tree,editor-app): 修复SubTree节点错误显示空节点警告 * fix(editor-app): 修复局部黑板类型定义文件扩展名错误
This commit is contained in:
@@ -649,22 +649,49 @@ export class Entity {
|
||||
|
||||
/**
|
||||
* 获取所有指定类型的组件
|
||||
*
|
||||
*
|
||||
* @param type - 组件类型
|
||||
* @returns 组件实例数组
|
||||
*/
|
||||
public getComponents<T extends Component>(type: ComponentType<T>): T[] {
|
||||
const result: T[] = [];
|
||||
|
||||
|
||||
for (const component of this.components) {
|
||||
if (component instanceof type) {
|
||||
result.push(component as T);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定基类的组件(支持继承查找)
|
||||
*
|
||||
* 与 getComponent() 不同,此方法使用 instanceof 检查,支持子类查找。
|
||||
* 性能比位掩码查询稍慢,但支持继承层次结构。
|
||||
*
|
||||
* @param baseType - 组件基类类型
|
||||
* @returns 第一个匹配的组件实例,如果不存在则返回 null
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // 查找 CompositeNodeComponent 或其子类
|
||||
* const composite = entity.getComponentByType(CompositeNodeComponent);
|
||||
* if (composite) {
|
||||
* // composite 可能是 SequenceNode, SelectorNode 等
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
public getComponentByType<T extends Component>(baseType: ComponentType<T>): T | null {
|
||||
for (const component of this.components) {
|
||||
if (component instanceof baseType) {
|
||||
return component as T;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加子实体
|
||||
*
|
||||
|
||||
@@ -102,8 +102,6 @@ export class World {
|
||||
|
||||
this.name = this._config.name!;
|
||||
this._createdAt = Date.now();
|
||||
|
||||
logger.info(`创建World: ${this.name}`);
|
||||
}
|
||||
|
||||
// ===== Scene管理 =====
|
||||
@@ -132,11 +130,10 @@ export class World {
|
||||
}
|
||||
|
||||
this._scenes.set(sceneId, scene);
|
||||
|
||||
|
||||
// 初始化Scene
|
||||
scene.initialize();
|
||||
|
||||
logger.info(`在World '${this.name}' 中创建Scene: ${sceneId}`);
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,6 @@ export class WorldManager implements IService {
|
||||
const world = new World(worldConfig);
|
||||
this._worlds.set(worldId, world);
|
||||
|
||||
logger.info(`创建World: ${worldId}`, { config: worldConfig });
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user