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,到此算是彻底解决