pubgv3/assets/scripts/UI/UIManger.ts
zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

31 lines
884 B
TypeScript

import { UIBase } from "./UIBase";
const { ccclass, property } = cc._decorator;
@ccclass
export class UIManger extends cc.Component {
getMainNode() {
return cc.find("Canvas");
}
async showUI(prefabPath, data: any) {
var node = new cc.Node();
if (typeof prefabPath == "string") {
// path
cc.loader.loadRes(prefabPath, cc.Prefab, (err, res) => {
node = cc.instantiate(res);
this.getMainNode().addChild(node);
if (data) node.getComponent(UIBase).init(data);
});
} else {
// prefab
node = cc.instantiate(prefabPath);
this.getMainNode().addChild(node);
if (data) node.getComponent(UIBase).init(data);
}
return node
}
}
export const uimanger = new UIManger();