-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokenTrigger.cs
234 lines (163 loc) · 5.05 KB
/
TokenTrigger.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
Script: TokenTrigger
Author: Alex MacNair
Function: Detects nearby table objects (Tektons) and triggers a call to an
effect script on that object.
Usage: This script should be applied to the effect object(s) (tokens).
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TokenTrigger : MonoBehaviour {
public float maxDist = 6.3f;
public float minDist = 1.6f;
public string searchTag = "Tekton";
public enum effects {None, Scale, StretchX, StretchY, StretchZ, Skew, Mirror, Twist, LineArray, Sinusoid, Transparency };
public effects effect = effects.None;
private float objDist;
private GameObject[] tektons;
private List<GameObject> inRange;
private Transform other;
private MeshRenderer mesh;
// Use this for initialization
void Start () {
tektons = GameObject.FindGameObjectsWithTag("Tekton"); //Populate array with all token objects
inRange = new List<GameObject>();
}
// Update is called once per frame
void Update () {
mesh = GetComponent<MeshRenderer>();
if (mesh.enabled) { //If the token is active, scan for Tektons
ScanObjects();
}
if (!mesh.enabled) { //If the token is not active, stop it's effect(s)
stopEffects();
}
}
public void ScanObjects() {
if (tektons[0] == null) { //Make sure there is at least one object in the array
Debug.Log("No objects are tagged as tektons!");
return;
}
foreach (GameObject tekton in tektons) {
//Debug.Log(tekton);
other = tekton.transform;
if (!tekton.activeSelf) {
//If the current tekton is hidden (off the table) don't bother to check it
continue;
}
if (tekton.transform) {
//If the data is valid, calculate the distance between the objects
objDist = Vector3.Distance(other.position, this.transform.position);
}
if ( (objDist <= maxDist && objDist >= minDist) && mesh.enabled) { //If object is within the min-max range
inRange.Add(tekton);
switch(effect) {
case effects.None:
continue;
case effects.Scale:
doScale(1.5f);
continue;
case effects.StretchX:
doStretchX(2.0f);
continue;
case effects.StretchY:
doStretchY(2.0f);
continue;
case effects.StretchZ:
doStretchZ(2.0f);
continue;
case effects.Skew:
doSkew();
continue;
case effects.Mirror:
doMirror();
continue;
case effects.Twist:
doTwist();
continue;
case effects.LineArray:
doArrayLine();
continue;
case effects.Sinusoid:
doSinusoid();
continue;
/*
Not yet implemented
case effects.Transparency:
doTransparency();
continue;
*/
default:
continue;
}
}
if ( (objDist > maxDist)) {
inRange.Remove(tekton);
stopEffects();
}
}
}
public void stopEffects() {
foreach (GameObject tekton in inRange) {
other = tekton.transform;
switch(effect) {
case effects.None:
continue;
case effects.Scale:
endScale();
continue;
case effects.StretchX:
endStretchX();
continue;
case effects.StretchY:
endStretchY();
continue;
case effects.StretchZ:
endStretchZ();
continue;
case effects.Skew:
endSkew();
continue;
case effects.Mirror:
endMirror();
continue;
case effects.Twist:
endTwist();
continue;
case effects.LineArray:
endArrayLine();
continue;
case effects.Sinusoid:
endSinusoid();
continue;
/*
Not yet implemented
case effects.Transparency:
endTransparency();
continue;
*/
default:
continue;
}
}
}
public void doScale(float n) { other.GetComponent<ScaleEffect>().Scale(n); }
public void doStretchX(float n) { other.GetComponent<StretchEffect>().StretchX(n); }
public void doStretchY(float n) { other.GetComponent<StretchEffect>().StretchY(n); }
public void doStretchZ(float n) { other.GetComponent<StretchEffect>().StretchZ(n); }
public void doSkew() { other.GetComponent<MeshSkew>().Skew(); }
public void doMirror() { other.GetComponent<ObjectMirror>().Mirror(); }
public void doTwist() { other.GetComponent<MeshTwist>().Twist() ; }
public void doArrayLine() { other.GetComponent<ObjectArray>().LineArray(); }
public void doSinusoid() { other.GetComponent<MeshSinusoid>().Sinusoid(); }
public void endScale() { other.GetComponent<ScaleEffect>().ResetScale(); }
public void endStretchX() { other.GetComponent<StretchEffect>().ResetStretchX(); }
public void endStretchY() { other.GetComponent<StretchEffect>().ResetStretchY(); }
public void endStretchZ() { other.GetComponent<StretchEffect>().ResetStretchZ(); }
public void endSkew() { other.GetComponent<MeshSkew>().ResetSkew(); }
public void endMirror() { other.GetComponent<ObjectMirror>().RemoveClones(); }
public void endTwist() { other.GetComponent<MeshTwist>().ResetTwist() ; }
public void endArrayLine() { other.GetComponent<ObjectArray>().RemoveClones(); }
public void endSinusoid() { other.GetComponent<MeshSinusoid>().ResetSinusoid(); }
}