Story流程+本地化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.Diagnostics;
|
||||
using Ichni.Localization;
|
||||
using Ichni.Menu.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -410,50 +410,26 @@ namespace Ichni.Story.UI
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string localizedText = LocalizationSettings.StringDatabase.GetLocalizedString(localizationTable, labelKey);
|
||||
return string.IsNullOrEmpty(localizedText) ? labelKey : localizedText;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogWarning($"[StoryTimeline] 无法本地化 Label Key '{labelKey}',将回退显示 Key。{exception.Message}");
|
||||
return labelKey;
|
||||
}
|
||||
return LocalizationTextService.Resolve(localizationTable, labelKey, labelKey);
|
||||
}
|
||||
|
||||
private async void OnSelectedLocaleChanged(Locale newLocale)
|
||||
private async void OnSelectedLocaleChanged(Locale _)
|
||||
{
|
||||
BuildHangTracer.Log("TIMELINE_EVENT", $"[OnSelectedLocaleChanged] 收到语言切换通知: newLocale={(newLocale != null ? newLocale.Identifier.Code : "null")},_markers.Count={_markers.Count}");
|
||||
|
||||
foreach (RuntimeMarker marker in _markers)
|
||||
{
|
||||
if (string.IsNullOrEmpty(marker.definition.labelKey)) continue;
|
||||
|
||||
try
|
||||
string localizedLabel = await LocalizationTextService.ResolveAsync(
|
||||
localizationTable,
|
||||
marker.definition.labelKey,
|
||||
marker.definition.labelKey);
|
||||
|
||||
// 异步等待结束后,防范对象在此期间被销毁。
|
||||
if (marker.view != null)
|
||||
{
|
||||
BuildHangTracer.Log("TIMELINE_EVENT", $"[OnSelectedLocaleChanged] 开始异步获取 Key '{marker.definition.labelKey}' 的本地化文本...");
|
||||
var handle = LocalizationSettings.StringDatabase.GetLocalizedStringAsync(localizationTable, marker.definition.labelKey);
|
||||
while (!handle.IsDone)
|
||||
{
|
||||
await System.Threading.Tasks.Task.Yield();
|
||||
}
|
||||
BuildHangTracer.Log("TIMELINE_EVENT", $"[OnSelectedLocaleChanged] 获取 Key '{marker.definition.labelKey}' 完成!Result='{handle.Result}'");
|
||||
|
||||
// 异步等待结束后,防范对象在此期间被销毁
|
||||
if (marker.view != null)
|
||||
{
|
||||
marker.view.SetLabel(string.IsNullOrEmpty(handle.Result) ? marker.definition.labelKey : handle.Result);
|
||||
}
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
BuildHangTracer.Log("TIMELINE_EVENT", $"[OnSelectedLocaleChanged] 异常: {exception.Message}");
|
||||
Debug.LogWarning($"[StoryTimeline] 无法本地化 Label Key '{marker.definition.labelKey}'。{exception.Message}");
|
||||
if (marker.view != null) marker.view.SetLabel(marker.definition.labelKey);
|
||||
marker.view.SetLabel(localizedLabel);
|
||||
}
|
||||
}
|
||||
BuildHangTracer.Log("TIMELINE_EVENT", "[OnSelectedLocaleChanged] 全部 Marker 更新完成。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user