123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using ThirdParty.DownloadSystem;
- using UnityEngine;
- public class GameZip
- {
- private UnZipThreadPool _unZipThreadPool;
- private string md5Value;
- public GameStart GameStart;
- private System.Action callBack;
- private string streamingPath;
- private GameStartUIPanel _gameStartUIPanel;
- public void Start(GameStartUIPanel gameStartUIPanel,GameStart gameStart, System.Action callBack)
- {
- this.GameStart = gameStart;
- this.callBack = callBack;
- _gameStartUIPanel = gameStartUIPanel;
- streamingPath = Application.streamingAssetsPath;
- #if UNITY_IPHONE
- streamingPath = "file://"+streamingPath;
- #endif
- LoadMd5();
- }
- private void LoadMd5()
- {
- string md5 = UnityEngine.PlayerPrefs.GetString("assetMD5", "");
- Debug.Log(" Application.version" + Application.version);
- if (!md5.Equals(Application.version)) //需要解压文件
- {
- Debug.Log(Application.persistentDataPath);
- GameStart.StartCoroutine(DowFile());
- }
- else
- {
- Finish();
- }
- }
- private IEnumerator DowFile()
- {
- _gameStartUIPanel.SetMassge("转移文件");
- string url = streamingPath + "/assetBundle.zip";
- string dowFinle = Application.persistentDataPath + "/assetBundle.zip";
- AddLoad("转移解压文件");
- DownloadFileData downloadFileData = new DownloadFileData();
- downloadFileData.remoteUrl = url;
- downloadFileData.localPath = dowFinle;
- DownloadHander downloadHander = FileDownloadSystem.Instance.DownloadFile(downloadFileData);
- while (!downloadHander.isFinish)
- {
- yield return new WaitForSeconds(1);
- }
- if (!File.Exists(dowFinle))
- {
- Finish();
- yield break;
- }
- string unzipPath = Application.persistentDataPath + "/Bundle";
- _unZipThreadPool = new UnZipThreadPool();
- AddLoad("开始解压" + unzipPath);
- _gameStartUIPanel.SetMassge("开始解压,解压过程中不消耗流量");
- _unZipThreadPool.InitUnZip(dowFinle, unzipPath);
- SliderData sliderData = new SliderData();
- sliderData.maxValue = _unZipThreadPool.maxSize;
- sliderData.CcurrValue = delegate { return sliderData.maxValue - _unZipThreadPool.CurrCount(); };
- _gameStartUIPanel.SetSlider(sliderData);
- while (!_unZipThreadPool.isEnd)
- {
- yield return new WaitForSeconds(1);
- }
- _gameStartUIPanel.ClearSlider();
- _gameStartUIPanel.SetMassge("解压完成");
- AddLoad("解压完成");
- _unZipThreadPool.Cloas();
- UnityEngine.PlayerPrefs.SetString("assetMD5", Application.version);
- Finish();
- }
- private void Finish()
- {
- // LoadDll.StartDllLoad();
- callBack?.Invoke();
- }
- private void Update()
- {
- FileDownloadSystem.Instance.Update();
- }
- public void AddLoad(string message)
- {
- }
- }
|