kunpolibrary/src/ui/ComponentExtendHelper.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-20 11:27:28 +08:00
/**
* @Author: Gongxh
* @Date: 2024-12-26
* @Description:
*/
import { UIObjectFactory } from "fairygui-cc";
import { debug } from "../tool/log";
import { PropsHelper } from "./PropsHelper";
import { _uidecorator } from "./UIDecorator";
export class ComponentExtendHelper {
public static register(): void {
for (const { ctor, res } of _uidecorator.getComponentMaps().values()) {
debug(`自定义组件注册 组件名:${res.name} 包名:${res.pkg}`);
this.registerComponent(ctor, res.pkg, res.name);
}
}
/**
*
* @param info
*/
private static registerComponent(ctor: any, pkg: string, name: string): void {
// 自定义组件扩展
const onConstruct = function (this: any): void {
PropsHelper.serializeProps(this, pkg);
this.onInit && this.onInit();
};
ctor.prototype.onConstruct = onConstruct;
// 自定义组件扩展
UIObjectFactory.setExtension(`ui://${pkg}/${name}`, ctor);
}
}