dd
This commit is contained in:
37
assets/script/game/manager/SpineManager.ts
Normal file
37
assets/script/game/manager/SpineManager.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Prefab, resources } from 'cc';
|
||||
import { GameConstants } from '../common/Constants';
|
||||
|
||||
export class SpineManager {
|
||||
private _cache: Map<string, Prefab> = new Map();
|
||||
|
||||
async load(spinePath: string): Promise<Prefab> {
|
||||
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<Prefab> {
|
||||
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<Prefab> {
|
||||
const path = `${GameConstants.SPINE.HERO}/${name}`;
|
||||
return this.load(path);
|
||||
}
|
||||
}
|
||||
9
assets/script/game/manager/SpineManager.ts.meta
Normal file
9
assets/script/game/manager/SpineManager.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "10e51fd3-8d01-4030-80a3-f98466d8c017",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user