예제 #1
0
        public string GetHost()
        {
            var pip = _context.GetPIPLogic();

            if (pip == null)
            {
                return(null);
            }

            return(pip.GetHost());
        }
예제 #2
0
        private IEnumerator DownloadResource()
        {
            var pip = _context.GetPIPLogic();

            if (pip.IsTest())
            {
                SetDownloadResourceResult(DownloadResourceResult.Ok, "");
                yield break;
            }
            var data = pip.GetPIPData();

            if (data == null)
            {
                SetDownloadResourceResult(DownloadResourceResult.Error, string.Format(
                                              "获取下载资源失败,请重新登陆\n【错误码{0}】)", NetworkStateErrorCode.DownloadResourcesFailCode));
                yield break;
            }

            if (data.Assets != null && data.Assets.Length > 0)
            {
                var downloadAssetBundleInfo = new DownloadAssetBundleInfo();
                downloadAssetBundleInfo.LoadType      = DownloadAssetBundleInfo.DownloadType.Download;
                downloadAssetBundleInfo.TotalCount    = data.Assets.Length;
                downloadAssetBundleInfo.CompleteCount = 0;

                foreach (var asset in data.Assets)
                {
                    if (asset == null)
                    {
                        continue;
                    }

                    //已下载过相同版本
                    if (GetLastAssetVersion(asset.Asset) != null &&
                        GetLastAssetVersion(asset.Asset).Version == asset.Version)
                    {
                        continue;
                    }

                    _downloadAssetBundleInfo.Write(downloadAssetBundleInfo, Time.time);

                    var req = UnityWebRequest.GetAssetBundle(asset.Url, (uint)asset.Version, (uint)0);

                    req.SendWebRequest();

                    while (!req.isDone)
                    {
                        yield return(null);
                    }

                    if (req.isNetworkError || req.isHttpError)
                    {
                        MyLog.ErrorWithFrame(name, asset.Url + " download  fail ");
                        SetDownloadResourceResult(DownloadResourceResult.Error, string.Format(
                                                      "下载资源失败,请重新登陆\n【错误码{0}】)", NetworkStateErrorCode.DownloadResourcesFailCode));

                        yield break;
                    }

                    try
                    {
                        var assetJson = JsonUtility.ToJson(asset);
                        PrefsUtil.SetString(asset.Asset, assetJson);
                        PrefsUtil.Flush();

                        downloadAssetBundleInfo.CompleteCount++;

                        //只卸载没有被cache的临时的assetbundle
                        if (!HasCached(asset.Asset))
                        {
                            var assetBundle = DownloadHandlerAssetBundle.GetContent(req);
                            if (assetBundle)
                            {
                                assetBundle.Unload(false);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyLog.ErrorWithFrame(name, asset.Url + " download  fail with error :" + e);
                        continue;
                    }
                }
            }

            yield return(null);

            _downloadAssetBundleInfo.ClearAndInvalidate(Time.time);
            SetDownloadResourceResult(DownloadResourceResult.Ok, "");
            MyLog.InfoWithFrame(name,
                                " download all resource succ  >>>>>>>>>>>>>>>>> UnloadAllAssetBundles >>>>>>>>>>>");
        }
예제 #3
0
 public IPIPLogic GetPIPLogic()
 {
     return(_context.GetPIPLogic());
 }