RegionSelector.cs
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class RegionSelector : MonoBehaviour {
private readonly Dictionary<string, string> regions = new Dictionary<string, string> {
{ "Padrão Nacional", "" },
{ "Acre", "AC/" },
{ "Alagoas", "AL/" },
{ "Amapá", "AP/" },
{ "Amazonas", "AM/" },
{ "Bahia", "BA/" },
{ "Ceará", "CE/" },
{ "Distrito Federal", "DF/" },
{ "Espírito Santo", "ES/" },
{ "Goiás", "GO/" },
{ "Maranhão", "MA/" },
{ "Mato Grosso", "MT/" },
{ "Mato Grosso do Sul", "MS/" },
{ "Minas Gerais", "MG/" },
{ "Pará", "PA/" },
{ "Paraíba", "PB/" },
{ "Paraná", "PR/"},
{ "Pernambuco", "PE/" },
{ "Piauí", "PI/" },
{ "Rio de Janeiro", "RJ/" },
{ "Rio Grande do Norte", "RN/" },
{ "Rio Grande do Sul", "RS/" },
{ "Rondônia", "RO/" },
{ "Roraima", "RR/" },
{ "Santa Catarina", "SC/" },
{ "São Paulo", "SP/" },
{ "Sergipe", "SE/" },
{ "Tocantins", "TO/" }
};
public PlayerManager manager;
public GameObject list;
public GameObject SampleItem;
public Text label;
private Region activeItem = null;
private Region selectedItem = null;
void Start ()
{
foreach (KeyValuePair<string, string> regionData in regions)
{
GameObject item = Instantiate(this.SampleItem) as GameObject;
item.GetComponentInChildren<Text>().text = regionData.Key;
item.transform.SetParent(this.list.transform);
item.GetComponent<Button>().onClick.AddListener(delegate {
selectItem(EventSystem.current.currentSelectedGameObject.GetComponent<Region>());
});
Region region = item.GetComponent<Region>();
region.Path = regionData.Value;
if (this.activeItem == null)
{
this.activeItem = region;
this.selectedItem = region;
region.select(true);
}
}
}
private void selectItem(Region region)
{
this.selectedItem.select(false);
this.selectedItem = region;
this.selectedItem.select(true);
}
public void ReselectActiveItem()
{
selectItem(this.activeItem);
}
public void OnDone()
{
this.activeItem = this.selectedItem;
this.manager.setRegion(this.activeItem.Path);
this.manager.clearLoadedBundles();
if (selectedItem.Path == "")
{
this.label.text = "BR";
}else
{
this.label.text = selectedItem.Path.Replace('/', ' ');
}
}
}
/*
void Start ()
{
this.group = this.gameObject.GetComponent<ToggleGroup>();
foreach (KeyValuePair<string, string> region in regions)
{
GameObject item = Instantiate(this.sampleItem) as GameObject;
item.GetComponentInChildren<Text>().text = region.Key;
Toggle toggle = item.GetComponentInChildren<Toggle>();
toggle.group = this.group;
toggles.Add(toggle);
Debug.Log(region.Key + ": " + (region.Value.Length == 0) + " but " + toggle.isOn);
if (region.Value.Length == 0)
this.selected = toggle;
item.transform.SetParent(this.list.transform);
}
foreach (Toggle toggle in this.toggles)
{
toggle.isOn = false;
}
this.selected.isOn = true;
}
void Update ()
{
int i = 0;
foreach (Toggle toggle in this.toggles)
{
Debug.Log("Toggle " + i++ + " : " + toggle.isOn);
toggle.isOn = false;
this.group.NotifyToggleOn(toggle);
}
}
public void OnSelect()
{
if ( ! selected.isOn) {
foreach (Toggle toggle in group.ActiveToggles())
{
if (toggle.isOn)
{
this.selected = toggle;
this.manager.setRegion(this.regions[toggle.GetComponent<Text>().text]);
}
}
}
}
*/