79 lines
2.8 KiB
JavaScript
79 lines
2.8 KiB
JavaScript
System.register(["cc"], function (_export, _context) {
|
|
"use strict";
|
|
|
|
var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, ResolutionPolicy, screen, view, _dec, _class, _crd, ccclass, property, UIAdapt;
|
|
|
|
return {
|
|
setters: [function (_cc) {
|
|
_cclegacy = _cc.cclegacy;
|
|
__checkObsolete__ = _cc.__checkObsolete__;
|
|
__checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
|
|
_decorator = _cc._decorator;
|
|
Component = _cc.Component;
|
|
ResolutionPolicy = _cc.ResolutionPolicy;
|
|
screen = _cc.screen;
|
|
view = _cc.view;
|
|
}],
|
|
execute: function () {
|
|
_crd = true;
|
|
|
|
_cclegacy._RF.push({}, "70cb2qzULxEf5iEFS/WMT/U", "UIAdapt", undefined);
|
|
|
|
__checkObsolete__(['_decorator', 'Component', 'Node', 'ResolutionPolicy', 'screen', 'Screen', 'view']);
|
|
|
|
({
|
|
ccclass,
|
|
property
|
|
} = _decorator);
|
|
|
|
_export("UIAdapt", UIAdapt = (_dec = ccclass('UIAdapt'), _dec(_class = class UIAdapt extends Component {
|
|
start() {
|
|
screen.on('window-resize', this.adaptScreenSize, this);
|
|
this.adaptScreenSize();
|
|
var self = this;
|
|
this.scheduleOnce(() => {
|
|
self.adaptScreenSize();
|
|
}, 0.1);
|
|
}
|
|
|
|
adaptScreenSize() {
|
|
var screenWidth = view.getViewportRect().width;
|
|
var screenHeight = view.getViewportRect().height; // let screenWidth = view.getVisibleSize().width;
|
|
// let screenHeight = view.getVisibleSize().height;
|
|
|
|
var screenRatio = screenHeight / screenWidth;
|
|
console.log("修改屏幕分辨率", screenRatio, view.getViewportRect(), view);
|
|
|
|
if (screenRatio > 18 / 9) {
|
|
// 适配屏幕高度
|
|
console.log("修改屏幕分辨率", "适配高度");
|
|
var designWidth = 1080;
|
|
var designHeight = screenHeight * (designWidth / screenWidth);
|
|
view.setDesignResolutionSize(designWidth, designHeight, ResolutionPolicy.FIXED_WIDTH);
|
|
} else if (screenRatio > 16 / 9) {
|
|
// 适配屏幕宽度
|
|
console.log("修改屏幕分辨率", "适配屏幕宽度");
|
|
var _designHeight = 1920;
|
|
|
|
var _designWidth = screenWidth * (_designHeight / screenHeight);
|
|
|
|
view.setDesignResolutionSize(_designWidth, _designHeight, ResolutionPolicy.FIXED_HEIGHT);
|
|
} else {
|
|
console.log("修改屏幕分辨率", "适配屏幕宽高");
|
|
var _designWidth2 = 1080;
|
|
|
|
var _designHeight2 = screenHeight * (_designWidth2 / screenWidth);
|
|
|
|
view.setDesignResolutionSize(_designWidth2, _designHeight2, ResolutionPolicy.EXACT_FIT);
|
|
}
|
|
}
|
|
|
|
}) || _class));
|
|
|
|
_cclegacy._RF.pop();
|
|
|
|
_crd = false;
|
|
}
|
|
};
|
|
});
|
|
//# sourceMappingURL=f345eef45e7020c7d073878c9c5b26e302d1813f.js.map
|