31 lines
884 B
TypeScript
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();
|