HKI Core
TextLocalization.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections.Generic;
3 
4 namespace HKI.Core.Loc
5 {
9  [System.Serializable]
10  public class TextLocalization : ScriptableObject
11  {
15  [System.Serializable]
17  {
18  // Public variables
19  [SerializeField] SystemLanguage Language = SystemLanguage.English;
20  [SerializeField] [Multiline(1)] string Text = "";
21 
22  // Getter
23  public SystemLanguage GetLanguage { get { return Language; } }
24  public string GetText { get { return Text; } }
25  }
26 
27  // Public variables
31  [SerializeField] List<TextLocalizationElement> TextLocalizationElements = new List<TextLocalizationElement>();
32 
33  // Interface function
39  public string GetText(Language language)
40  {
41  if(language != null)
42  return GetText(language.Value);
43  else
44  return GetDefaultText();
45  }
46 
52  public string GetText(SystemLanguage language)
53  {
54  for(int i = 0; i < TextLocalizationElements.Count; i++)
55  {
56  if(language == TextLocalizationElements[i].GetLanguage)
57  return TextLocalizationElements[i].GetText;
58  }
59 
60  return TextLocalizationElements.Count > 0 ? TextLocalizationElements[0].GetText : "";
61  }
62 
67  public string GetDefaultText()
68  {
69  return TextLocalizationElements.Count > 0 ? TextLocalizationElements[0].GetText : "";
70  }
71  }
72 }
string GetDefaultText()
This functions returns the default localization this will be the first TextElement. In the case there is no localization at all an empty string will be returned.
This ScriptableObject contains as a container for all text localization information.
string GetText(Language language)
This function returns the string in a specific language. If there is no localization element in the r...
Special Variable enables the use of the SystemLanguage data type as a variable of the settings system...
Definition: Language.cs:13
This subclass holds the data for a text localization in a specific language.
string GetText(SystemLanguage language)
Alternative way of getting the localized string with SystemLanguage as input.