* 获取第一个匹配的实体及其组件 * * Get first matching entity with its components. * * @returns 实体和组件元组,或 null | Entity and components tuple, or null
()
| 233 | * @returns 实体和组件元组,或 null | Entity and components tuple, or null |
| 234 | */ |
| 235 | public first(): [Entity, ...InstanceTypes<T>] | null { |
| 236 | const entities = this.entities; |
| 237 | if (entities.length === 0) { |
| 238 | return null; |
| 239 | } |
| 240 | |
| 241 | const entity = entities[0]!; |
| 242 | const components: Component[] = []; |
| 243 | |
| 244 | for (const type of this._componentTypes) { |
| 245 | const component = entity.getComponent(type); |
| 246 | if (!component) { |
| 247 | return null; |
| 248 | } |
| 249 | components.push(component); |
| 250 | } |
| 251 | |
| 252 | return [entity, ...(components as InstanceTypes<T>)]; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * 转换为数组 |
no test coverage detected