-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tile.cs
166 lines (145 loc) · 3.7 KB
/
Tile.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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Tile : MonoBehaviour {
public int indRow; //Row
public int indCol;
public Sprite Big;
public Sprite StartSp;
public int Number
{
get
{
return number;
}
set
{
number = value;
if (number == 0)
SetEmpty();
else if (0 < number && number < 16)
{
TileImage.sprite = StartSp;
ApplyStyle(number);
SetVisible();
}
else if (number >= 16)
{
TileImage.sprite = Big;
ApplyStyle(number);
SetVisible();
}
}
}
public string Color
{
get
{
return TileImage.color.ToString();
}
}
private int number;
private Text TileText;
private Image TileImage;
private Animator anim;
private void Awake()
{
anim = GetComponent<Animator>();
TileText = GetComponentInChildren<Text>(); // What is TileText and TileImage
TileImage = transform.Find("NumberedCell").GetComponent<Image>();
}
public void PlayMergedAnimation()
{
anim.SetTrigger("Merge");
}
public void PlayAppearAnimation()
{
anim.SetTrigger("Appear");
}
public void PlayBigAnimation()
{
anim.SetTrigger("Big");
}
void ApplyStyleFromHolder(int index)
{
TileText.text = TileStyleHolder.Instance.TileStyles[index].Number.ToString(); //call an enemy
TileText.color = TileStyleHolder.Instance.TileStyles[index].TextColor;
TileImage.color = TileStyleHolder.Instance.TileStyles[index].TileColor;
}
void ApplyStyle(int num)
{
switch (num)
{
case 1:
ApplyStyleFromHolder(0);
break;
case 2:
ApplyStyleFromHolder(1);
break;
case 3:
ApplyStyleFromHolder(2);
break;
case 4:
ApplyStyleFromHolder(3);
break;
case 5:
ApplyStyleFromHolder(4);
break;
case 6:
ApplyStyleFromHolder(5);
break;
case 7:
ApplyStyleFromHolder(6);
break;
case 8:
ApplyStyleFromHolder(7);
break;
case 9:
ApplyStyleFromHolder(8);
break;
case 10:
ApplyStyleFromHolder(9);
break;
case 11:
ApplyStyleFromHolder(10);
break;
case 12:
ApplyStyleFromHolder(11);
break;
case 13:
ApplyStyleFromHolder(12);
break;
case 14:
ApplyStyleFromHolder(13);
break;
case 15:
ApplyStyleFromHolder(14);
break;
case 16:
ApplyStyleFromHolder(15);
break;
default:
Debug.LogError("Check the number that you pass to ApplyStyle !! L");
break;
}
}
// Use this for initialization
private void SetVisible()
{
TileImage.enabled = true;
TileText.enabled = true;
}
private void SetEmpty()
{
TileImage.enabled = false;
TileText.enabled = false;
}
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}