init
This commit is contained in:
9
assets/scripts/utils.meta
Normal file
9
assets/scripts/utils.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "8c0af393-af1b-47f5-83aa-48f638d0156d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
27
assets/scripts/utils/BackgroundScaler.ts
Normal file
27
assets/scripts/utils/BackgroundScaler.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { _decorator, Component, UITransform, view } from 'cc';
|
||||
const { ccclass, menu, disallowMultiple } = _decorator;
|
||||
|
||||
@ccclass('BackgroundScaler')
|
||||
@menu('Nexux/BackgroundScaler')
|
||||
@disallowMultiple()
|
||||
export class BackgroundScaler extends Component {
|
||||
onLoad() {
|
||||
const bg = this.node;
|
||||
const uiTransform = bg.getComponent(UITransform);
|
||||
const bgSize = uiTransform?.contentSize;
|
||||
|
||||
if (!bgSize) {
|
||||
console.error('BackgroundScaler: bgSize is null');
|
||||
return;
|
||||
}
|
||||
|
||||
const winSize = view.getVisibleSize();
|
||||
|
||||
const scaleX = winSize.width / bgSize.width;
|
||||
const scaleY = winSize.height / bgSize.height;
|
||||
|
||||
const scale = Math.max(scaleX, scaleY);
|
||||
|
||||
bg.setScale(scale, scale);
|
||||
}
|
||||
}
|
||||
9
assets/scripts/utils/BackgroundScaler.ts.meta
Normal file
9
assets/scripts/utils/BackgroundScaler.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d33b066b-2902-4468-a658-3763de83e0bf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user