77 lines
3.2 KiB
TypeScript
77 lines
3.2 KiB
TypeScript
// @structural-rewrite-v1
|
|
import { _decorator, AudioClip, Component, Sprite, UITransform } from 'cc';
|
|
import { RuntimeAssetLoader } from './framework/runtime/RuntimeAssetLoader';
|
|
const { ccclass, property } = _decorator;
|
|
@ccclass('AssetController')
|
|
export class AssetController extends Component {
|
|
static instance: AssetController;
|
|
@property({ "type": AudioClip })
|
|
fire: AudioClip = null;
|
|
@property({ "type": AudioClip })
|
|
click: AudioClip = null;
|
|
@property({ "type": AudioClip })
|
|
win: AudioClip = null;
|
|
@property({ "type": AudioClip })
|
|
die: AudioClip = null;
|
|
@property({ "type": AudioClip })
|
|
xiao: AudioClip = null;
|
|
@property({ "type": AudioClip })
|
|
getCoin: AudioClip = null;
|
|
protected onLoad(): void {
|
|
try {
|
|
do {
|
|
switch (0 as number) {
|
|
case 1: break;
|
|
case 2: break;
|
|
default: void (AssetController["instance"] = this);
|
|
}
|
|
} while (false);
|
|
}
|
|
finally {
|
|
}
|
|
}
|
|
loadSetSprite(path: string, sprite: Sprite, preserveAspect = false): void {
|
|
const displayBounds = preserveAspect
|
|
? sprite?.node.getComponent(UITransform)?.contentSize.clone()
|
|
: null;
|
|
try {
|
|
do {
|
|
switch (0 as number) {
|
|
case 1: break;
|
|
case 2: break;
|
|
default: void (RuntimeAssetLoader["loadSpriteFrame"](`${path}/spriteFrame`)["then"]((spriteFrame) => {
|
|
try {
|
|
do {
|
|
switch (0 as number) {
|
|
case 1: break;
|
|
case 2: break;
|
|
default: if (sprite?.["isValid"]) {
|
|
void (sprite["spriteFrame"] = spriteFrame);
|
|
if (displayBounds) {
|
|
const sourceSize = spriteFrame.rect;
|
|
if (sourceSize.width > 0 && sourceSize.height > 0) {
|
|
const scale = Math.min(
|
|
displayBounds.width / sourceSize.width,
|
|
displayBounds.height / sourceSize.height,
|
|
);
|
|
sprite.node.getComponent(UITransform)?.setContentSize(
|
|
sourceSize.width * scale,
|
|
sourceSize.height * scale,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} while (false);
|
|
}
|
|
finally {
|
|
}
|
|
})["catch"]((error) => console["error"](error)));
|
|
}
|
|
} while (false);
|
|
}
|
|
finally {
|
|
}
|
|
}
|
|
}
|