浏览代码

Fix to Editor scripts blocking the build process

/UI
Ciro Continisio 3 年前
当前提交
b53cf466
共有 9 个文件被更改,包括 114 次插入102 次删除
  1. 4
      UOP1_Project/Assets/Scripts/Dialogues/DialogueDataSO.cs
  2. 124
      UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs
  3. 80
      UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs
  4. 8
      UOP1_Project/Assets/Scripts/Localization/Editor.meta
  5. 0
      /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs
  6. 0
      /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs.meta
  7. 0
      /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs.meta
  8. 0
      /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs

4
UOP1_Project/Assets/Scripts/Dialogues/DialogueDataSO.cs


public List<Choice> Choices => _choices;
public DialogueType DialogueType => _dialogueType;
#if UNITY_EDITOR
//TODO: Add support for branching conversations
// Maybe add 2 (or more) special line slots which represent a choice in a conversation
// Each line would also have an event associated, or another Dialogue

}
}
#endif
[Serializable]
public class Choice

124
UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.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;
}
}
}

80
UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs


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> { }
}

8
UOP1_Project/Assets/Scripts/Localization/Editor.meta


fileFormatVersion: 2
guid: 37b07de76954f38498cb772572ea4f96
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/UOP1_Project/Assets/Scripts/Localization/LocalizeComponent_TMProFont.cs → /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs

/UOP1_Project/Assets/Scripts/Localization/LocalizeComponent_TMProFont.cs.meta → /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeComponent_TMProFont.cs.meta

/UOP1_Project/Assets/Scripts/Localization/LocalizeTMProFontEvent.cs.meta → /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs.meta

/UOP1_Project/Assets/Scripts/Localization/LocalizeTMProFontEvent.cs → /UOP1_Project/Assets/Scripts/Localization/Editor/LocalizeTMProFontEvent.cs

正在加载...
取消
保存