• 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/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>
    
    • 1
    • 2
    • 3
    • 4
    • 5

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

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

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

    也可以引入第三方包里的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);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    切记一点 不要让解压路径就是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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    CXL崛起:2024启航,2025年开启新时代
    OA办公软件篇(三)—审批流
    条码工具 Dynamic Web TWAIN HTML5 版本的工作原理
    【PAT甲级】1073 Scientific Notation
    理论修炼---View事件分发的快速理解
    每日一博 - CRUD system VS Event sourcing design
    springboot整合MeiliSearch轻量级搜索引擎
    html+css+js贪吃蛇游戏
    微信小程序入门
    交换机堆叠与集群
  • 原文地址:https://blog.csdn.net/qq_38913715/article/details/127569160