/* * @Author: 白哉 * @Description: * @Date: 2025年05月26日 星期一 11:05:13 * @Modify: */ using System; using System.Collections.Generic; using TMPro; using UnityEngine; namespace Logic.Multilingual { public enum MultilingualType { None, ZH, TDZH, EN, JP, KR, } public class MultilingualData : ScriptableObject { public List FontGroups = new List(); public List Items = new List(); public List TargetTypes = new List(); private Dictionary _itemDict; public Dictionary ItemDict => _itemDict; public string GetMultilingualStr(uint id, MultilingualType type) { if (_itemDict == null) RefreshDict(); if (_itemDict == null) return string.Empty; if (!_itemDict.TryGetValue(id, out var item)) return string.Empty; return type switch { MultilingualType.ZH => item.ZH, MultilingualType.TDZH => item.TDZH, MultilingualType.EN => item.EN, MultilingualType.JP => item.JP, MultilingualType.KR => item.KR, _ => string.Empty, }; } public TMP_FontAsset GetMultilingualFont(uint fontId, MultilingualType type) { if (fontId == 0) return null; foreach (var group in FontGroups) { if (group.FontID != fontId) continue; return type switch { MultilingualType.ZH => group.ZHFont, MultilingualType.TDZH => group.TDZHFont, MultilingualType.EN => group.ENFont, MultilingualType.JP => group.JPFont, MultilingualType.KR => group.KRFont, _ => null, }; } return null; } public uint GetFontGroupID(TMP_FontAsset font) { foreach (var group in FontGroups) { if (group.ZHFont == font) return group.FontID; } return 0; } public void RefreshDict() { if (_itemDict == null) _itemDict = new Dictionary(); if (_itemDict.Count == Items.Count) return; _itemDict.Clear(); foreach (var item in Items) _itemDict[item.ID] = item; } public MultilingualType GetSystemLanguageTargetMultilingual(MultilingualType type) { var index = (int)type - 1; if (index >= TargetTypes.Count) return type; return TargetTypes[index]; } } [Serializable] public class MultilingualItem { public uint ID; public string ZH; public string TDZH; public string EN; public string JP; public string KR; public void Refresh() { ZH = ZH.Replace("\r\n", "\n"); TDZH = TDZH.Replace("\r\n", "\n"); EN = EN.Replace("\r\n", "\n"); JP = JP.Replace("\r\n", "\n"); KR = KR.Replace("\r\n", "\n"); } } [Serializable] public class MultilingualFontGroup { public uint FontID; public TMP_FontAsset ZHFont; public TMP_FontAsset TDZHFont; public TMP_FontAsset ENFont; public TMP_FontAsset JPFont; public TMP_FontAsset KRFont; } }