Unity zip解压和压缩

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

https://github.com/needle-mirror/com.unity.sharp-zip-lib
unity 官方界面
https://docs.unity3d.com/Packages/[email protected]/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:puertsXluaTestProLibraryScriptAssembliesUnity.SharpZipLib.Utils.dll
        </HintPath>
 </Reference>

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

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

	<Compile Include="AssetsCSSrc*.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);

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>