2022-12-08 21:14:02 +08:00
|
|
|
import { _decorator, resources, Asset } from "cc";
|
|
|
|
import Singleton from "../Base/Singleton";
|
2022-11-27 23:23:47 +08:00
|
|
|
|
|
|
|
export class ResourceManager extends Singleton {
|
|
|
|
static get Instance() {
|
2022-12-08 21:14:02 +08:00
|
|
|
return super.GetInstance<ResourceManager>();
|
2022-11-27 23:23:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loadRes<T extends Asset>(path: string, type: new (...args: any[]) => T) {
|
|
|
|
return new Promise<T>((resolve, reject) => {
|
|
|
|
resources.load(path, type, (err, res) => {
|
|
|
|
if (err) {
|
2022-12-08 21:14:02 +08:00
|
|
|
reject(err);
|
|
|
|
return;
|
2022-11-27 23:23:47 +08:00
|
|
|
}
|
2022-12-08 21:14:02 +08:00
|
|
|
resolve(res);
|
|
|
|
});
|
|
|
|
});
|
2022-11-27 23:23:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loadDir<T extends Asset>(path: string, type: new (...args: any[]) => T) {
|
|
|
|
return new Promise<T[]>((resolve, reject) => {
|
|
|
|
resources.loadDir(path, type, (err, res) => {
|
|
|
|
if (err) {
|
2022-12-08 21:14:02 +08:00
|
|
|
reject(err);
|
|
|
|
return;
|
2022-11-27 23:23:47 +08:00
|
|
|
}
|
2022-12-08 21:14:02 +08:00
|
|
|
resolve(res);
|
|
|
|
});
|
|
|
|
});
|
2022-11-27 23:23:47 +08:00
|
|
|
}
|
|
|
|
}
|