在Unity3d中使用GZip來壓縮傳輸資料
阿新 • • 發佈:2018-12-30
因為Unity中的.net支援是有限制的,所以C#自帶的GZip的壓縮方法不能夠使用。
可以到下面網址去下載一個專門的dll來處理資料的GZip壓縮:
將下載的dll檔案引入到工程中。
using ICSharpCode.SharpZipLib; using ICSharpCode.SharpZipLib.GZip;
GZipInputStream gZipInputStream = new GZipInputStream(new MemoryStream(www.bytes)); MemoryStream outStream = new MemoryStream(); try { int count = 0; byte[] data = new byte[256]; while ((count = gZipInputStream.Read(data, 0, data.Length)) != 0) { outStream.Write(data, 0, count); } } catch (Exception ex) { throw new Exception("GZipcompress error:" + ex.Message); } outStream.ToArray();