浏览代码

Add feature to localization : Localize TMP font (#290)

* Localize TMP font

LocalizeTMProFontEvent.cs - Component to localize a TMP_FontAsset
LocalizeComponent_TMProFont.cs - TextmeshProUGUI context menu "Localize String And Font"

* Auto set up the Localize TMPro Font Event component
/UI
GitHub 3 年前
当前提交
7ae9d134
共有 1 个文件被更改,包括 24 次插入0 次删除
  1. 24
      UOP1_Project/Assets/Scripts/Localization/LocalizeTMProFontEvent.cs

24
UOP1_Project/Assets/Scripts/Localization/LocalizeTMProFontEvent.cs


using System;
using TMPro;
using UnityEditor.Localization;
using UnityEngine.Events;
namespace UnityEngine.Localization.Components

[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]

正在加载...
取消
保存