首页 新闻 搜索 专区 学院

Unity3d 字符串压缩 c# 字符串压缩,如何在u3d中压缩字符串

0
悬赏园豆:40 [已关闭问题] 关闭于 2013-07-28 14:23
DllNotFoundException: MonoPosixHelper
System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip)
(wrapper remoting-invoke-with-check) System.IO.Compression.DeflateStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode,bool,bool)
System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen)
System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode)
(wrapper remoting-invoke-with-check) System.IO.Compression.GZipStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode)
FileHelper.Zip (System.String tozipstr) (at Assets/Script/FileHelper.cs:88)
SaveWindow+<InsulatorSave1>c__IteratorE.MoveNext () (at Assets/Script/GUI/SaveWindow.cs:269)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
SaveWindow:Window(Int32) (at Assets/Script/GUI/SaveWindow.cs:83)
UnityEngine.GUI:CallWindowDelegate(WindowFunction, Int32, GUISkin, Int32, Single, Single, GUIStyle)
View Code

 

请教,如题,如何在U3d中压缩字符串,我如下的方法在控制台程序中正常运行,压缩3mb的文件和字符串都可以,压缩解压正常运行,但是在U3d中就:如上错误,是运行到第7行报错,说找不到dll,难道U3d真的不是完整的System.dll???

 1 if (!string.IsNullOrEmpty(toCompress))
 2         {
 3             Debug.Log("得到的待解压到字符串是:"+toCompress);
 4             byte[] inBuffer = Encoding.UTF8.GetBytes(toCompress);
 5             using (MemoryStream compressedStream = new MemoryStream())
 6             {
 7                 using (GZipStream gzip = new GZipStream(compressedStream, CompressionMode.Compress,true))
 8                 {
 9                     gzip.Write(inBuffer, 0, inBuffer.Length);
10                 }
11 
12                 compressedStream.Position = 0;
13 
14                 // store the length of the uncompressed array (inBuffer) at the first 4 bytes in outBuffer
15                 byte[] outBuffer = new byte[compressedStream.Length + 4];
16                 System.Buffer.BlockCopy(compressedStream.ToArray(), 0, outBuffer, 4, Convert.ToInt32(compressedStream.Length));
17                 System.Buffer.BlockCopy(BitConverter.GetBytes(inBuffer.Length), 0, outBuffer, 0, 4);
18 
19                 return Convert.ToBase64String(outBuffer);
20             }
21         }
22         else
23         {
24             return string.Empty;
25         }
留下的枇杷的主页 留下的枇杷 | 初学一级 | 园豆:4
提问于:2013-07-23 09:04
< >
分享
所有回答(2)
0

http://answers.unity3d.com/questions/7710/how-do-i-fix-the-monoposixhelper-reference.html 官网找,这个和你的相似问题

2012 | 园豆:19163 (专家六级) | 2013-07-23 12:37
0

U3D不是完整的mono吧,一些IO相关的特性不支持很正常。这儿有个压缩的例子,你可以参考一下:http://answers.unity3d.com/questions/17870/whats-the-best-way-to-implement-file-compression.html

天方 | 园豆:5266 (大侠五级) | 2013-07-23 22:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册