Unity zip解压和压缩

博客主要探讨了适用于Unity的C#压缩库。介绍了https://github.com/needle-mirror/com.unity.sharp-zip-lib这个库,给出官方界面及安装链接。还说明了安装后无代码提示的解决办法,以及使用时解压路径的注意事项,避免因路径问题导致错误。

c#一般用这个库 https://github.com/icsharpcode/SharpZipLib
但是他用的api太高了
有没有unity能直接用的呢?

https://github.com/needle-mirror/com.unity.sharp-zip-lib
unity 官方界面
https://docs.unity3d.com/Packages/com.unity.sharp-zip-lib@1.3/manual/index.html
unity 安装链接
https://github.com/needle-mirror/com.unity.sharp-zip-lib.git
但是安装完 你会发现没有代码提示
需要手动加一下这个
打开你项目的 Assembly-CSharp.csproj

 <Reference Include="Unity.SharpZipLib.Utils">
        <HintPath>
        	E:\puerts\XluaTestPro\Library\ScriptAssemblies\Unity.SharpZipLib.Utils.dll
        </HintPath>
 </Reference>

把包里的dll引过来就可以了

有时候你用vscode创建的类 没代码提示 别的类也找不到
你需要在 Assembly-CSharp.csproj 里把你的cs代码目录放进去 现在就有代码提示了

	<Compile Include="Assets\CSSrc\*.cs" />

也可以引入第三方包里的cs类
比如上面那个压缩类

using Unity.SharpZipLib.Utils;
StartCoroutine(this.loadZip());
IEnumerator loadZip()
{
    string fileName = "lua.zip";
    UnityWebRequest unityWebRequest = UnityWebRequest.Get(@"http://10.0.16.118:5000/" + fileName);
    yield return unityWebRequest.SendWebRequest();
    byte[] b = unityWebRequest.downloadHandler.data;
    string fileUrl = Path.Combine(Application.persistentDataPath, fileName);
    FileInfo fileInfo = new FileInfo(fileUrl);
    if (fileInfo.Exists == false)
    {
        File.WriteAllBytes(fileInfo.FullName, b);
    }
    else
    {
        string fileUr1l = Path.Combine(Application.persistentDataPath, "luatxt/");
        ZipUtility.UncompressFromZip(fileInfo.FullName, null, fileUr1l);
    }
}

切记一点 不要让解压路径就是zip的路径 比如zip在a包下 解压路径也是a 就不行
因为ZipUtility会先删除该路径

public static void UncompressFromZip(string archivePath, string password, string outFolder) {
		if (Directory.Exists(outFolder))  {
		    Directory.Delete(outFolder,true);
		}
		Directory.CreateDirectory(outFolder);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值