Commit 07252680 authored by 范雪寒's avatar 范雪寒

feat: 中间层完美适配

parent ba03f80e
......@@ -311,9 +311,6 @@
},
{
"__id__": 94
},
{
"__id__": 95
}
],
"_prefab": null,
......@@ -3923,32 +3920,5 @@
"_isTrimmedMode": true,
"_atlas": null,
"_id": "77Taml+DhKYLCnxnSi08Bm"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 1280,
"_originalHeight": 720,
"_id": "b8s6BwK6JGdo9khgpExHfg"
}
]
\ No newline at end of file
......@@ -80,7 +80,7 @@ cc.Class({
start() {
initAir(this);
this.reWriteAir();
this.updateWidgets();
this.updateScale();
window.courseware.getEngineInfo((dataStr) => {
const engineInfo = JSON.parse(dataStr);
......@@ -402,7 +402,7 @@ cc.Class({
window.courseware.freeAllOcMethod();
this.hideWaitingLetters();
this.updateWidgets();
this.updateScale();
callback && callback();
});
});
......@@ -425,34 +425,56 @@ cc.Class({
this.loadBundleByConf(this.bundleInfoList[this.currentBundleIndex]);
},
updateWidgets() {
this.updateScale();
this.node.getComponentsInChildren(cc.Widget).forEach((widget) => {
widget.updateAlignment();
});
},
updateScale() {
// const canvas = cc.find("Canvas");
// const canvasSize = cc.view.getCanvasSize();
console.log("updateScale");
const canvas = cc.find("Canvas");
const canvasComponent = canvas.getComponent(cc.Canvas);
const canvasSize = cc.view.getCanvasSize();
const designSize = cc.view.getDesignResolutionSize();
if (canvasComponent.fitHeight && canvasComponent.fitWidth) {
console.log("fit both");
// const designSize = cc.view.getDesignResolutionSize();
const scale = Math.max(
designSize.width / canvasSize.width,
designSize.height / canvasSize.height
);
// const scale =
// canvas.width / canvasSize.width / (canvas.height / canvasSize.height);
this.node.width = canvasSize.width;
this.node.height = canvasSize.height;
this.node.scale = scale;
// console.log("canvasSize:", canvasSize);
// console.log("designSize:", designSize);
const pos = this.node.parent.convertToNodeSpaceAR(
canvas.convertToWorldSpaceAR(cc.v2(0, 0))
);
this.node.setPosition(pos);
return;
}
// console.log({ x: canvas.x, y: canvas.y });
// console.log({ width: canvas.width, height: canvas.height });
// console.log('scale = ' + scale);
if (canvasComponent.fitHeight && !canvasComponent.fitWidth) {
console.log("fit height");
// this.node.width = canvas.width;
// this.node.height = canvas.height * scale;
const scale = designSize.height / canvasSize.height;
this.node.width = canvasSize.width;
this.node.height = canvasSize.height;
this.node.scale = scale;
this.node.x = (this.node.width * scale) / 2;
this.node.y = (this.node.height * scale) / 2;
return;
}
if (!canvasComponent.fitHeight && canvasComponent.fitWidth) {
console.log("fit width");
// this.node.x = this.node.width / 2;
// this.node.y = this.node.height / 2 - 120;
const scale = designSize.width / canvasSize.width;
this.node.width = canvasSize.width;
this.node.height = canvasSize.height;
this.node.scale = scale;
this.node.x = (this.node.width * scale) / 2;
this.node.y = (this.node.height * scale) / 2;
return;
}
},
exit() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment