configMgr.ts 969 B

123456789101112131415161718192021222324252627282930313233
  1. const jsonNames = ['all', 'behavior', 'level', 'nest', 'map', 'path'];
  2. export class ConfigMgr {
  3. private static _inst: ConfigMgr;
  4. public static get inst(): ConfigMgr {
  5. if (this._inst == null) {
  6. this._inst = new ConfigMgr();
  7. }
  8. return this._inst;
  9. }
  10. config: cc.AssetManager.Cache = new cc.AssetManager.Cache();
  11. init(): Promise<void> {
  12. let arr = jsonNames.map(v=>{ return 'json/'+ v});
  13. return new Promise((resolve)=>{
  14. cc.resources.load(arr, cc.JsonAsset, (err, res)=>{
  15. if(res){
  16. res.forEach((v, k)=>{
  17. this.config.add(jsonNames[k], v.json);
  18. cc.assetManager.releaseAsset(v);
  19. });
  20. }
  21. resolve();
  22. })
  23. });
  24. }
  25. getCfgById(key, id){
  26. let cfg = this.config.get(key);
  27. return cfg[id];
  28. }
  29. }