Change load addressable script
This commit is contained in:
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace BrewMonster.Network
|
||||
{
|
||||
@@ -134,40 +135,39 @@ namespace BrewMonster.Network
|
||||
m_SkillDesc = new BrewMonster.CECStringTab();
|
||||
m_BuffDesc = new BrewMonster.CECStringTab();
|
||||
|
||||
//TODO: DUCK Have to remove this after moving all file to persistentDataPath
|
||||
return;
|
||||
// Load string files from StreamingAssets/configs directory
|
||||
string dataPath = Application.streamingAssetsPath + "/configs/";
|
||||
|
||||
try
|
||||
{
|
||||
// Load each string table using the actual file names from StreamingAssets/configs
|
||||
if (!m_FixedMsgs.Init(dataPath + "fixed_msg.txt", true))
|
||||
// Addressables-only loading (no StreamingAssets/configs file IO).
|
||||
// These must match the Addressables "Address" values configured in `Assets/AddressableAssetsData/...`.
|
||||
Addressables.InitializeAsync().WaitForCompletion();
|
||||
|
||||
var fixedMsgTa = Addressables.LoadAssetAsync<TextAsset>("Assets/Addressable/fixed_msg.txt").WaitForCompletion();
|
||||
if (!m_FixedMsgs.InitFromTextAsset(fixedMsgTa, true))
|
||||
{
|
||||
Debug.LogWarning("[EC_Game] Failed to load fixed_msg.txt");
|
||||
}
|
||||
|
||||
if (!m_ItemDesc.Init(dataPath + "item_desc.txt", true))
|
||||
var itemDescTa = Addressables.LoadAssetAsync<TextAsset>("Assets/Addressable/item_desc.txt").WaitForCompletion();
|
||||
if (!m_ItemDesc.InitFromTextAsset(itemDescTa, true))
|
||||
{
|
||||
Debug.LogWarning("[EC_Game] Failed to load item_desc.txt");
|
||||
}
|
||||
|
||||
if (!m_ItemExtDesc.Init(dataPath + "item_ext_desc.txt", true))
|
||||
var itemExtDescTa = Addressables.LoadAssetAsync<TextAsset>("Assets/Addressable/item_ext_desc.txt").WaitForCompletion();
|
||||
if (!m_ItemExtDesc.InitFromTextAsset(itemExtDescTa, true))
|
||||
{
|
||||
Debug.LogWarning("[EC_Game] Failed to load item_ext_desc.txt");
|
||||
}
|
||||
|
||||
if (!m_SkillDesc.Init(dataPath + "skillstr.txt", true))
|
||||
var skillStrTa = Addressables.LoadAssetAsync<TextAsset>("Assets/Addressable/skillstr.txt").WaitForCompletion();
|
||||
if (!m_SkillDesc.InitFromTextAsset(skillStrTa, true))
|
||||
{
|
||||
Debug.LogWarning("[EC_Game] Failed to load skillstr.txt");
|
||||
}
|
||||
|
||||
// Note: There's no buff_desc.txt file in the configs folder
|
||||
// You may need to create this file or use a different source for buff descriptions
|
||||
if (!m_BuffDesc.Init(dataPath + "buff_desc.txt", true))
|
||||
{
|
||||
Debug.LogWarning("[EC_Game] Failed to load buff_desc.txt - file may not exist");
|
||||
}
|
||||
// (If you add it to Addressables later, load it here.)
|
||||
|
||||
// Load item message map (template -> message id)
|
||||
LoadItemMsgMap();
|
||||
@@ -191,15 +191,18 @@ namespace BrewMonster.Network
|
||||
m_ItemMsgMap = new Dictionary<int, ItemMsgMapEntry>();
|
||||
try
|
||||
{
|
||||
string path = Application.streamingAssetsPath + "/configs/item_msg_map.txt";
|
||||
if (!File.Exists(path))
|
||||
Addressables.InitializeAsync().WaitForCompletion();
|
||||
var mapTa = Addressables.LoadAssetAsync<TextAsset>("Assets/Addressable/item_msg_map.txt").WaitForCompletion();
|
||||
if (mapTa == null || string.IsNullOrEmpty(mapTa.text))
|
||||
{
|
||||
Debug.LogWarning(
|
||||
"[EC_Game] item_msg_map.txt not found; descriptions will fall back to template IDs");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var raw in File.ReadLines(path))
|
||||
using var sr = new StringReader(mapTa.text);
|
||||
string raw;
|
||||
while ((raw = sr.ReadLine()) != null)
|
||||
{
|
||||
var line = raw.Trim();
|
||||
if (line.Length == 0) continue;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user