forked from Nhacsam/SiPoteris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transition2D3D.js
346 lines (252 loc) · 7.47 KB
/
Transition2D3D.js
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#pragma strict
/*
Transition2D3D.js
number of lines : 340
*/
//camera transition parameter
private var TransitionTime : float = 10.0f ;
//signals allowing the transition 2D3D and ending
private var enable:boolean = false;
private var enableEnding:boolean = false;
private var done:boolean = false;
private var done2:boolean = false;
private var done3:boolean = false;
private var lightFlag:boolean = false;
//to access accelerometer
private var control:CameraControl;
private var zoom: Zoom;
private var Videos:videoSettings;
private var rot;
private var scene2D : boolean = true;
/* Coordinates of the 2D/3D button */
private var buttonUp : int = Screen.height * 0.85;
private var buttonLeft : int = Screen.width * 0.05;
private var buttonHeight : int = Screen.height * 0.12;
private var buttonWidth : int = Screen.height * 0.12;
private var exitFinished: boolean = true;
// CallBacks appelés lors d'un changement de vue
private var OnBeginTrans : Array ;
private var OnEndTrans : Array ;
// champ de vision de la cam en 2D et en 3D
private var fieldOfView2D : float ;
private var fieldOfView3D : float ;
private var letterStyle : GUIStyle; // style of text
private var letterStyleButton : GUIStyle; // style of the text in the button
//instantiate items
function init(fieldOfView_2D : float , fieldOfView_3D : float ){
control = gameObject.GetComponent("CameraControl");
if (!control)
control = gameObject.AddComponent("CameraControl");
zoom = gameObject.GetComponent("Zoom");
if (!zoom)
zoom = gameObject.AddComponent("Zoom");
Videos = gameObject.GetComponent("videoSettings") as videoSettings;
control.enabled = false ;
scene2D = Videos.GetFirstView();
fieldOfView2D = fieldOfView_2D ;
fieldOfView3D = fieldOfView_3D ;
letterStyle = new GUIStyle();
letterStyle.fixedHeight = Screen.height / 30; // Recopié salement de text.js
letterStyle.fixedWidth = Screen.width / 125; // pareil
letterStyle.normal.textColor = Color.white;
if (isOnIpad())
letterStyle.fontSize = 27; // Default: 13
letterStyleButton = new GUIStyle (letterStyle);
letterStyleButton.alignment = TextAnchor.MiddleCenter;
// Initialisation des Callback
OnBeginTrans = new Array();
OnEndTrans = new Array();
}
// update the transitions statements
public function UpdateTrans() {
Update2D3D();
Update3D2D();
UpdateEnding();
}
//setter for enable at the end of the video, called in videosettings
function endingEnable(){
enableEnding=true;
}
/*
* button switcher interface 2D/3D and directions
*/
function OnGUI2D3D(){
if(Videos.OnPlay() && !enable && exitFinished){
var Rectangle : Rect = new Rect(Screen.width * 0.8 , Screen.height * 0.9, camera.pixelWidth , camera.pixelHeight);
GUI.Label(Rectangle,"Click anywhere on the screen \n to get further information.", letterStyle);
if(Videos.GetOtherView()){
if (GUI.Button(new Rect(buttonLeft, buttonUp, buttonWidth, buttonHeight), " ")) {
zoom.disableEvents();
Change2D3D();
//Videos.test();
}
GUI.Label(new Rect(buttonLeft + 0.5 * buttonWidth - 0.5 * letterStyleButton.fixedWidth, buttonUp + 0.5 * buttonHeight - 0.5 * letterStyleButton.fixedHeight, buttonWidth, buttonHeight), scene2D ? "3D View" : "2D View", letterStyleButton );
}
}
}
/*
* Tests if pos is inside the 2D / 3D button
*/
function isInButton (pos : Vector2) {
return ( pos.x > buttonLeft && pos.x < buttonLeft + buttonWidth && pos.y > Screen.height - buttonUp - buttonHeight && pos.y < Screen.height - buttonUp);
}
/*
* reset camera parameters on switching 2D/3D
*/
function Change2D3D(){
end=false;
cameraTransition();
switchScene();
}
/**
* Camera switch 2D/3D
*/
function cameraTransition(){
if(scene2D){
rot= camera.transform.eulerAngles;
lightFlag=false;
enable=true;
done=false;
next=false;
done2=false;
done3=false;
}
else{
rot= Vector3(270,180,0);
camera.transform.eulerAngles=Vector3(0,0,0);
enable=true;
done=false;
next=false;
done2=false;
done3=false;
lightFlag=false;
light.type=LightType.Point;
light.cookie=null;
}
Console.Info('Début de la transition 2D-3D');
// Appel des callbacks
for( var j = 0; j < OnBeginTrans.length; j++){
(OnBeginTrans[j] as function( boolean ) )( scene2D ) ;
}
}
private var next:boolean = false;
private var end:boolean =false;
//called at everyframe, function generating transition
function Update2D3D(){
if (!enable)
return ;
control.DetachGyro();
//decrease light intensity
if(!scene2D && !lightFlag){
light.intensity-=0.02;
if(light.intensity <= 0.04)lightFlag=true;
}
//load the pshere and reincrease light
if(!scene2D && !done && lightFlag){
camera.fieldOfView = fieldOfView3D ;
Videos.changeSettings(true);
camera.transform.eulerAngles=Vector3(270,0,0);
if(light.intensity <= 0.88)light.intensity+=0.02;
camera.transform.position.y += 1/TransitionTime;
if(camera.transform.position.y >= 0.7 ) {done = true; next=true;}
}
if(!scene2D && next && done){
camera.transform.Rotate(Vector3(10,0,0)/TransitionTime);
if(camera.transform.eulerAngles.x >= 358 ){
enable=false;
(gameObject.GetComponent("Main") as Main).enableMouseLook();
control.AttachGyro();
zoom.enableEvents();
Console.Info('Fin de la transition 2D->3D');
// Appel des callbacks
for( var j = 0; j < OnEndTrans.length; j++){
(OnEndTrans[j] as function( boolean ) )( scene2D ) ;
}
}
}
}
function Update3D2D(){
if (!enable)
return ;
control.DetachGyro();
//decrease light intensity
if(scene2D && !done){
light.intensity-=0.02;
camera.transform.Rotate(Vector3(-10,0,0)/TransitionTime);
if(camera.transform.eulerAngles.x <= 270 ) {done = true;}
}
if(scene2D && !done2){
camera.transform.Rotate(Vector3(0,10,0)/TransitionTime);
if(camera.transform.eulerAngles.x >= 180 ) {done2 = true; next=true;}
}
//load the plane
if(scene2D && next ){
camera.fieldOfView = fieldOfView2D ;
if(camera.transform.position.y >= -10)camera.transform.position.y -= 1/TransitionTime;
else{done3=true;
camera.transform.eulerAngles=rot;
Videos.changeSettings(false);
}
}
//reincrease light
if(scene2D && done3){
if(light.intensity <= 0.88)light.intensity+=0.02;
else {
enable=false;
zoom.enableEvents();
Console.Info('Fin de la transition 2D<-3D');
// Appel des callbacks
for( var j = 0; j < OnEndTrans.length; j++){
(OnEndTrans[j] as function( boolean ) )( scene2D ) ;
}
}
}
}
function UpdateEnding(){
Videos.effectsOnEnd();
if (!enableEnding)
return ;
if(!end && !lightFlag){
light.intensity-=0.02;
if(light.intensity <= 0.04)lightFlag=true;
}
if(!end && lightFlag){
light.intensity+=0.02;
if(light.intensity >= 0.88){enableEnding=false;end=true;zoom.enableEvents();Videos.EndFlagOff();}
}
}
//called in Transition2D3D
function switchScene(){
scene2D=!scene2D;
}
//getter for other functions in other scripts
function isScene2D(){
return scene2D;
}
//called in DeZoom state
function flagExit(){
exitFinished=!exitFinished;
return exitFinished;
}
static function isOnIpad() : boolean {
return ( SystemInfo.deviceType == DeviceType.Handheld );
}
// decrease light
function fonduDown(){
if(light.intensity <= 0.04)return;
else light.intensity-=0.02;
}
//increase light
function fonduUp(){
if(light.intensity >= 0.88)return;
else light.intensity+=0.02;
}
/**
* Setter de Callback
*/
function AddOnBeginTrans ( f : function( boolean ) ) {
OnBeginTrans.push(f);
}
function AddOnEndTrans ( f : function( boolean ) ) {
OnEndTrans.push(f);
}