Skip to content

Instantly share code, notes, and snippets.

@mattiemonster
Last active August 30, 2018 17:23
Show Gist options
  • Save mattiemonster/dff24c1f5af517ce186bace0da4cf002 to your computer and use it in GitHub Desktop.
Save mattiemonster/dff24c1f5af517ce186bace0da4cf002 to your computer and use it in GitHub Desktop.
´╗┐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