-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneralWindow.cs
55 lines (49 loc) · 1.41 KB
/
GeneralWindow.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace WeersProductions
{
/// <summary>
/// A simple window with x buttons and a text in the center.
/// Background color can be changed using properties in the constructor.
/// </summary>
public class GeneralWindow : MCMenu {
/// <summary>
/// Main text in the center of the window.
/// </summary>
[SerializeField]
private Text _text;
/// <summary>
/// The background image which color is changed using properties.
/// </summary>
[SerializeField]
private Image _background;
[SerializeField]
private Button[] _buttons;
public override void Show(object data)
{
GeneralWindowData windowData = data as GeneralWindowData;
if (windowData == null) {
Debug.LogError("Trying to show a GeneralWindow without the apprioate data!");
return;
}
_text.text = windowData.text;
_background.color = windowData.BackgroundColor;
for(int i = 0; i < _buttons.Length; i++) {
// Store, since we use it in a lambda expression
int index = i;
_buttons[i].GetComponentInChildren<Text>().text = windowData.ButtonsTexts[index];
_buttons[i].onClick.RemoveAllListeners();
_buttons[i].onClick.AddListener(() => {
SetText(windowData.ButtonFunctionTexts[index]);
});
}
base.Show(data);
}
private void SetText(string text)
{
this._text.text = text;
}
}
}