关于Unity WebGL GB2312编码问题

3 篇文章 0 订阅
Encoding gb2312Encoding =  Encoding.GetEncoding("GB2312");

上面的代码在Unity编辑器运行正常,但是导出到PC端运行就会出现Encoding 936 data could not be found问题,把I18N.CJK.dll和I18N.dll拷贝到工程里可以解决这个问题。
但是,在WebGL平台上面会有新的报错

NotSupportedException: This encoding is not supported. Code table is missing.
  at I18N.CJK.CodeTable..ctor (System.String name) [0x00000] in <00000000000000000000000000000000>:0 
  at I18N.CJK.DbcsConvert..ctor (System.String fileName) [0x00000] in <00000000000000000000000000000000>:0 
  at I18N.CJK.DbcsConvert..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at I18N.CJK.CP936.GetConvert () [0x00000] in <00000000000000000000000000000000>:0 
  at I18N.CJK.CP936.GetDecoder () [0x00000] in <00000000000000000000000000000000>:0 
  at I18N.CJK.CP936.GetCharCount (System.Byte[] bytes, System.Int32 index, System.Int32 count) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Text.Encoding.GetChars (System.Byte[] bytes, System.Int32 index, System.Int32 count) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Text.Encoding.GetString (System.Byte[] bytes, System.Int32 index, System.Int32 count) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Text.Encoding.GetString (System.Byte[] bytes) [0x00000] in <00000000000000000000000000000000>:0

ILSpy拉开I18N.CJK.dll源码看了一下,大概问题出在gb2312.table加载不了

namespace I18N.CJK
{
	internal sealed class CodeTable : IDisposable
	{
		private Stream stream;

		public CodeTable(string name)
		{
			//此行代码加载gb2312.table
			stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (stream != null)
			{
				return;
			}
			throw new NotSupportedException(string.Format(Strings.GetString("NotSupp_MissingCodeTable"), name));
		}

		public void Dispose()
		{
			if (stream != null)
			{
				stream.Close();
				stream = null;
			}
		}

改了改代码,但是没有解决问题
参考了一下 https://blog.csdn.net/yiyikela/article/details/45335847
最后使用了https://github.com/GuanXP/System.Text.GB2312Encoding 与yiyikela的方案没啥本质区别

2023.6.16 又发现https://github.com/GuanXP/System.Text.GB2312Encoding的方案log里中文显示???估计不适合
彻底修改一番,ILSpy拉开I18N.CJK.dll源码,改成Resources.Load,剥离代码,只留CP936,到此算是彻底解决

https://github.com/xue-fei/Unity.I18N.CJK

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地狱为王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值