using System; using TMPro; using UnityEditor.Localization; using UnityEngine.Events; namespace UnityEngine.Localization.Components { /// /// Component that can be used to Localize a TMP_FontAsset asset. /// [AddComponentMenu("Localization/Asset/Localize TMPro Font Event")] public class LocalizeTMProFontEvent : LocalizedAssetEvent { private void Reset() { //Set up Unity Event automatically var target = GetComponent(); var setFontMethod = target.GetType().GetProperty("font").GetSetMethod(); var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction), target, setFontMethod) as UnityAction; 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 { } [Serializable] public class UnityEventFont : UnityEvent { } }