123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const DWTool = require("./DWTool");
- var Promise = require('../lib/es6-promise').Promise;
- 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;
- }
- //prefab预制资源
- static loadPrefab(name) {
- if (GameGlobal.prefabsRes) {
- // let prefab = this.getPrefabByPath(name,GameGlobal.prefabsRes);
- // sprite.spriteFrame = prefab;
- let p = new Promise((resolve, reject) => {
- let prefab = this.getPrefabByPath(name,GameGlobal.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;
|