-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEndSequence1stPerson.js
275 lines (224 loc) · 8.5 KB
/
EndSequence1stPerson.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
#pragma strict
var Player : GameObject;
private var FallingPlayerScript : FallingPlayer;
var PlayerController : MoveController;
var ScoreController : ScoreController;
var LifeController : lifeCountdown;
var EndTriggerName : GameObject;
var EndTriggerComponent : EndSequenceTrigger;
var EndMenuLogoObjectVR : GameObject;
var EndMenuLogoObject : GameObject;
var EndMenuLogoCamera : GameObject;
var OutroMusic : AudioSource;
var OutroMusicBedObject : GameObject;
var OutroMusicBed : AudioSource;
var MusicBedInterpolated : AudioVolumeInterpolate;
var UIscriptEndMenuName : GameObject;
var UIscriptEndMenuComponent : FallingEndMenuUI;
var reticleVRUIScript : VRLifeMeter;
//var outroShards : GameObject;
var outroCompletedOrb : GameObject;
var outroCompletionPoint : GameObject;
function Start () {
FallingPlayerScript = GetComponent("FallingPlayer");
PlayerController = GetComponent("MoveController");
ScoreController = GetComponent("ScoreController");
LifeController = GetComponent("lifeCountdown");
MusicBedInterpolated = OutroMusicBedObject.GetComponent("AudioVolumeInterpolate");
UIscriptEndMenuComponent = UIscriptEndMenuName.GetComponent("FallingEndMenuUI");
EndTriggerComponent = EndTriggerName.GetComponent("EndSequenceTrigger");
// Look up manually if not added in inspector:
if (!reticleVRUIScript) {
Debug.Log("Did you forget to select a reticleVRUIScript in the Unity Inspector?");
reticleVRUIScript = GameObject.Find("vr-radial-life-meter").GetComponent.<VRLifeMeter>();
}
// Skip to the outro for testing.
// Make sure to disable EndSequenceTrigger's PlayOutro call so they don't compete:
// PlayOutro();
}
function PlayOutro () {
// GameAnalytics events for beating the game
var isNewGamePlus : String = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game";
FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime);
FallingLaunch.Analytics.Event(
"GameComplete:" + FallingLaunch.vrModeAnalyticsString + isNewGamePlus,
FallingLaunch.secondsInLevel
);
// TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName );
// TestFlightUnity.TestFlight.PassCheckpoint( "GameComplete");
FallingPlayer.isPausable = false;
ScoreController.enabled = false;
LifeController.enabled = false;
FallingPlayer.isTiltable = false;
PlayerController.lerpSlowdown(1);
OutroMusic.Play();
//PlayerController.SpeedLinesOff(1);
yield WaitForSeconds (1);
PlayerController.enabled = false;
FallingPlayer.isPausable = false;
Player.transform.GetComponent.<Rigidbody>().isKinematic = true;
if (FallingLaunch.isVRMode) {
reticleVRUIScript.FadeReticleOut(0.5);
} else {
FallingPlayer.UIscriptComponent.BeginOutroUI();
}
ScoreController.IncrementScore(35);
LerpTowardsDiamond(10);
RotateTowardsDiamond(10);
yield WaitForSeconds (10);
// LerpIntoDiamond(14);
MusicBedInterpolated.falsifyCheckDistance();
FadeMusic(8, OutroMusicBed);
// Only using iTween for path movement.
// Rotation is handled via FinalRotation's Slerp.
iTween.MoveTo(gameObject,
iTween.Hash("path",iTweenPath.GetPath("player-end-path"),
"orienttopath", false,
// "looktarget", EndTriggerComponent.getDiamondCenter(),
// "axis", "y",
"time", 13,
"easetype", "easeOutSine"
));
// start rotating player camera to end at the same time as the above tween path traveling.
FinalRotation(13);
EndTriggerComponent.AddDiamondCore(5);
yield WaitForSeconds (1);
EndTriggerComponent.AddDiamond3DCore(6);
yield WaitForSeconds (1);
EndTriggerComponent.FadeDiamond(8);
yield WaitForSeconds (6);
ScoreController.enabled = true;
LifeController.enabled = true;
lifeCountdown.inOutro = false;
if (!FallingLaunch.isVRMode) {
FallingPlayer.UIscriptComponent.GameCompleteUI();
UIscriptEndMenuComponent.ShowEndGameUI();
}
FadeAudioListener (4);
yield WaitForSeconds(1);
if (FallingLaunch.isVRMode) {
FadeEndMenuLogoVR(3.0);
FallingPlayerScript.WhiteFadeVREndGame(5.0);
} else {
FadeEndMenuLogo(3.0);
}
FallingLaunch.NewGamePlus = true;
}
function LerpTowardsDiamond (timer : float) {
var diamondLookTarget = outroCompletedOrb.transform;
var start = gameObject.transform.position;
var end = outroCompletionPoint.transform.position;
var i = 0.0;
var step = 1.0/timer;
var startRotation = transform.rotation;
var endRotation = Quaternion.Euler(-54,96,-2.3);
// var zeroRotation = Quaternion.Euler(0,0,0);
// var direction:Vector3 = diamondLookTarget.position - start;
// rotation = Quaternion.LookRotation(direction);
// Debug.Log('direction is ' + diamondLookTarget.position);
while (i <= 1.0) {
// transform.LookAt(diamondLookTarget);
i += step * Time.deltaTime;
var t : float = i*i*i * (i * (6f*i - 15f) + 10f); // smootherstep lerp
transform.position = Vector3.Slerp(start, end, t);
//transform.rotation = Quaternion.Slerp(startRotation, endRotation, i);
yield;
}
EndTriggerComponent.SwapDiamonds(4);
}
function FinalRotation (timer : float) {
var i = 0.0;
var step = 1.0/timer;
var startRotation = transform.rotation;
var endRotation = Quaternion.Euler(-23.9,101.74,-2.52);
while (i <= 1.0) {
i += step * Time.deltaTime;
var t : float = i*i*i * (i * (6f*i - 15f) + 10f); // smootherstep lerp
transform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
yield;
}
}
function RotateTowardsDiamond (timer : float) {
var i = 0.0;
var step = 1.0/timer;
var startRotation = transform.rotation;
var endRotation = Quaternion.Euler(-54,96,-2.3);
var myCameraParent = transform.Find("Player-cameras");
var parentRotation = myCameraParent ? myCameraParent.localRotation : Quaternion.identity;
while (i <= 1.0) {
i += step * Time.deltaTime;
var t : float = i*i * (3f - 2f*i); // smoothstep lerp
transform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
// myCameraParent needs rotating too, because otherwise the local container object
// (tilted via FallingPlayer.playerTilt) will not be aligned to 0,0,0 local rotation,
// so the diamond target won't be centered in view. VR mode is unaffected by this,
// since the VR eye cameras aren't children of myCameraParent.
if (myCameraParent) {
myCameraParent.localRotation = Quaternion.Slerp(parentRotation, Quaternion.identity, t);
}
yield;
}
}
// function LerpIntoDiamond (timer : float) {
// var end = outroCompletedOrb.transform.position;
// var start = gameObject.transform.position;
// var startRotation = transform.rotation;
// var endRotation = Quaternion.Euler(-79,97,-2.3);
// var i = 0.0;
// var step = 1.0/timer;
// while (i <= 1.0) {
// i += step * Time.deltaTime;
// transform.position = Vector3.Slerp(start, end, i);
// transform.rotation = Quaternion.Slerp(startRotation, endRotation, i);
// yield;
// }
// }
function FadeEndMenuLogoVR(timer:float){
EndMenuLogoObjectVR.GetComponent.<Renderer>().enabled = true;
var start = 0;
var end = 1.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
EndMenuLogoObjectVR.GetComponent.<Renderer>().material.color.a = Mathf.Lerp(start, end, i);
yield;
}
yield WaitForSeconds (timer);
}
function FadeEndMenuLogo(timer:float){
EndMenuLogoCamera.GetComponent(Camera).enabled = true;
EndMenuLogoObject.GetComponent.<Renderer>().enabled = true;
var start = 0;
var end = 1.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
EndMenuLogoObject.GetComponent.<Renderer>().material.color.a = Mathf.Lerp(start, end, i);
yield;
}
yield WaitForSeconds (timer);
}
function FadeMusic (timer : float, source : AudioSource) {
var audioStart = source.volume;
var audioEnd = 0.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
source.volume = Mathf.Lerp(audioStart, audioEnd, i);
yield;
}
}
function FadeAudioListener(timer : float) {
var start = AudioListener.volume;
var end = 0.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
AudioListener.volume = Mathf.Lerp(start, end, i);
yield;
}
}