支持可以任意参数

This commit is contained in:
YHH
2025-08-12 11:47:18 +08:00
parent 56dd18b983
commit baeb047e27
5 changed files with 8 additions and 6 deletions

2
package-lock.json generated
View File

@@ -11400,7 +11400,7 @@
}, },
"packages/core": { "packages/core": {
"name": "@esengine/ecs-framework", "name": "@esengine/ecs-framework",
"version": "2.1.34", "version": "2.1.35",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^28.0.3", "@rollup/plugin-commonjs": "^28.0.3",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/ecs-framework", "name": "@esengine/ecs-framework",
"version": "2.1.34", "version": "2.1.35",
"description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架", "description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架",
"type": "module", "type": "module",
"main": "bin/index.js", "main": "bin/index.js",

View File

@@ -8,8 +8,9 @@ export { EnableSoA, HighPrecision, Float64, Int32, SerializeMap, SerializeSet, S
/** /**
* 组件类型定义 * 组件类型定义
* 支持任意构造函数签名,提供更好的类型安全性
*/ */
export type ComponentType<T extends Component = Component> = new (...args: unknown[]) => T; export type ComponentType<T extends Component = Component> = new (...args: any[]) => T;
/** /**
* 组件注册表 * 组件注册表

View File

@@ -335,7 +335,7 @@ export class Entity {
*/ */
public createComponent<T extends Component>( public createComponent<T extends Component>(
componentType: ComponentType<T>, componentType: ComponentType<T>,
...args: unknown[] ...args: any[]
): T { ): T {
const component = new componentType(...args); const component = new componentType(...args);
return this.addComponent(component); return this.addComponent(component);
@@ -508,7 +508,7 @@ export class Entity {
*/ */
public getOrCreateComponent<T extends Component>( public getOrCreateComponent<T extends Component>(
type: ComponentType<T>, type: ComponentType<T>,
...args: unknown[] ...args: any[]
): T { ): T {
let component = this.getComponent(type); let component = this.getComponent(type);
if (!component) { if (!component) {

View File

@@ -54,8 +54,9 @@ export interface ISystemBase {
* 组件类型定义 * 组件类型定义
* *
* 用于类型安全的组件操作 * 用于类型安全的组件操作
* 支持任意构造函数签名,提供更好的类型安全性
*/ */
export type ComponentType<T extends IComponent = IComponent> = new (...args: unknown[]) => T; export type ComponentType<T extends IComponent = IComponent> = new (...args: any[]) => T;
/** /**
* 事件总线接口 * 事件总线接口