Ciro Continisio
4 年前
当前提交
b53cf466
共有 9 个文件被更改,包括 114 次插入 和 102 次删除
-
4UOP1_Project/Assets/Scripts/Dialogues/DialogueDataSO.cs
-
124UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs
-
80UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs
-
8UOP1_Project/Assets/Scripts/Localization/Editor.meta
-
0/UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs
-
0/UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs.meta
-
0/UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs.meta
-
0/UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
using UnityEngine.Events; |
|||
using UnityEngine.Localization.Components; |
|||
|
|||
namespace UnityEditor.Localization.Plugins.TMPro |
|||
{ |
|||
internal static class LocalizeComponent_TMProFont |
|||
{ |
|||
[MenuItem("CONTEXT/TextMeshProUGUI/Localize String And Font")] |
|||
static void LocalizeTMProText(MenuCommand command) |
|||
{ |
|||
var target = command.context as TextMeshProUGUI; |
|||
SetupForStringLocalization(target); |
|||
SetupForFontLocalization(target); |
|||
} |
|||
|
|||
public static MonoBehaviour SetupForStringLocalization(TextMeshProUGUI target) |
|||
using TMPro; |
|||
using UnityEngine; |
|||
using UnityEngine.Events; |
|||
using UnityEngine.Localization.Components; |
|||
|
|||
namespace UnityEditor.Localization.Plugins.TMPro |
|||
{ |
|||
internal static class LocalizeComponent_TMProFont |
|||
{ |
|||
[MenuItem("CONTEXT/TextMeshProUGUI/Localize String And Font")] |
|||
static void LocalizeTMProText(MenuCommand command) |
|||
{ |
|||
var target = command.context as TextMeshProUGUI; |
|||
SetupForStringLocalization(target); |
|||
SetupForFontLocalization(target); |
|||
} |
|||
|
|||
public static MonoBehaviour SetupForStringLocalization(TextMeshProUGUI target) |
|||
if (target.GetComponent<LocalizeStringEvent>() != null) |
|||
return null; |
|||
|
|||
var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeStringEvent)) as LocalizeStringEvent; |
|||
var setStringMethod = target.GetType().GetProperty("text").GetSetMethod(); |
|||
var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<string>), target, setStringMethod) as UnityAction<string>; |
|||
Events.UnityEventTools.AddPersistentListener(comp.OnUpdateString, methodDelegate); |
|||
|
|||
const int kMatchThreshold = 5; |
|||
var foundKey = LocalizationEditorSettings.FindSimilarKey(target.text); |
|||
if (foundKey.collection != null && foundKey.matchDistance < kMatchThreshold) |
|||
{ |
|||
comp.StringReference.TableEntryReference = foundKey.entry.Id; |
|||
comp.StringReference.TableReference = foundKey.collection.TableCollectionNameReference; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static MonoBehaviour SetupForFontLocalization(TextMeshProUGUI target) |
|||
if (target.GetComponent<LocalizeStringEvent>() != null) |
|||
return null; |
|||
|
|||
var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeStringEvent)) as LocalizeStringEvent; |
|||
var setStringMethod = target.GetType().GetProperty("text").GetSetMethod(); |
|||
var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<string>), target, setStringMethod) as UnityAction<string>; |
|||
Events.UnityEventTools.AddPersistentListener(comp.OnUpdateString, methodDelegate); |
|||
|
|||
const int kMatchThreshold = 5; |
|||
var foundKey = LocalizationEditorSettings.FindSimilarKey(target.text); |
|||
if (foundKey.collection != null && foundKey.matchDistance < kMatchThreshold) |
|||
{ |
|||
comp.StringReference.TableEntryReference = foundKey.entry.Id; |
|||
comp.StringReference.TableReference = foundKey.collection.TableCollectionNameReference; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static MonoBehaviour SetupForFontLocalization(TextMeshProUGUI target) |
|||
if (target.GetComponent<LocalizeTMProFontEvent>() != null) |
|||
return null; |
|||
|
|||
var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeTMProFontEvent)) as LocalizeTMProFontEvent; |
|||
var setFontMethod = target.GetType().GetProperty("font").GetSetMethod(); |
|||
var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<TMP_FontAsset>), target, setFontMethod) as UnityAction<TMP_FontAsset>; |
|||
if (target.GetComponent<LocalizeTMProFontEvent>() != null) |
|||
return null; |
|||
|
|||
var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeTMProFontEvent)) as LocalizeTMProFontEvent; |
|||
var setFontMethod = target.GetType().GetProperty("font").GetSetMethod(); |
|||
var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<TMP_FontAsset>), target, setFontMethod) as UnityAction<TMP_FontAsset>; |
|||
var collections = LocalizationEditorSettings.GetAssetTableCollections(); |
|||
foreach (var tableCollection in collections) |
|||
{ |
|||
if (tableCollection.name == "Fonts") |
|||
{ |
|||
comp.AssetReference.TableReference = tableCollection.TableCollectionNameReference; |
|||
foreach (var entry in tableCollection.SharedData.Entries) |
|||
{ |
|||
if (entry.Key == "font") |
|||
comp.AssetReference.TableEntryReference = entry.Id; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
var collections = LocalizationEditorSettings.GetAssetTableCollections(); |
|||
foreach (var tableCollection in collections) |
|||
{ |
|||
if (tableCollection.name == "Fonts") |
|||
{ |
|||
comp.AssetReference.TableReference = tableCollection.TableCollectionNameReference; |
|||
foreach (var entry in tableCollection.SharedData.Entries) |
|||
{ |
|||
if (entry.Key == "font") |
|||
comp.AssetReference.TableEntryReference = entry.Id; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using TMPro; |
|||
using UnityEditor.Localization; |
|||
using UnityEngine.Events; |
|||
|
|||
namespace UnityEngine.Localization.Components |
|||
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() |
|||
/// <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() |
|||
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>; |
|||
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>; |
|||
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> { } |
|||
|
|||
|
|||
} |
|||
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> { } |
|||
|
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 37b07de76954f38498cb772572ea4f96 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue