UI系统优化
This commit is contained in:
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
using TMPro;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Events;
|
||||
using BaseGames.Localization;
|
||||
|
||||
namespace BaseGames.World.Map
|
||||
{
|
||||
@@ -90,7 +91,8 @@ namespace BaseGames.World.Map
|
||||
{
|
||||
if (_regionNames != null)
|
||||
foreach (var e in _regionNames)
|
||||
if (e.RegionId == regionId) return e.DisplayName;
|
||||
if (e.RegionId == regionId)
|
||||
return e.GetDisplayName();
|
||||
return regionId;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +100,26 @@ namespace BaseGames.World.Map
|
||||
[Serializable]
|
||||
public struct RegionNameEntry
|
||||
{
|
||||
[Tooltip("场景/区域 ID,与 EVT_RegionChanged 事件传递的字符串匹配。")]
|
||||
public string RegionId;
|
||||
|
||||
[Tooltip("本地化 Key(如 REGION_CITY_NAME)。设置后运行时通过 LocalizationManager 自动解析。")]
|
||||
public string LocKey;
|
||||
|
||||
[Tooltip("直接显示名(LocKey 为空时使用)。建议优先配置 LocKey,仅在开发或单语言项目中直接善用。")]
|
||||
public string DisplayName;
|
||||
|
||||
/// <summary>返回最终显示名:优先读 LocKey,其次 DisplayName,最后回退到 RegionId。</summary>
|
||||
public string GetDisplayName()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(LocKey))
|
||||
{
|
||||
string localized = LocalizationManager.Get(LocKey, LocalizationTable.UI);
|
||||
// LocalizationManager 在未找到 Key 时返回 Key 本身,判断是否是真正翻译结果
|
||||
if (!string.IsNullOrEmpty(localized) && localized != LocKey)
|
||||
return localized;
|
||||
}
|
||||
return !string.IsNullOrEmpty(DisplayName) ? DisplayName : RegionId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user