blob: 271976b84921f89ddf3a5de390c804a5b3db4190 (
plain)
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
160
161
162
163
164
165
166
167
|
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class UpgradeButton : MonoBehaviour
{
[SerializeField]
private string unlockString;
[SerializeField]
public int xpCost;
public int cardCountRequirement;
[SerializeField]
private bool countsAsCardUnlock = true;
[SerializeField]
private bool countAsDevelopment;
[SerializeField]
private Sprite unlockedSprite;
[SerializeField]
private bool checkAchievements;
[SerializeField]
private GameObject priceTag;
private GameObject currentPriceTag;
private Image img;
private Button btn;
[SerializeField]
private UpgradeButton previous;
[SerializeField]
private UpgradeButton[] next;
public bool unlocked;
private void Start()
{
img = GetComponent<Image>();
btn = GetComponent<Button>();
CheckUnlock();
StartCoroutine(LateStart());
}
public void Unlock()
{
if (UpgradeManager.instance.xp >= xpCost)
{
SFXManager.instance.ButtonClick();
UpgradeManager.instance.AddXP(-xpCost);
PlayerPrefs.SetInt(unlockString, 1);
if (checkAchievements)
{
AchievementManager.instance.CheckTowerUnlocks();
}
UpgradeManager.instance.CountCard(countsAsCardUnlock);
UpgradeManager.instance.CountDevelopment(countAsDevelopment);
btn.enabled = false;
img.sprite = unlockedSprite;
unlocked = true;
UpdateTitleText();
UpgradeButton[] array = next;
for (int i = 0; i < array.Length; i++)
{
array[i].CheckEnabled();
}
}
}
public void ResetUnlock()
{
PlayerPrefs.SetInt(unlockString, 0);
unlocked = false;
}
private void CheckUnlock()
{
if (PlayerPrefs.GetInt(unlockString, 0) == 1)
{
btn.enabled = false;
img.sprite = unlockedSprite;
unlocked = true;
}
}
public void CheckEnabled()
{
if (previous == null)
{
if (cardCountRequirement <= UpgradeManager.instance.unlockedCardCount)
{
btn.interactable = true;
}
else
{
btn.interactable = false;
}
UpdateTitleText();
}
else
{
if (previous.unlocked && cardCountRequirement <= UpgradeManager.instance.unlockedCardCount)
{
btn.interactable = true;
}
else
{
btn.interactable = false;
}
UpdateTitleText();
}
}
private void UpdateTitleText()
{
if (!unlocked)
{
if (currentPriceTag == null)
{
currentPriceTag = Object.Instantiate(priceTag, base.transform);
currentPriceTag.transform.localPosition = new Vector3(-63.7f, 0f, 0f);
int num = cardCountRequirement - UpgradeManager.instance.unlockedCardCount;
if (num > 0)
{
currentPriceTag.GetComponent<RectTransform>().sizeDelta = new Vector2(75f, 50f);
currentPriceTag.GetComponentInChildren<Text>().text = " Unlock " + num + "\n more cards";
}
else
{
currentPriceTag.GetComponent<RectTransform>().sizeDelta = new Vector2(50f, 25f);
currentPriceTag.GetComponentInChildren<Text>().text = xpCost + " xp";
}
}
else
{
int num2 = cardCountRequirement - UpgradeManager.instance.unlockedCardCount;
if (num2 > 0)
{
currentPriceTag.GetComponent<RectTransform>().sizeDelta = new Vector2(75f, 50f);
currentPriceTag.GetComponentInChildren<Text>().text = " Unlock " + num2 + "\n more cards";
}
else
{
currentPriceTag.GetComponent<RectTransform>().sizeDelta = new Vector2(50f, 25f);
currentPriceTag.GetComponentInChildren<Text>().text = xpCost + " xp";
}
}
}
else if (currentPriceTag != null)
{
currentPriceTag.SetActive(value: false);
}
}
private IEnumerator LateStart()
{
yield return new WaitForSeconds(0.1f);
CheckEnabled();
}
}
|