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AC;QACpE,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACpD,IAAI,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,IAAI,EAAE;YACN,OAAO,IAAI,CAAC;SACf;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;SAC/C;IACL,CAAC;IATqB,yBAAgB,mBASrC,CAAA;IAED,GAAG;AACP,CAAC,EA9EgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QA8ExB","file":"","sourceRoot":"/","sourcesContent":["export namespace ResUtils {\n    export async function loadRes<T extends cc.Asset>(resource: string, type: new () => T, maxTryCount = 3): Promise<T> {\n        return new Promise((resolve, reject) => {\n            let tryCount = 0;\n            function loadFunc() {\n                tryCount++;\n                cc.resources.load(resource, type as any, (err: Error, res: any) => {\n                    if (err) {\n                        if (tryCount < maxTryCount) {\n                            setTimeout(() => {\n                                loadFunc();\n                            }, 500);\n                        } else {\n                            reject(err);\n                        }\n                    } else {\n                        if (res.json) {\n                            resolve(res.json);\n                        } else if (res.text) {\n                            resolve(res.text);\n                        } else {\n                            resolve(res);\n                        }\n                    }\n                });\n            }\n            loadFunc();\n        });\n    }\n\n    //动态加载图片的方法\n    export async function loadOnlineImg(container: cc.Sprite, url: string): Promise<any> {\n        return new Promise<any>((resolve, reject) => {\n            cc.assetManager.loadRemote(url, function (err, texture) {\n                if (err) {\n                    reject(err)\n                } else {\n                    var sprite = new cc.SpriteFrame(texture);\n                    container.spriteFrame = sprite;\n                    resolve()\n                }\n            });\n\n        })\n    }\n\n    /**释放资源 */\n    export function releaseRes(resource: string) {\n        cc.resources.release(resource)\n    }\n    /**批量释放资源 */\n    export function releaseResArray(resources: string[]) {\n        for (let i = 0; i < resources.length; i++) {\n            cc.resources.release(resources[i])\n        }\n    }\n\n    export function releaseAsset(asset: cc.Asset) {\n        cc.assetManager.releaseAsset(asset)\n    }\n\n    export function releaseAssetArray(assets: cc.Asset[]) {\n        assets.forEach((asset) => cc.assetManager.releaseAsset(asset));\n    }\n\n    /**加载预制体并实例化node */\n    export async function createWithPrefab(resource: string): Promise<cc.Node> {\n        let prefab = await ResUtils.loadRes<cc.Prefab>(resource, cc.Prefab);\n        if (!prefab) throw new Error(\"Load prefab failed!\");\n        let node = cc.instantiate(prefab);\n        if (node) {\n            return node;\n        } else {\n            throw new Error(\"Instantiate node failed!\");\n        }\n    }\n\n    //检\n}"]}