PrefabManager.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const DWTool = require("./DWTool");
  2. class PrefabManager {
  3. static getPrefabByPath(path, res) {
  4. let filePath = `prefabs/precedence/${path}`;
  5. let uuid = cc.loader._getResUuid(filePath, cc.Prefab, true);
  6. let result = res.filter((item) => {
  7. return item._uuid === uuid
  8. });
  9. if (result != null && result.length != undefined) {
  10. let prefab = result[0];
  11. if (prefab) {
  12. return new cc.instantiate(prefab);
  13. } else {
  14. return null;
  15. }
  16. }
  17. return null;
  18. }
  19. //明星普通头像
  20. static loadPrefab(name) {
  21. if (Global.prefabsRes) {
  22. // let prefab = this.getPrefabByPath(name,Global.prefabsRes);
  23. // sprite.spriteFrame = prefab;
  24. let p = new Promise((resolve, reject) => {
  25. let prefab = this.getPrefabByPath(name,Global.prefabsRes);
  26. if (prefab) {
  27. resolve(prefab)
  28. } else {
  29. DWTool.loadResPrefab(`./prefabs/precedence/${name}`)
  30. .then((result) => {
  31. let alert = cc.instantiate(result);
  32. resolve(alert);
  33. });
  34. }
  35. });
  36. return p;
  37. } else {
  38. let p = new Promise((resolve, reject) => {
  39. DWTool.loadResPrefab(`./prefabs/precedence/${name}`)
  40. .then((result) => {
  41. let alert = cc.instantiate(result);
  42. resolve(alert);
  43. });
  44. })
  45. return p;
  46. }
  47. }
  48. }
  49. module.exports = PrefabManager;