chore:代码重构
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// @structural-rewrite-v1
|
||||
import { AssetManager, Prefab, resources, SpriteFrame } from 'cc';
|
||||
/** Shared promise-based bridge for Cocos bundle and resources callbacks. */
|
||||
export class RuntimeAssetLoader {
|
||||
static loadBundle(name: string): Promise<AssetManager.Bundle> {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default: return this["request"]((complete) => (AssetManager["instance"] satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown)["loadBundle"](name, complete), `Bundle not found: ${name}`);
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
static loadBundlePrefab(bundle: AssetManager.Bundle, path: string): Promise<Prefab> {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default: return this["request"]((complete) => bundle["load"](path, Prefab, complete), `Prefab not found: ${path}`);
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
static loadResourcePrefab(path: string): Promise<Prefab> {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default: return this["request"]((complete) => resources["load"](path, Prefab, complete), `Resource prefab not found: ${path}`);
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
static loadSpriteFrame(path: string): Promise<SpriteFrame> {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default: return this["request"]((complete) => resources["load"](path, SpriteFrame, complete), `SpriteFrame not found: ${path}`);
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
private static request<T>(start: (complete: (error: Error, asset: T) => void) => void, missingMessage: string): Promise<T> {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default: return new Promise((resolve, reject) => {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default: void (start((error, asset) => {
|
||||
try {
|
||||
do {
|
||||
switch (0 as number) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
default:
|
||||
if (error || !asset) {
|
||||
void (reject(error || new Error(missingMessage)));
|
||||
return;
|
||||
}
|
||||
void (resolve(asset));
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}));
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
});
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user