const DWTool = require("./DWTool"); class PrefabManager { static getPrefabByPath(path, res) { let filePath = `prefabs/precedence/${path}`; let uuid = cc.loader._getResUuid(filePath, cc.Prefab, true); let result = res.filter((item) => { return item._uuid === uuid }); if (result != null && result.length != undefined) { let prefab = result[0]; if (prefab) { return new cc.instantiate(prefab); } else { return null; } } return null; } //明星普通头像 static loadPrefab(name) { if (Global.prefabsRes) { // let prefab = this.getPrefabByPath(name,Global.prefabsRes); // sprite.spriteFrame = prefab; let p = new Promise((resolve, reject) => { let prefab = this.getPrefabByPath(name,Global.prefabsRes); if (prefab) { resolve(prefab) } else { DWTool.loadResPrefab(`./prefabs/precedence/${name}`) .then((result) => { let alert = cc.instantiate(result); resolve(alert); }); } }); return p; } else { let p = new Promise((resolve, reject) => { DWTool.loadResPrefab(`./prefabs/precedence/${name}`) .then((result) => { let alert = cc.instantiate(result); resolve(alert); }); }) return p; } } } module.exports = PrefabManager;