这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

46 行
1.5 KiB

using System;
using TMPro;
using UnityEditor.Localization;
using UnityEngine.Events;
namespace UnityEngine.Localization.Components
{
/// <summary>
/// Component that can be used to Localize a TMP_FontAsset asset.
/// </summary>
[AddComponentMenu("Localization/Asset/Localize TMPro Font Event")]
public class LocalizeTMProFontEvent : LocalizedAssetEvent<TMP_FontAsset, LocalizedTMProFont, UnityEventFont>
{
private void Reset()
{
//Set up Unity Event automatically
var target = GetComponent<TextMeshProUGUI>();
var setFontMethod = target.GetType().GetProperty("font").GetSetMethod();
var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<TMP_FontAsset>), target, setFontMethod) as UnityAction<TMP_FontAsset>;
UnityEditor.Events.UnityEventTools.AddPersistentListener(this.OnUpdateAsset, methodDelegate);
//Set up font localize asset table automatically
var collections = LocalizationEditorSettings.GetAssetTableCollections();
foreach (var tableCollection in collections)
{
if (tableCollection.name == "Fonts")
{
this.AssetReference.TableReference = tableCollection.TableCollectionNameReference;
foreach (var entry in tableCollection.SharedData.Entries)
{
if (entry.Key == "font")
this.AssetReference.TableEntryReference = entry.Id;
}
}
}
}
}
[Serializable]
public class LocalizedTMProFont : LocalizedAsset<TMP_FontAsset> { }
[Serializable]
public class UnityEventFont : UnityEvent<TMP_FontAsset> { }
}