1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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;
- }
- //prefab预制资源
- 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;
|