import { Prefab, resources } from 'cc'; import { GameConstants } from '../common/Constants'; export class SpineManager { private _cache: Map = new Map(); async load(spinePath: string): Promise { if (this._cache.has(spinePath)) { return this._cache.get(spinePath)!; } const prefab = await this._load(spinePath); this._cache.set(spinePath, prefab); return prefab; } private _load(path: string): Promise { return new Promise((resolve, reject) => { resources.load(path, Prefab, (err, prefab) => { err ? reject(err) : resolve(prefab); }); }); } release(spinePath: string) { if (this._cache.has(spinePath)) { resources.release(spinePath); this._cache.delete(spinePath); } } // 加载英雄资源 async loadHero(name: string): Promise { const path = `${GameConstants.SPINE.HERO}/${name}`; return this.load(path); } }