Exemple #1
0
        //依据记录的资源更新列表覆盖更新本地资源
        IEnumerator IUpdateAllBundles()
        {
            string strUpdateInfo = FileTool.ReadFile(RecsPathCtrl.GetIns().GetPathUpdateInfoFile(true), Encoding.UTF8, () => Log.LogAndSave("读取资源更新列表完毕"));

            MsgUICtrl.GetIns().ShowMsg("读取资源更新列表完毕", strUpdateInfo, null, true, 0.5f);

            string[] updateList = strUpdateInfo.Split('\n', '\r');
            for (int i = 0; i < updateList.Length; i++)
            {
                if (string.IsNullOrEmpty(updateList[i].Trim()))
                {
                    continue;
                }

                LoadRecsUI.GetIns().InitAndShow(string.Format("更新资源[{0}]", updateList[i]), true, i * 1f / updateList.Length * 1f);
                yield return(StartCoroutine(AssetBundleTool.DownloadAssetBundle(RecsPathCtrl.GetIns().RecsRootPathServer, updateList[i], RecsPathCtrl.GetIns().RecsRootPathLocal,
                                                                                (error) => { MsgUICtrl.GetIns().ShowMsg("更新资源失败", error, null, true, 1); },
                                                                                null
                                                                                )));

#if UNITY_EDITOR//测试
                yield return(new WaitForSeconds(0.05f));
#endif
            }
            LoadRecsUI.GetIns().InitAndShow(string.Format("更新资源完成"), true, 1);


            //刷新本地的Manifest
            //  yield return StartCoroutine(IUpdateManifestToLocal());


            yield return(null);
        }
Exemple #2
0
        //一次性从服务器将所有AssetBundle文件下载到本地缓存
        IEnumerator IDownAllBundlesFromServerToLocal()
        {
            //更新Manifest至本地
            yield return(StartCoroutine(IUpdateManifestToLocal()));

            //显示读取信息
            Log.LogAndSave("下载根数据成功");
            MsgUICtrl.GetIns().ShowMsg("下载根数据成功", "将根数据保存至本地 " + RecsPathCtrl.GetIns().GetPathManifest(true), null, true);


            //获取Manifest包含的所有的AssetBundle信息
            string[] arrAllBundles = ManifestServer.GetAllAssetBundles();

            if (arrAllBundles == null || arrAllBundles.Length == 0)
            {
                MsgUICtrl.GetIns().ShowMsg("空资源", "根数据下没有其它资源 ", null, true, 1);
                Log.LogAndSave("根数据下没有其它资源");
                yield break;
            }

            //下载所有的AssetBundle文件到本地
            for (int i = 0; i < arrAllBundles.Length; i++)
            {
                LoadRecsUI.GetIns().InitAndShow(string.Format("下载资源[{0}]", arrAllBundles[i]), true, i * 1f / arrAllBundles.Length);
                yield return(StartCoroutine(AssetBundleTool.DownloadAssetBundle(
                                                RecsPathCtrl.GetIns().RecsRootPathServer
                                                , arrAllBundles[i],
                                                RecsPathCtrl.GetIns().RecsRootPathLocal,
                                                (string str) =>
                {
                    Log.LogAndSave("下载资源失败 " + str);
                    MsgUICtrl.GetIns().ShowMsg("下载资源失败", str, null, true, 1);
                },
                                                () => LoadRecsUI.GetIns().InitAndShow(string.Format("下载资源[{0}]}", arrAllBundles[i]), true, (i + 1) * 1f / arrAllBundles.Length))));


#if UNITY_EDITOR//测试
                yield return(new WaitForSeconds(0.05f));
#endif
            }

            LoadRecsUI.GetIns().InitAndShow(string.Format("下载资源成功"), true, 1);
            yield return(new WaitForSeconds(1));

            yield return(null);
        }
Exemple #3
0
        IEnumerator ILoadAllBundles()
        {
            //--开始加载数据
            bool bWait = false;

            MsgUICtrl.GetIns().ShowMsg("开始加载数据", "加载本地数据", () => bWait = true, true, 3);
            //MsgUICtrl.GetIns().ShowMsg("开始加载数据", "加载本地数据", null, true, 3);
            Log.LogAndSave("开始加载数据");
            yield return(new WaitUntil(() => bWait));



            WWW localMan = new WWW("file://" + RecsPathCtrl.GetIns().GetPathManifest(true));

            if (localMan == null)
            {
                yield break;
            }

            yield return(localMan);

            if (!string.IsNullOrEmpty(localMan.error))
            {
                MsgUICtrl.GetIns().ShowMsg("加载资源失败", "Local Manifst丢失", null, true, 1);
                Log.LogAndSave("加载资源失败:Local Manifst丢失");
                ////下载资源
                //yield return StartCoroutine(IDownAllBundlesFromServerToLocal());

                ////加载本地资源
                //yield return StartCoroutine(ILoadAllBundles());

                yield break;
            }

            //获取本地的AssetBundlemanifest
            AssetBundle ab = localMan.assetBundle;

            if (ab == null)
            {
                MsgUICtrl.GetIns().ShowMsg("加载资源失败", "Local Manifst丢失", null, true, 1);
                Log.LogAndSave("加载资源失败:Local Manifst丢失");
                yield break;
            }

            AssetBundleManifest man = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

            ab.Unload(false);
            if (man == null)
            {
                MsgUICtrl.GetIns().ShowMsg("加载资源失败", "资源包为空", null, true, 1);
                Log.LogAndSave("加载资源失败:资源包为空");

                yield break;
            }

            recsList.Clear();
            dicRecs.Clear();
            string[] arrBundles = man.GetAllAssetBundles();
            for (int i = 0; i < arrBundles.Length; i++)
            {
                LoadRecsUI.GetIns().InitAndShow(string.Format("加载{0}成功", arrBundles[i]), true, (float)i / arrBundles.Length);
                AssetBundle tempAB = null;
                yield return(StartCoroutine(AssetBundleTool.ILoadAssetBundle(RecsPathCtrl.GetIns().RecsRootPathLocal + arrBundles[i], true,
                                                                             (error) =>
                {
                    MsgUICtrl.GetIns().ShowMsg("加载AssetBundle失败", error, null, true, 0.1f);
                    Log.LogAndSave(string.Format("加载{0}失败 ERROR:{1}", arrBundles[i], error));
                },
                                                                             (adLoad) =>
                {
                    tempAB = adLoad;
                    LoadRecsUI.GetIns().InitAndShow(string.Format("加载{0}成功", tempAB.name), true, (float)(i + 1) / arrBundles.Length);
                    Log.LogAndSave(string.Format("加载{0}成功", tempAB.name));

                    //从AssetBundle中加载所有资源后释放AssetBundle
                    //AssetBundleRequest ar = tempAB.LoadAllAssetsAsync();
                    //yield return new WaitUntil(()=>ar.isDone);

                    recsList.AddRange(tempAB.LoadAllAssets());
                    //adLoad.Unload(false);
                }
                                                                             )));
            }



            yield return(null);
        }