Exemplo n.º 1
0
        protected IEnumerator UpdateAssetFromUrl(CUpdateList needUpdateLst, string downloadUrl)
        {
            updateNum     = 0;
            needUpdateNum = needUpdateLst.Count();
            string savePath, downloadPath, saveDir;

            base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_START);
            foreach (CUpdateListField field in needUpdateLst)
            {
                downloadPath = downloadUrl + field.Path;
                savePath     = CEnv.AssetPath + field.Path;

                saveDir = savePath.Substring(0, savePath.LastIndexOf('/'));

                updateNum++;
                base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_ACTION);

                using (UnityWebRequest request = UnityWebRequest.Get(downloadPath))
                {
                    yield return(request.Send());

                    if (request.isError || request.responseCode != 200)
                    {
                        base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_FAILD);
                        yield break;
                    }
                    CDirectory.CreateDir(saveDir);
                    CFile.Cover(savePath, request.downloadHandler.data, 0, request.downloadHandler.data.Length);
                }
            }

            base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_END);
        }