HKI Core
UILanguageDropdown.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using TMPro;
3 using System.Collections.Generic;
4 using HKI.Core.Loc;
5 
6 namespace HKI.Core.UI.Settings
7 {
11  [RequireComponent(typeof(TMP_Dropdown))]
12  public class UILanguageDropdown : MonoBehaviour
13  {
14  // Public variables
15  [SerializeField] List<SystemLanguage> Languages = new List<SystemLanguage>() { SystemLanguage.English };
16  [SerializeField] Language Language = null;
17 
18  // Private variables
19  TMP_Dropdown dropdown = null;
20 
21  // Awake function
22  void Awake()
23  {
24  dropdown = GetComponent<TMP_Dropdown>();
25  }
26 
27  // Start function
28  void Start()
29  {
30  if(Language != null)
31  {
32  List<TMP_Dropdown.OptionData> list = new List<TMP_Dropdown.OptionData>();
33  for(int i = 0; i < Languages.Count; i++)
34  list.Add(new TMP_Dropdown.OptionData(Languages[i].ToString()));
35 
36  dropdown.ClearOptions();
37  dropdown.AddOptions(list);
38 
39  dropdown.value = Languages.FindIndex(x => x == Language.Value);
40 
41  if(dropdown.value < 0)
42  dropdown.value = 0;
43  }
44  else
45  Debug.LogError("(UILanguageDropdown) Language value is null!");
46  }
47 
48  // Interface functions
50  {
51  if(Language != null)
52  Language.SetValue = Languages[dropdown.value];
53  }
54 
55  public void Reset()
56  {
57  List<TMP_Dropdown.OptionData> list = new List<TMP_Dropdown.OptionData>();
58  for (int i = 0; i < Languages.Count; i++)
59  list.Add(new TMP_Dropdown.OptionData(Languages[i].ToString()));
60 
61  dropdown.ClearOptions();
62  dropdown.AddOptions(list);
63 
64  dropdown.value = Languages.FindIndex(x => x == Language.Value);
65 
66  if (dropdown.value < 0)
67  dropdown.value = 0;
68  }
69  }
70 }
Special Variable enables the use of the SystemLanguage data type as a variable of the settings system...
Definition: Language.cs:13
This MonoBehaviour fills and handles a dropdown (TMP_Dropdown) with language settings.