Change load addressable script

This commit is contained in:
HungDK
2025-12-26 10:10:17 +07:00
parent dd3134971d
commit ce2d81a43f
2 changed files with 62 additions and 17 deletions
+42
View File
@@ -18,6 +18,48 @@ namespace BrewMonster
public CECStringTab() { }
~CECStringTab() { Release(); }
/// <summary>
/// Initialize the table directly from a Unity TextAsset (e.g. loaded via Addressables).
/// </summary>
public bool InitFromTextAsset(TextAsset textAsset, bool bUnicode)
{
Release();
m_bUnicode = bUnicode;
try
{
if (textAsset == null)
{
Debug.LogError("[CECStringTab] InitFromTextAsset failed: textAsset is null");
return false;
}
bool ok;
if (bUnicode)
{
// Unity TextAsset.text is already UTF-8 decoded.
using var sr = new StringReader(textAsset.text);
ok = ParseIntoDict(sr, isWide: true);
}
else
{
// ANSI tables are in CP936 in original PW; keep using CP936 decoder.
string content = ByteToStringUtils.ByteArrayToCP936String(textAsset.bytes);
using var sr = new StringReader(content);
ok = ParseIntoDict(sr, isWide: false);
}
m_bInit = ok;
return ok;
}
catch (Exception e)
{
Debug.LogError($"[CECStringTab] InitFromTextAsset failed: {e}");
Release();
return false;
}
}
public bool Init(string szFile, bool bUnicode)
{
Release();