UI系统优化
This commit is contained in:
59
Assets/_Game/Scripts/Localization/LanguageFontConfigSO.cs
Normal file
59
Assets/_Game/Scripts/Localization/LanguageFontConfigSO.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Localization
|
||||
{
|
||||
/// <summary>
|
||||
/// 每种语言对应的 TMP 字体配置。
|
||||
/// 创建资产:Assets/Data/Localization/FontConfig.asset
|
||||
///
|
||||
/// 用法:将此资产拖入 <see cref="BaseGames.Localization.LocalizedText"/> 的
|
||||
/// <c>Font Config</c> 字段,切换语言时 LocalizedText 将自动替换字体和材质。
|
||||
///
|
||||
/// CJK 语言通常需要单独的字体资产,无需为每个文本节点逐一指定,
|
||||
/// 只需在此 SO 中统一配置一次即可全局生效。
|
||||
/// </summary>
|
||||
[CreateAssetMenu(
|
||||
menuName = "BaseGames/Localization/Language Font Config",
|
||||
fileName = "FontConfig")]
|
||||
public class LanguageFontConfigSO : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public class FontEntry
|
||||
{
|
||||
[Tooltip("对应的语言。")]
|
||||
public Language language;
|
||||
|
||||
[Tooltip("该语言使用的 TMP 字体资产(留空表示沿用默认字体)。")]
|
||||
public TMP_FontAsset fontAsset;
|
||||
|
||||
[Tooltip("该语言字体的材质预设(留空表示使用字体默认材质)。")]
|
||||
public Material fontMaterial;
|
||||
}
|
||||
|
||||
[Tooltip("每种语言的字体映射。未列出的语言保持默认字体不变。")]
|
||||
public FontEntry[] entries = Array.Empty<FontEntry>();
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取指定语言的字体配置。
|
||||
/// 返回 false 表示该语言未配置,调用方应保持现有字体不变。
|
||||
/// </summary>
|
||||
public bool TryGetFont(Language language, out TMP_FontAsset font, out Material material)
|
||||
{
|
||||
if (entries != null)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
if (entry.language != language) continue;
|
||||
font = entry.fontAsset;
|
||||
material = entry.fontMaterial;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
font = null;
|
||||
material = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user