unity3d 压缩文件夹和压缩文件

来源:互联网 发布:shake it of 编辑:程序博客网 时间:2024/06/04 19:50

直接开始,不扯淡

1:下载名字为《   Ionic.zip    》的压缩包,将里面的《    Ionic.Zip.dll    》放到unity3d的Plugins文件夹下。如果没有此文件夹,自己创建

2:脚本操作

using UnityEngine;
using System.Collections;
using Ionic.Zip;


public class YaSuo : MonoBehaviour {
    //路径
    string WenJianJiaPath;  //文件夹
    //string FilePath;      //文件


// Use this for initialization
void Start () {
        //设置文件夹的路径
        WenJianJiaPath = Application.dataPath + "/Sound";
        //文件路径
        //FilePath = Application.dataPath + "/Sound/New Material.mat";
        //压缩包的名字
        string FileName = "XiaoBaiYaSouFile";
        //输出
        print(FileName);
        //开始压缩
        using(ZipFile zip = new ZipFile(Application.dataPath + "/" + FileName + ".zip")){
            //设置密码
            zip.Password = "000";
            //压缩文件夹
            zip.AddDirectory(WenJianJiaPath, "Sound");
            //压缩文件
            //zip.AddFile(FilePath,"");
            //保存
            zip.Save();


            //其他方法提示
            //删除文件
            //zip.RemoveEntry();
            //解压文件
            //zip[text.text].Extract(SoundPath);
        }
}

}

 3:此脚本随便拖到一个物体上。

4:创建一个Sound的文件夹,因为脚本上面我填写的就是Sound文件夹。zip.AddDirectory(WenJianJiaPath, "Sound");

5:运行程序。



温馨提示:

如果有中文路径,请将  using(ZipFile zip = new ZipFile(Application.dataPath + "/" + FileName + ".zip")) 改成 using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))

然后将  zip.Save(); 改成  zip.Save(Application.dataPath + "/" + FileName + ".zip"); 

这样就完美的解决了发布以后中文文件夹名字变成乱码的情况啦。

0 0
原创粉丝点击