mirror of
https://github.com/szrpf/SceneAdapterDemo
synced 2025-10-25 00:15:55 +00:00
v1.0
This commit is contained in:
25
assets/Script/SceneAdapter.ts
Normal file
25
assets/Script/SceneAdapter.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
const { ccclass, menu } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
@menu('Comp/SceneAdapter')
|
||||
export default class SceneAdapter extends cc.Component {
|
||||
|
||||
protected onLoad() {
|
||||
this.resize();
|
||||
cc.view.setResizeCallback(this.resize.bind(this));
|
||||
}
|
||||
|
||||
private resize() {
|
||||
let node = this.node;
|
||||
if (cc.sys.isMobile) {
|
||||
node.width = cc.winSize.width;
|
||||
node.height = cc.winSize.height;
|
||||
} else {
|
||||
if (cc.winSize.width / cc.winSize.height > node.width / node.height) {
|
||||
node.scale = cc.winSize.height / node.height;
|
||||
} else {
|
||||
node.scale = cc.winSize.width / node.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
assets/Script/SceneAdapter.ts.meta
Normal file
10
assets/Script/SceneAdapter.ts.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"uuid": "e1b90feb-a217-4493-849d-9a611900d683",
|
||||
"importer": "typescript",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user