33 lines
795 B
TypeScript
Raw Normal View History

2022-12-01 22:26:41 +08:00
import { _decorator, resources, Asset } from 'cc'
2022-11-27 23:23:47 +08:00
import Singleton from '../Base/Singleton'
export class ResourceManager extends Singleton {
static get Instance() {
return super.GetInstance<ResourceManager>()
}
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) {
reject(err)
return
}
resolve(res)
})
})
}
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) {
reject(err)
return
}
resolve(res)
})
})
}
}