TH1/Unity/Assets/Scripts/TH1_DataAssetsScript/TextStylePresetDataAssets.cs
2026-05-10 17:57:15 +08:00

73 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: 自动生成
* @Description: 文本样式预设系统 - 多语言下统一的字号/行距/字间距方案
* @Date: 2026-05-10
*
* 用法说明:
* - 给每个 MultilingualTextMono 选一个 Preset 枚举None=不参与预设)
* - 在 Resources/DataAssets/TextStylePresetDataAssets.asset 里给每个 Preset 配各语言的 MultiTextConfig
* - 运行时三级 fallbackTMP 自己的 TextCfg(override) → 全局 Preset → 不动
*/
using System;
using System.Collections.Generic;
using Logic.Multilingual;
using UnityEngine;
namespace TH1_DataAssetsScript
{
/// <summary>
/// 文本样式预设。给同类 UI 文本定一套通用的多语言字号/行距方案,避免每个 prefab 单独配。
/// </summary>
public enum TextStylePreset
{
None = 0, // 不使用预设(仅用 prefab 上的 TextCfg override 或保持原值)
ButtonText, // 按钮文字
Title, // 大标题(面板顶上的标题)
BodyText, // 正文段落教程、Wiki、剧情
Tooltip, // 浮窗提示 / 小字
DialogueText, // 对话文本(角色对话、剧情独白)
}
[Serializable]
[CreateAssetMenu(fileName = "TextStylePresetDataAssets", menuName = "TH1 Game Data/Text Style Preset Data Asset")]
public class TextStylePresetDataAssets : ScriptableObject
{
public List<TextStylePresetEntry> Presets = new List<TextStylePresetEntry>();
/// <summary>
/// 取某个 Preset 在某语言下的样式。三级 fallback:
/// 1. preset 下找当前语言的 cfg
/// 2. 找不到则找该 preset 下的 EN cfg
/// 3. 还找不到返回 null
/// 注意None 也是合法的 Preset 值,作为"全局默认通用方案"参与查表,
/// 不在这里 early return让美术能配 None 这一档作为基础默认)。
/// </summary>
public MultiTextConfig GetConfig(TextStylePreset preset, MultilingualType lang)
{
foreach (var entry in Presets)
{
if (entry.Preset != preset) continue;
MultiTextConfig hit = null, fallback = null;
foreach (var cfg in entry.LangCfgs)
{
if (cfg.Type == lang) { hit = cfg; break; }
if (cfg.Type == MultilingualType.EN) fallback = cfg;
}
return hit ?? fallback;
}
return null;
}
}
/// <summary>
/// 一个 Preset 对应的所有语言配置项
/// </summary>
[Serializable]
public class TextStylePresetEntry
{
public TextStylePreset Preset;
public List<MultiTextConfig> LangCfgs = new List<MultiTextConfig>();
}
}