文章目录
- 前言
- Ionic.Zip.Unity.dll下载
- 压缩
- 解压
前言
Unity游戏项目,上线运营后,可能要做热更,热更文件会打成AssetBundle形式,可能一次会有N个AssetBundle,这个时候,可以考虑压缩成一个zip,并设置解压密码,下载后再解压。
Ionic.Zip.Unity.dll下载
可以使用Ionic.Zip.Unity.dll
这个库进行压缩和解压。
下载地址: https://share.weiyun.com/5XZxOTD (密码:THwr)
压缩
using Ionic.Zip;using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Ionic.Zip;
using UnityEditor;public class ZipEditor
{[MenuItem("Tools/ZipTest")]public static void ZipTest(){using (ZipFile zip = new ZipFile()){zip.Password = "123456";zip.AddDirectory(Application.dataPath + "/TestDir", "./TestDir");zip.AddFile(Application.dataPath + "/Test1.txt", "./");zip.Save(Application.dataPath + "/result.zip");}AssetDatabase.Refresh();}
}
压缩后结果
解压
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Ionic.Zip;
using UnityEditor;public class ZipEditor
{[MenuItem("Tools/UnZipTest")]public static void UnZipTest(){using (ZipFile zip = new ZipFile(Application.dataPath + "/result.zip")){zip.Password = "123456";zip.ExtractAll(Application.dataPath + "/UnZip");}AssetDatabase.Refresh();}
}