133 lines
3.6 KiB
C#
133 lines
3.6 KiB
C#
/*
|
|
* @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<MultilingualFontGroup> FontGroups = new List<MultilingualFontGroup>();
|
|
public List<MultilingualItem> Items = new List<MultilingualItem>();
|
|
public List<MultilingualType> TargetTypes = new List<MultilingualType>();
|
|
private Dictionary<uint, MultilingualItem> _itemDict;
|
|
public Dictionary<uint, MultilingualItem> 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<uint, MultilingualItem>();
|
|
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;
|
|
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;
|
|
}
|
|
} |