地图系统
This commit is contained in:
@@ -23,6 +23,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Assets;
|
||||
using BaseGames.Core.Save;
|
||||
|
||||
namespace BaseGames.Localization
|
||||
@@ -197,7 +198,7 @@ namespace BaseGames.Localization
|
||||
if (dict == null)
|
||||
Debug.LogWarning(
|
||||
$"[LocalizationManager] PreloadTables:{language}/{table} 未找到," +
|
||||
$"请确认 Resources/Localization/{language}/{table}.json 存在。");
|
||||
$"请确认 Addressable 地址 'Localization/{language}/{table}' 已配置。");
|
||||
#endif
|
||||
_cache[ck] = dict;
|
||||
}
|
||||
@@ -217,20 +218,16 @@ namespace BaseGames.Localization
|
||||
var ck = new CacheKey(language, table);
|
||||
if (_cache.ContainsKey(ck)) { yield return null; continue; }
|
||||
|
||||
string path = $"Localization/{language}/{table}";
|
||||
var request = Resources.LoadAsync<TextAsset>(path);
|
||||
yield return request;
|
||||
|
||||
var asset = request.asset as TextAsset;
|
||||
var dict = asset == null ? null : ParseTableText(asset.text);
|
||||
|
||||
// 经 AssetLoader 门面加载(本地小 JSON,同步开销可忽略;分帧 yield 避免一次性卡顿)
|
||||
var dict = LoadTable(language, table);
|
||||
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
if (dict == null)
|
||||
Debug.LogWarning(
|
||||
$"[LocalizationManager] PreloadTablesAsync:{language}/{table} 未找到," +
|
||||
$"请确认 Resources/Localization/{language}/{table}.json 存在。");
|
||||
$"请确认 Addressable 地址 'Localization/{language}/{table}' 已配置。");
|
||||
#endif
|
||||
_cache[ck] = dict;
|
||||
yield return null; // 分帧:每帧加载一个表,避免一次性卡顿
|
||||
}
|
||||
|
||||
onComplete?.Invoke();
|
||||
@@ -296,8 +293,8 @@ namespace BaseGames.Localization
|
||||
private static readonly Dictionary<string, Dictionary<string, string>> s_editorPreviewCache = new();
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器工具专用:不依赖运行时服务实例,直接从 Resources 读取本地化文本。
|
||||
/// 结果缓存在静态字典中,同一编辑器会话内同一表只加载一次。
|
||||
/// 编辑器工具专用:不依赖运行时服务实例,直接用 AssetDatabase 按路径读取本地化文本
|
||||
/// (编辑器期无需初始化 Addressables)。结果缓存在静态字典中,同一编辑器会话内同一表只加载一次。
|
||||
/// 找不到时返回 null(区别于运行时的 key 回退,便于调用方判断是否显示 key)。
|
||||
/// </summary>
|
||||
public static string GetEditorPreview(string key, string table = LocalizationTable.UI,
|
||||
@@ -319,8 +316,9 @@ namespace BaseGames.Localization
|
||||
if (s_editorPreviewCache.TryGetValue(cacheKey, out var cached))
|
||||
return cached;
|
||||
|
||||
string path = $"Localization/{language}/{table}";
|
||||
var asset = Resources.Load<TextAsset>(path);
|
||||
// 编辑器按资产路径读取(与运行时 Addressable 地址对应的物理位置)
|
||||
string path = $"Assets/_Game/Data/Localization/{language}/{table}.json";
|
||||
var asset = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(path);
|
||||
var dict = asset == null ? null : ParseTableText(asset.text);
|
||||
s_editorPreviewCache[cacheKey] = dict;
|
||||
return dict;
|
||||
@@ -345,14 +343,20 @@ namespace BaseGames.Localization
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 Resources/Localization/{language}/{table}.json 加载字符串表。
|
||||
/// 返回 null 表示文件不存在。
|
||||
/// 通过 Addressables 同步加载字符串表(地址 "Localization/{language}/{table}")。
|
||||
/// 项目统一用 Addressables 管理资源,不使用 Resources。
|
||||
/// 表不存在时返回 null(先用 LoadResourceLocations 判存在,避免缺表时的错误日志刷屏)。
|
||||
/// </summary>
|
||||
private static Dictionary<string, string> LoadTable(Language language, string table)
|
||||
{
|
||||
string path = $"Localization/{language}/{table}";
|
||||
var asset = Resources.Load<TextAsset>(path);
|
||||
return asset == null ? null : ParseTableText(asset.text);
|
||||
string address = $"Localization/{language}/{table}";
|
||||
// 统一经 AssetLoader 门面:缺键安全检查 + 同步加载 + 释放
|
||||
if (!AssetLoader.Exists(address, typeof(TextAsset))) return null;
|
||||
|
||||
var (asset, handle) = AssetLoader.LoadSync<TextAsset>(address);
|
||||
var dict = asset == null ? null : ParseTableText(asset.text);
|
||||
AssetLoader.Release(handle); // 已解析为字典,释放资源句柄
|
||||
return dict;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user