Last active
January 21, 2025 14:27
-
-
Save ksnnacar/de2c81cff25ee3ec54290fd4cf60f6cf to your computer and use it in GitHub Desktop.
Lean Localization Text Mesh Pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file is my contribution to use the Lean Localization asset with TextMeshProUGUI, | |
I'm not the owner of the main asset, All copyrights are their respective owners. | |
Please check the original license of the package if you have any questions regarding that. | |
You can get the asset free on the assetstore: | |
http://www.assetstore.unity3d.com/#!/content/28504 | |
22.11.2017 K.S.A | |
github.com/ksnnacar | |
*/ | |
using UnityEngine; | |
using UnityEngine.UI; | |
using TMPro; | |
namespace Lean.Localization | |
{ | |
// This component will update a Text component with localized text, or use a fallback if none is found | |
[ExecuteInEditMode] | |
[RequireComponent(typeof(TextMeshProUGUI))] | |
public class LeanLocalizedTextMeshPro : 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 TextMeshUI component attached to this GameObject | |
var textMesh = GetComponent<TextMeshProUGUI>(); | |
// Use translation? | |
if (translation != null) | |
{ | |
textMesh.text = translation.Text; | |
} | |
// Use fallback? | |
else | |
{ | |
textMesh.text = FallbackText; | |
} | |
} | |
protected virtual void Awake() | |
{ | |
// Should we set FallbackText? | |
if (string.IsNullOrEmpty(FallbackText) == true) | |
{ | |
// Get the TextMeshUI component attached to this GameObject | |
var textMesh = GetComponent<TextMeshProUGUI>(); | |
// Copy current text to fallback | |
FallbackText = textMesh.text; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was a helping hand, I just needed to change line 32 from
translation.Text
totranslation.Data
for it to work on version 2.0.2