From c58ca510ccc4eb29c11d8a584d99baa610e2fb55 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 1 Apr 2021 15:48:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E8=8E=B7=E5=8F=96=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8F=82=E6=95=B0=E8=A1=A5=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ source/bin/framework.d.ts | 4 ++-- source/src/ECS/Entity.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bbd5db10..3ed1ece1 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,11 @@ class MoveSystem extends es.EntityProcessingSystem { // 因为在构造函数中有一个Matcher匹配器,在你初始化MoveSystem的时候需要你传入匹配的对象. 见下方如何定义匹配带MoveComponent的匹配器 // 该方法每帧都会执行,请确保您的操作尽可能的小或者在使用大数据时采用缓存的方法进行获取操作 + const moveComponent = entity.getComponent(MovementComponent); + if (!moveComponent.enabled) + return; + + // 根据moveComponent的数据执行移动的逻辑 } } ``` diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index dceddcdb..be9d3bf8 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -375,12 +375,12 @@ declare module es { * 检查实体是否具有该组件 * @param type */ - hasComponent(type: any): boolean; + hasComponent(type: new (...args: any[]) => T): boolean; /** * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 * @param type */ - getOrCreateComponent(type: any): T; + getOrCreateComponent(type: new (...args: any[]) => T): T; /** * 获取typeName类型的所有组件,但不使用列表分配 * @param typeName diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 44b49aa0..a55e23d6 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -424,7 +424,7 @@ module es { * 检查实体是否具有该组件 * @param type */ - public hasComponent(type) { + public hasComponent(type: new (...args) => T) { return this.components.getComponent(type, false) != null; } @@ -432,7 +432,7 @@ module es { * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 * @param type */ - public getOrCreateComponent(type) { + public getOrCreateComponent(type: new (...args) => T) { let comp = this.components.getComponent(type, true); if (!comp) { comp = this.addComponent(new type());