/**
 * 资源管理类
 */ export default class Res { /**
     * 资源缓存
     */ private static _cacheMap : Map < string , cc . Asset > = new Map ( ) ; param url public static getLoaded ( url ) { let asset = this . _cacheMap . get ( url ) ; if ( asset === undefined ) { cc . error ( `[Res.getLoaded] error: 资源未加载` ) ; return null ; } return asset ; } param url param type public static async load ( url , type ) { let asset = this . _cacheMap . get ( url ) ; if ( asset ) { return asset ; } return await new Promise ( ( resolve , reject ) => { cc . loader . loadRes ( url , type , ( error , resource ) => { if ( error ) { cc . error ( `[Res.load] error: ${ error }` ) ; resolve ( null ) ; } else { this . _cacheMap . set ( url , resource ) ; resolve ( resource ) ; } } ) ; } ) ; } param url param type public static async loadDir ( url , type ) { return await new Promise ( ( resolve , reject ) => { cc . loader . loadResDir ( url , type , ( error , resource , urls ) => { if ( error ) { cc . error ( `[Res.loadDir] error: ${ error }` ) ; resolve ( [ ] ) ; } else { urls . forEach ( ( v , i ) => { this . _cacheMap . set ( v , resource [ i ] ) ; } ) ; resolve ( resource ) ; } } ) ; } ) ; } }