Ejemplo n.º 1
0
    /// <summary>
    ///   更新AssetBundle
    /// </summary>
    IEnumerator StartUpdateAssetBundle()
    {
        Debug.Log("AssetUpdater:StartUpdateAssetBundle");
        if (ErrorCode != EmErrorCode.None)
        {
            yield break;
        }

        UpdateCompleteValue(0f, 0f);

        ////载入MainManifest
        AssetBundleManifest manifest = ZTAssetBundleManager.GetInstance().MainManifest;
        //载入新的ResourcesManifest
        string file = DownLoadCommon.GetCacheFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME);
        AssetBundleManifest new_manifest = DownLoadCommon.LoadMainManifestByPath(file);

        if (new_manifest == null)
        {
            Error(EmErrorCode.LoadNewMainManifestFailed
                  , "Can't find new version MainManifest!");
            yield break;
        }

        ////获取需下载的资源列表与删除的资源的列表
        List <string> download_files = new List <string>();
        List <string> delete_files   = new List <string>();

        CompareAssetBundleDifference(ref download_files, ref delete_files
                                     , manifest, new_manifest);

        //删除已废弃的文件
        if (delete_files.Count > 0)
        {
            for (int i = 0; i < delete_files.Count; ++i)
            {
                string full_name = DownLoadCommon.GetFileFullName(delete_files[i]);
                if (File.Exists(full_name))
                {
                    File.Delete(full_name);
                    yield return(0);
                }
            }
        }

        //更新所有需下载的资源
        _ab_download = new AssetBundleDownloader(_current_ab_url);
        _ab_download.Start(DownLoadCommon.PATH, download_files);
        while (!_ab_download.IsDone)
        {
            UpdateCompleteValue(_ab_download.CompletedSize, _ab_download.TotalSize);
            yield return(0);
        }
        if (_ab_download.IsFailed)
        {
            Error(EmErrorCode.DownloadAssetBundleFailed);
            yield break;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    ///   写入下载缓存信息,用于断点续传
    /// </summary>
    void SaveDownloadCacheData()
    {
        if (CurrentState < EmState.UpdateAssetBundle)
        {
            return;
        }

        if (!Directory.Exists(DownLoadCommon.CACHE_PATH))
        {
            return;
        }

        //载入新的Manifest
        string new_manifest_name         = DownLoadCommon.GetCacheFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME);
        AssetBundleManifest new_manifest = DownLoadCommon.LoadMainManifestByPath(new_manifest_name);

        if (new_manifest == null)
        {
            return;
        }

        //先尝试读取旧的缓存信息,再保存现在已经下载的数据
        //PS:由于只有版本完整更新完才会移动Cache目录,且玩家可能多次尝试下载更新,所以必须保留旧的缓存信息
        DownloadCache cache = new DownloadCache();

        cache.Load(DownLoadCommon.DOWNLOADCACHE_FILE_PATH);
        if (_ab_download != null &&
            _ab_download.CompleteDownloads != null &&
            _ab_download.CompleteDownloads.Count > 0)
        {
            for (int i = 0; i < _ab_download.CompleteDownloads.Count; ++i)
            {
                string  assetbundle_name = _ab_download.CompleteDownloads[i];
                Hash128 hash_code        = new_manifest.GetAssetBundleHash(assetbundle_name);
                if (hash_code.isValid && !cache.Data.AssetBundles.ContainsKey(assetbundle_name))
                {
                    DownloadCacheData.AssetBundle elem = new DownloadCacheData.AssetBundle()
                    {
                        AssetBundleName = assetbundle_name,
                        Hash            = hash_code.ToString(),
                    };
                    Debug.Log(cache.Data.AssetBundles.Count + " - Cache Add:" + assetbundle_name);
                    cache.Data.AssetBundles.Add(assetbundle_name, elem);
                }
            }
        }
        if (cache.HasData())
        {
            cache.Save(DownLoadCommon.DOWNLOADCACHE_FILE_PATH);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    ///   拷贝文件并覆盖旧数据文件
    /// </summary>
    IEnumerator StartCopyCacheFile()
    {
        Debug.Log("AssetUpdater:StartCopyCacheFile");
        if (ErrorCode != EmErrorCode.None)
        {
            yield break;
        }

        string str  = DownLoadCommon.GetCacheFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME);
        string dest = DownLoadCommon.GetFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME);

        UpdateCompleteValue(1, 1);
        yield return(DownLoadCommon.StartCopyFile(str, dest));
    }
Ejemplo n.º 4
0
    IEnumerator StartUnZipLua()
    {
        Debug.Log("AssetUpdater:StartUnZipLua");
        if (ErrorCode != EmErrorCode.None)
        {
            yield break;
        }

        string path    = DownLoadCommon.GetCacheFileFullName("LuaScript.zip");
        string outPath = DownLoadCommon.HOT_LUA_PATH;

        CompressHelper.CompressTask task = CompressHelper.UnCompressAsync(path, outPath);
        while (!task.IsDone)
        {
            Debug.Log(task.Progress);
            UpdateCompleteValue(Mathf.Floor(task.Progress * 100), 100f);
            yield return(null);
        }
        Debug.Log("AssetUpdater:StartUnZipLua Delete: " + path);
        File.Delete(path);

        UpdateCompleteValue(1f, 1f);
    }