使用ecs系统进行重构

This commit is contained in:
walkpan
2025-01-31 21:50:59 +08:00
parent 6ea3e9504d
commit c5c01c6cf4
18 changed files with 491 additions and 44 deletions

View File

@@ -0,0 +1,19 @@
@ecs.registerSystem()
export class SkillCollisionSystem extends ecs.System {
filter(): ecs.IMatcher {
return ecs.allOf(SkillEffectComp, ColliderComp);
}
update(skills: ecs.Entity[]) {
skills.forEach(skill => {
const collider = skill.get(ColliderComp);
const collisionResult = skill.get(CollisionResultComp) || skill.add(CollisionResultComp);
// 检测碰撞(伪代码,实际使用物理引擎检测)
const hitHeroes = PhysicsSystem.overlap(collider.bounds, 'Hero');
// 转换为ECS实体
collisionResult.targets = hitHeroes.map(h => h.entity);
});
}
}