暂时增加初版编辑器及时预览多语言切换
This commit is contained in:
parent
6061b51dbd
commit
5084130abe
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using AlicizaX.Localization;
|
using AlicizaX.Localization;
|
||||||
using AlicizaX.Localization.Editor;
|
using AlicizaX.Localization.Editor;
|
||||||
|
using TMPro;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
@ -172,6 +173,7 @@ namespace UnityEngine.UI
|
|||||||
localizationID.intValue = 0;
|
localizationID.intValue = 0;
|
||||||
m_localizationKey.stringValue = string.Empty;
|
m_localizationKey.stringValue = string.Empty;
|
||||||
selectedSelectionIndex = 0;
|
selectedSelectionIndex = 0;
|
||||||
|
(target as TextMeshProUGUI).text = string.Empty;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -186,7 +188,6 @@ namespace UnityEngine.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
53
Runtime/UXComponent/Text/LocalizationRefreshHelper.cs
Normal file
53
Runtime/UXComponent/Text/LocalizationRefreshHelper.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AlicizaX.Localization;
|
||||||
|
using AlicizaX.Localization.Runtime;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
internal static class LocalizationRefreshHelper
|
||||||
|
{
|
||||||
|
private static Dictionary<string, string> previewLabelDic = new();
|
||||||
|
|
||||||
|
internal static string GetPreviewLabel(string key)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
if (previewLabelDic.ContainsKey(key))
|
||||||
|
{
|
||||||
|
return previewLabelDic[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Init()
|
||||||
|
{
|
||||||
|
previewLabelDic.Clear();
|
||||||
|
List<GameLocaizationTable> allTables = new();
|
||||||
|
string[] guids = AssetDatabase.FindAssets("t:GameLocaizationTable");
|
||||||
|
foreach (string guid in guids)
|
||||||
|
{
|
||||||
|
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
GameLocaizationTable table = AssetDatabase.LoadAssetAtPath<GameLocaizationTable>(assetPath);
|
||||||
|
if (table != null)
|
||||||
|
{
|
||||||
|
allTables.Add(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string language = EditorPrefs.GetString(LocalizationComponent.PrefsKey, "None");
|
||||||
|
var localizationLanguage = allTables.Select(e => e.Languages.Find(t => t.LanguageName == language)).ToList();
|
||||||
|
foreach (var localization in localizationLanguage)
|
||||||
|
{
|
||||||
|
foreach (var item in localization.Strings)
|
||||||
|
{
|
||||||
|
previewLabelDic.TryAdd(item.Key, item.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 169b0bd7883944ed897310ddf0085517
|
||||||
|
timeCreated: 1765358242
|
||||||
@ -9,6 +9,13 @@ namespace UnityEngine.UI
|
|||||||
[SerializeField] private int m_localizationID;
|
[SerializeField] private int m_localizationID;
|
||||||
[SerializeField] private string m_localizationKey = "";
|
[SerializeField] private string m_localizationKey = "";
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
protected override void OnValidate()
|
||||||
|
{
|
||||||
|
base.OnValidate();
|
||||||
|
if (Application.isEditor) text = LocalizationRefreshHelper.GetPreviewLabel(m_localizationKey);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
protected override void Start()
|
protected override void Start()
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user