-
Notifications
You must be signed in to change notification settings - Fork 0
/
HiddenWallMediator.cs
205 lines (144 loc) · 3.03 KB
/
HiddenWallMediator.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using UnityEngine;
using System.Collections;
public class HiddenWallMediator : MonoBehaviour {
public static bool ShowFlag = true;
public int id = 0;
private bool show = true;
private bool visible = true;
private float alphaChange = 1f;
private tk2dSprite currentSprite;
public float FadeDuration = 0.1f;
private float timeSinceStart = 0;
private bool invalidateUI = false;
private bool inside = true;
void Awake()
{
Messenger.AddListener<int, bool>("HideWall", HideWallEventHandler);
}
void OnDestroy()
{
//Messenger.RemoveListener<int, bool>("HideWall", HideWallEventHandler);
}
void Start()
{
currentSprite = GetComponent<tk2dSprite>();
}
void HideWallEventHandler(int id, bool show)
{
CancelInvoke();
if(id == this.id)
{
//CancelInvoke();
this.show = show;
//timeSinceStart = 0;
invalidateUI = true;
//target.renderer.material.color.a -= Time.deltaTime/fadeDuration;
}
}
void Update()
{
/*if(ShowFlag)
{
currentSprite.color = new Color(1,1,1,1);
}
else
{
currentSprite.color = new Color(1,1,1,0);
}*/
if(invalidateUI)
{
timeSinceStart += Time.deltaTime;
if(ShowFlag)
{
//if(!visible)
//{
Debug.Log("hidding");
alphaChange = Mathf.Lerp(0, 1, timeSinceStart);
//currentSprite.color = new Color(1,1,1,alphaChange);
//}
}
else
{
//if(visible)
//{
Debug.Log("showing");
alphaChange = Mathf.Lerp(1, 0, timeSinceStart);
//currentSprite.color = new Color(1,1,1,alphaChange);
//}
}
currentSprite.color = new Color(1,1,1,alphaChange);
if(alphaChange == 1f)
{
Debug.Log("finishing");
invalidateUI = false;
timeSinceStart = 0;
visible = show;
}
}
}
/*void OnTriggerEnter()
{
ShowFlag = false;
//
// when we step on this collider
// tell all the sprites of this
// to hide them all
//
//
// Dont do this while we are invalidating the ui
//
//if(!invalidateUI)
//{
//HideWall();
//
// avoid the display of the wall for all those invokes already
//
//CancelInvoke();
//
// now set to show the wall in one second
//
//Invoke("ShowWall", 1f);
//}
//ShowFlag = true;
}
void OnTriggerExit()
{
//Debug.Log("Exit");
//inside = false;
Invoke("ShowWall", 1f);
}*/
void OnTriggerStay(Collider other)
{
//
// do it only if beign hit by the player
//
UnitPlayer player = other.GetComponent<UnitPlayer>();
if(player)
{
HideWall();
CancelInvoke();
Invoke("ShowWall", 1f);
}
}
void ShowWall()
{
//Messenger.Broadcast( "HideWall", id, true);
ShowFlag = true;
invalidateUI = true;
Debug.Log("show wall");
/*if(!inside)
{
Messenger.Broadcast( "HideWall", id, true);
}*/
}
void HideWall()
{
//if(inside)
//{
ShowFlag = false;
invalidateUI = true;
Messenger.Broadcast( "HideWall", id, false );
Debug.Log("hide wall");
//}
}
}