Esempio n. 1
0
    private IEnumerator CheckAssetUpdate()
    {
        #region load local update list config
        string          clientList = null;
        AssetBundleInfo bundleInfo = null;
        AssetBundleManager.Instance.LoadAssetAsync("updatelist.conf", (abInfo) =>
        {
            waiteString = GetAssetBundleText(abInfo);
            bundleInfo  = abInfo;
        });

        yield return(StartCoroutine(WaiteRequest()));

        if (null != bundleInfo)
        {
            AssetBundleManager.Instance.RemoveAssetBundle(bundleInfo);
        }
        clientList = waiteString;
        if (string.IsNullOrEmpty(clientList))
        {
            Logger.LogError("load client update list failed!!!");
            yield break;
        }
        clientResourceConfig.Initialize(clientList);
        #endregion

        #region load server update list config
        string serverList  = null;
        byte[] serverBytes = null;
        AssetBundleManager.Instance.DownloadAssetAsync(GameConstant.RemoteResourcePath + GameResourceDefine.ASSET_UPDATE_FILE, null, (abInfo) =>
        {
            waiteString = GetAssetBundleText(abInfo);
            serverBytes = abInfo.bytes;
        });
        yield return(StartCoroutine(WaiteRequest()));

        serverList = waiteString;
        #endregion

        if (!string.IsNullOrEmpty(serverList))
        {
            serverResourceConfig.Initialize(serverList);
            List <ConfResourceItem> updateList = new List <ConfResourceItem>();
            int totalSize = 0;

            if (!clientResourceConfig.resource.Equals(serverResourceConfig.resource))
            {
                for (int index = 0; index < serverResourceConfig.resource.patchLst.Count; ++index)
                {
                    var item       = serverResourceConfig.resource.patchLst[index];
                    var clientItem = clientResourceConfig.GetResourceItem(item.file);
                    if (null == clientItem || clientItem.md5 != item.md5)
                    {
                        if (Utils.FileToMd5(GameConstant.PersistentDataPath + item.file) != item.md5)
                        {
                            totalSize += item.size;
                            updateList.Add(item);
                        }
                    }
                    Logger.LogError("check resource is valid");
                }

                if (updateList.Count > 0 && totalSize > 0)
                {
                    yield return(StartCoroutine(DownloadAsset(updateList, serverBytes)));
                }
            }
        }
        yield return(StartCoroutine(PreloadNeedAsset()));
    }