支持可以任意参数
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
* 组件注册表
|
||||
|
||||
@@ -335,7 +335,7 @@ export class Entity {
|
||||
*/
|
||||
public createComponent<T extends Component>(
|
||||
componentType: ComponentType<T>,
|
||||
...args: unknown[]
|
||||
...args: any[]
|
||||
): T {
|
||||
const component = new componentType(...args);
|
||||
return this.addComponent(component);
|
||||
@@ -508,7 +508,7 @@ export class Entity {
|
||||
*/
|
||||
public getOrCreateComponent<T extends Component>(
|
||||
type: ComponentType<T>,
|
||||
...args: unknown[]
|
||||
...args: any[]
|
||||
): T {
|
||||
let component = this.getComponent(type);
|
||||
if (!component) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 事件总线接口
|
||||
|
||||
Reference in New Issue
Block a user