JM_KA/assets/Script/Manager.ts
2022-01-02 11:16:05 +08:00

51 lines
1.6 KiB
TypeScript

const { ccclass, property } = cc._decorator;
@ccclass
export default class Manager extends cc.Component {
//#region 外調參數
@property({ type: cc.WebView })
public webview: cc.WebView = null
//#endregion
//#region Lifecycle
protected onLoad(): void {
this.webview.url = `https://karolchang.github.io/jm-expense-vue-ts/?ignore=${Date.now()}`;
this.webview.node.active = true;
cc.view.setResizeCallback(this._resize.bind(this));
this._resize();
}
private _resize(): void {
let Canvas: cc.Canvas = cc.Canvas.instance;
let rect: DOMRect = cc.game.canvas.getBoundingClientRect();
/** 判断是否是横屏 */
let landscape: boolean = false;
if (rect.width > rect.height) {
landscape = true;
}
// 根据横竖屏调整节点的位置适配等
let frameSize: cc.Size = cc.view.getFrameSize();
if (landscape) {
// 横屏
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
if (frameSize.height > frameSize.width) {
cc.view.setFrameSize(frameSize.height, frameSize.width);
}
Canvas.designResolution = cc.size(1920, 1080);
} else {
// 竖屏
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
if (frameSize.width > frameSize.height) {
cc.view.setFrameSize(frameSize.height, frameSize.width);
}
Canvas.designResolution = cc.size(1080, 1920);
}
}
//#endregion
}