加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
App.ts 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
import { Canvas, director, game, Layers, Node, UITransform, v3, view } from "cc";
import { PopupManager } from "./popup/manager/PopupManager";
export class App {
private static _instance: App | null = null;
public static get instance() {
if (null == this._instance) {
this._instance = new App();
}
return this._instance;
}
private _root: Node = null!;
get root() {
if (null == this._root) {
this.init();
}
return this._root;
}
init() {
if (null != this._root) {
console.warn('已经初始化了');
return;
}
this._root = new Node('Root');
this._root.layer = Layers.Enum.UI_2D;
this._root.addComponent(Canvas);
director.getScene()?.addChild(this._root);
game.addPersistRootNode(this._root);
let size = view.getVisibleSize();
let transform = this._root.addComponent(UITransform);
transform.contentSize = size;
this._root.position = v3(size.width / 2, size.height / 2, 0);
PopupManager.instance.init();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化