Last active
August 30, 2018 17:23
-
-
Save mattiemonster/dff24c1f5af517ce186bace0da4cf002 to your computer and use it in GitHub Desktop.
This file contains 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
´╗┐using UnityEngine; | |
using TMPro; | |
using System.Collections.Generic; | |
namespace Vortex.TextLoader | |
{ | |
[RequireComponent(typeof(TextMeshProUGUI))] | |
public class TranslatableText : MonoBehaviour | |
{ | |
TextMeshProUGUI text; | |
public string key; | |
public string manualFallback = "No Text Definition Found"; | |
void Start() | |
{ | |
text = GetComponent<TextMeshProUGUI>(); | |
if (!text) | |
{ | |
Debug.LogError("Translatable text object with no text component!"); | |
} | |
} | |
public void Load(Dictionary<string, string> dictionary, Dictionary<string, string> fallbackDictionary) | |
{ | |
// Debug.Log(gameObject.name); | |
if (!text) | |
{ | |
Debug.LogError("Text component null! For object " + gameObject.name); | |
return; | |
} | |
if (dictionary.ContainsKey(key)) | |
text.text = dictionary[key]; | |
else if (fallbackDictionary.ContainsKey(key)) | |
text.text = fallbackDictionary[key]; | |
else | |
text.text = manualFallback; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment