编码.默认在Unity Player中不起作用 [英] Encoding.Default not working in Unity Player

查看:86
本文介绍了编码.默认在Unity Player中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的应用程序中遇到了一个小问题,该应用程序基本上是从我的网站下载字符串和图像,现在在Unity Editor中可以正常使用,但是在我构建和运行时,它无法正确打印图像不再了!这是重要的代码

I recently went thru a small issue with my app, which basically downloads a string and an image from my website, now it works perfectly in the Unity Editor, but when I build and run, it doesn't print the image properly anymore! Here is the important code

byte[] data = sendMessage("https://mywebsite.com", values);
string ret = Encoding.Default.GetString(data);
var split = ret.Split(new string[] {"//"}, StringSplitOptions.None);
byte[] texdata = Encoding.Default.GetBytes(split[1]);
varstr = split[0];

texdata用于tex.LoadImage();并保存了varstr供以后使用,现在当我在编辑器中时,一切正常且正常,但是在构建时,图像显示大了吗? (png无效),而varstr无法正确返回.我100%肯定是编码,就像刚做完一样

texdata is used in the tex.LoadImage(); and varstr is saved for later, now it all works fine and dandy when I'm in the editor but when built, the image shows a big ? (the png is invalid) and varstr doesn't return properly. I am 100% sure it's the encoding, as when just doing

byte[] data = sendMessage("https://mywebsite.com", values);
byte[] texdata = data;

在sendMessage()仅返回图像而不返回字符串的情况下,它在构建和编辑器中均能完美运行,而且,我尝试了字符串ret = Convert.ToBase64String(data);但是然后ret.Split();返回

Where sendMessage() only returns the image and not the string, it works perfectly in build and in editor, moreso, I've tried string ret = Convert.ToBase64String(data); but then ret.Split(); returns

IndexOutOfRangeException:数组索引超出范围.

IndexOutOfRangeException: Array index is out of range.

是的,仅此而已,希望您过得愉快!

So yeah, that's pretty much it, and I hope you have a nice day!

  • PS:我的网站是php,sendMessage()完美运行

  • P.S: My website is php and sendMessage() works perfectly

推荐答案

如果该代码中存在编码问题,请查看

If it is an encoding issue within that code, look at Encoding.Default.EncodingName in the editor vs. during runtime. This will tell you if the default encodings are different.

作为一种可能的解决方案,请不要使用默认值.例如,使用 .如果您发现Unity编辑器使用的是哪种编码,则可以使用.

As a potential solution, don't use the default. For example, use Encoding.UTF8. If you find out which encoding the Unity editor is using, you can use that.

这篇关于编码.默认在Unity Player中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆