diff options
| author | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
| commit | 85553832ead1a96f88726cd2b35cb6ff1d8b8cc8 (patch) | |
| tree | 7a2615034462d4296ed09d24038bb4c68107979d /Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs | |
| parent | e06acf066171670248b0b644c0eb8f6d895e051e (diff) | |
| download | Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.gz Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.bz2 Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.zip | |
Attempt number 2 on localization
Diffstat (limited to 'Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs')
| -rw-r--r-- | Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs new file mode 100644 index 0000000..c9fcbc6 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +namespace Lean.Localization +{ + /// <summary>This component will update a TMPro.TextMeshProUGUI component with localized text, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(TextMesh))] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized TextMesh")] + public class LeanLocalizedTextMesh : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this text will be used")] + public string FallbackText; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the TextMeshProUGUI component attached to this GameObject + var text = GetComponent<TextMesh>(); + + // Use translation? + if (translation != null && translation.Data is string) + { + text.text = LeanTranslation.FormatText((string)translation.Data, text.text, this); + } + // Use fallback? + else + { + text.text = LeanTranslation.FormatText(FallbackText, text.text, this); + } + } + + protected virtual void Awake() + { + // Should we set FallbackText? + if (string.IsNullOrEmpty(FallbackText) == true) + { + // Get the TextMeshProUGUI component attached to this GameObject + var text = GetComponent<TextMesh>(); + + // Copy current text to fallback + FallbackText = text.text; + } + } + } +}
\ No newline at end of file |
