From fe9e42abc1376224556541a2e7ac25a09fa12d6f Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 5 Jan 2017 23:07:24 -0500 Subject: [PATCH 01/77] refactor movement based on VR mode --- FallingLaunch.js | 25 +++++++++++++++++-------- FallingPlayer.js | 30 ++++++++++++++++++++++++------ MoveController.js | 15 +++++++++++++-- setVRMode.js | 20 ++++++++++++++++++++ 4 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 setVRMode.js diff --git a/FallingLaunch.js b/FallingLaunch.js index 4c60118..286c690 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -30,6 +30,8 @@ static var debugMode : boolean = false; var testFlightToken : String; +static var isVRMode : boolean = false; + //GameAnalytics variables static var secondsAlive : float = 0; static var secondsInLevel : float = 0; @@ -47,6 +49,7 @@ enum iPads { }; function Awake () { + isVRMode = true; // TODO: Let user pick this via UI } function Start () { @@ -76,6 +79,11 @@ function Start () { //this is necessary to override Unity 4's auto-orientation code Input.compensateSensors = false; + + // NB: still doesn't work, sensor 'correctness' depends on starting device orientation as read by Cardboard. + // HACK: Force landscape left orientation for Cardboard compatibility. + // TODO: make conditional on isVRMode? + // Screen.orientation = ScreenOrientation.LandscapeLeft; var iOSGen = iOS.Device.generation; @@ -150,6 +158,13 @@ function OnLevelWasLoaded (level : int) { //Debug.Log("my loaded level is... " + Application.loadedLevelName); } +function SetAxesRotation () { + if (PlayerPrefs.GetInt("invertHorizAxis", 0) == 1) {invertHorizAxisVal = -1;} + else {invertHorizAxisVal = 1;} + if (PlayerPrefs.GetInt("invertVertAxis", 0) == 1) {invertVertAxisVal = -1;} + else {invertVertAxisVal = 1;} +} + function Calibrate () { tiltable = false; @@ -157,10 +172,7 @@ function Calibrate () { else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} else {restPosition = neutralPosFlat;} - if (PlayerPrefs.GetInt("invertHorizAxis", 0) == 1) {invertHorizAxisVal = -1;} - else {invertHorizAxisVal = 1;} - if (PlayerPrefs.GetInt("invertVertAxis", 0) == 1) {invertVertAxisVal = -1;} - else {invertVertAxisVal = 1;} + SetAxesRotation(); //acceleratorSnapshot = Input.acceleration; acceleratorSnapshot = Vector3(0.0,0.0,-1.0); calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition); @@ -175,10 +187,7 @@ function CalibrateInLevel () { else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} else {restPosition = neutralPosFlat;} - if (PlayerPrefs.GetInt("invertHorizAxis", 0) == 1) {invertHorizAxisVal = -1;} - else {invertHorizAxisVal = 1;} - if (PlayerPrefs.GetInt("invertVertAxis", 0) == 1) {invertVertAxisVal = -1;} - else {invertVertAxisVal = 1;} + SetAxesRotation(); calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition); tiltable = true; diff --git a/FallingPlayer.js b/FallingPlayer.js index 3bf710a..adc7c16 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -76,9 +76,14 @@ var myVol : float; var peakVol : float; private var myTransform : Transform; +private var myMainCamera : Camera; + +private var myBackdrop : GameObject; +private var myBackdropRenderer : Renderer; private var BackdropMist : GameObject; -BackdropMist = transform.FindChild("Cylinder").gameObject; + +private var myVRViewer : GameObject; var rb : Rigidbody; @@ -86,13 +91,20 @@ function Awake() { // if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) { // flipMultiplier = -1; //} - myTransform = transform; + myTransform = transform; } function Start() { + myMainCamera = myTransform.FindChild("Camera").GetComponent.(); + myBackdrop = GameObject.Find("plane-close"); + BackdropMist = GameObject.Find("Cylinder"); + myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; + + myVRViewer = GameObject.Find("GvrViewerMain"); + // startingFogColor = RenderSettings.fogColor * 2; startingFogEndDistance = RenderSettings.fogEndDistance; - startingCameraFarClipPlane = myTransform.FindChild("Camera").GetComponent.().farClipPlane; + startingCameraFarClipPlane = myMainCamera.farClipPlane; isAlive = 1; UIscriptComponent = UIscriptName.GetComponent(fallingUITest); lifeStartTime = Time.time; @@ -245,13 +257,19 @@ function changeLevelBackdrop () { // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); RenderSettings.fogEndDistance = startingFogEndDistance; - myTransform.FindChild("Camera").GetComponent.().farClipPlane = startingCameraFarClipPlane; - myTransform.FindChild("plane-close").GetComponent.().materials = [origMat]; + if (myMainCamera) {myMainCamera.farClipPlane = startingCameraFarClipPlane;} + if (myBackdropRenderer) { + myBackdropRenderer.materials = [origMat]; + } iTween.ColorTo(BackdropMist,{"a":startingCloudsAlpha,"time":.5}); } function Update () { - playerTilt (); + // playerTilt moves camera on device tilt. Enable if not in VR mode, and there's no VR viewer object: + if (!FallingLaunch.isVRMode && !myVRViewer) { + playerTilt (); + } + //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); //Debug.Log("your current acceleration is: " + FallingLaunch.accelerator); } diff --git a/MoveController.js b/MoveController.js index 25bdcc4..69f2c21 100644 --- a/MoveController.js +++ b/MoveController.js @@ -35,6 +35,9 @@ var shouldChangePitch : boolean = true; static var pauseButtonArea : Rect; +static var horizAxisInversionVal : int; +static var vertAxisInversionVal : int; + function Awake() { myTransform = transform; script = GetComponent("ScoreController"); @@ -45,6 +48,10 @@ function Awake() { function Start() { + // HACK: Force landscape left orientation for Cardboard compatibility. + // TODO: make conditional on isVRMode? + Screen.orientation = ScreenOrientation.LandscapeLeft; + // Screen.sleepTimeout = 0.0f; // deprecated, now should use NeverSleep Screen.sleepTimeout = SleepTimeout.NeverSleep; @@ -102,8 +109,12 @@ if (FallingPlayer.isAlive == 1 && FallingLaunch.tiltable == true) { dir.x = 4 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * -((FallingLaunch.accelerator.y) * Mathf.Abs(FallingLaunch.accelerator.y)); dir.z = 3 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * ((FallingLaunch.accelerator.x) * Mathf.Abs(FallingLaunch.accelerator.x)); - dir.x = FallingLaunch.invertHorizAxisVal * Mathf.Clamp(dir.x, -2.0, 2.0); - dir.z = FallingLaunch.invertVertAxisVal * Mathf.Clamp(dir.z, -2.0, 2.0); + // Ignore axis inversion prefs if in VR mode: + horizAxisInversionVal = FallingLaunch.isVRMode ? 1 : FallingLaunch.invertHorizAxisVal; + vertAxisInversionVal = FallingLaunch.isVRMode ? 1 : FallingLaunch.invertVertAxisVal; + + dir.x = horizAxisInversionVal * Mathf.Clamp(dir.x, -2.0, 2.0); + dir.z = vertAxisInversionVal * Mathf.Clamp(dir.z, -2.0, 2.0); myTransform.Translate (dir * speed, Space.World); } diff --git a/setVRMode.js b/setVRMode.js new file mode 100644 index 0000000..5a1c84c --- /dev/null +++ b/setVRMode.js @@ -0,0 +1,20 @@ +#pragma strict + +function Start () { + // NOTE: Would be best to perform these lookups elsewhere, but + // due to JS/C# interactions and compilation order it's less feasible. + // http://answers.unity3d.com/questions/507580/bce0019-enabled-is-not-a-member-of-unityenginecomp-3.html + var VRViewer = GetComponent("GvrViewer"); + + if (FallingLaunch.isVRMode && VRViewer) { + (VRViewer as MonoBehaviour).enabled = true; // type coersion required to access 'enabled' + } + + if (!FallingLaunch.isVRMode) { + gameObject.SetActive(false); // disable our own gameObject to stop blank viewer from rendering + } +} + +function Update () { + +} From 7059d1c164f3955dd23c69d62b8c00b6b9bec059 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 5 Jan 2017 23:12:21 -0500 Subject: [PATCH 02/77] Clean up getVRMode for Cardboard gameObject detection --- setVRMode.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/setVRMode.js b/setVRMode.js index 5a1c84c..e51743b 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -1,20 +1,20 @@ #pragma strict +private var VRViewer : Component; + function Start () { // NOTE: Would be best to perform these lookups elsewhere, but // due to JS/C# interactions and compilation order it's less feasible. // http://answers.unity3d.com/questions/507580/bce0019-enabled-is-not-a-member-of-unityenginecomp-3.html - var VRViewer = GetComponent("GvrViewer"); + // Also better to use a type below, not a string, but it's necessary due to C# + JS: + // https://docs.unity3d.com/ScriptReference/Component.GetComponent.html + VRViewer = GetComponent("GvrViewer"); if (FallingLaunch.isVRMode && VRViewer) { - (VRViewer as MonoBehaviour).enabled = true; // type coersion required to access 'enabled' + (VRViewer as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' } if (!FallingLaunch.isVRMode) { gameObject.SetActive(false); // disable our own gameObject to stop blank viewer from rendering } -} - -function Update () { - -} +} \ No newline at end of file From f5426d849c887e5e3aa01445fb4c0550e0c077ea Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 6 Jan 2017 01:07:33 -0500 Subject: [PATCH 03/77] Refactor MoveController --- MoveController.js | 96 ++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 60 deletions(-) diff --git a/MoveController.js b/MoveController.js index 69f2c21..8aaeeda 100644 --- a/MoveController.js +++ b/MoveController.js @@ -35,9 +35,6 @@ var shouldChangePitch : boolean = true; static var pauseButtonArea : Rect; -static var horizAxisInversionVal : int; -static var vertAxisInversionVal : int; - function Awake() { myTransform = transform; script = GetComponent("ScoreController"); @@ -95,34 +92,33 @@ function FixedUpdate () { // if (dir.sqrMagnitude > 1) // dir.Normalize(); -if (FallingPlayer.isAlive == 1 && FallingLaunch.tiltable == true) { + if (FallingPlayer.isAlive == 1 && FallingLaunch.tiltable == true) { + + // TODO: Don't use accelerometer-derived movement at all in VR mode! + // But for now, ignore axis inversion prefs in VR mode: + if (FallingLaunch.isVRMode) {movePlayer(1, 1);} + else { + // Or use the axis settings from player prefs: + movePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); + } + } + else {dir = Vector3.zero;} - // Make it move 10 meters per second instead of 10 meters per frame... - // .:. not necessary in fixedupdate - // dir *= Time.deltaTime; - // print("Your dir is: " + dir); - - //myTransform.Translate (dir * speed, Space.World); +} + +function movePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { FallingLaunch.hasSetAccel = true; FallingLaunch.accelerator = FallingLaunch.calibrationRotation * Input.acceleration; //Debug.Log(FallingLaunch.accelerator); dir.x = 4 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * -((FallingLaunch.accelerator.y) * Mathf.Abs(FallingLaunch.accelerator.y)); - dir.z = 3 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * ((FallingLaunch.accelerator.x) * Mathf.Abs(FallingLaunch.accelerator.x)); - - // Ignore axis inversion prefs if in VR mode: - horizAxisInversionVal = FallingLaunch.isVRMode ? 1 : FallingLaunch.invertHorizAxisVal; - vertAxisInversionVal = FallingLaunch.isVRMode ? 1 : FallingLaunch.invertVertAxisVal; + dir.z = 3 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * ((FallingLaunch.accelerator.x) * Mathf.Abs(FallingLaunch.accelerator.x)); dir.x = horizAxisInversionVal * Mathf.Clamp(dir.x, -2.0, 2.0); - dir.z = vertAxisInversionVal * Mathf.Clamp(dir.z, -2.0, 2.0); + dir.z = vertAxisInversionVal * Mathf.Clamp(dir.z, -2.0, 2.0); myTransform.Translate (dir * speed, Space.World); } -else {dir = Vector3.zero;} - -} - function SmoothSlowdown () { isSlowing = true; @@ -140,17 +136,17 @@ function SmoothSlowdown () { } function ChangeSpeed ( i : int ) { -Slowdown = i; -// Debug.Log("Your current speed score is " + ScoreController.visibleScore); + Slowdown = i; + // Debug.Log("Your current speed score is " + ScoreController.visibleScore); } function ResumeSpeed () { -isSlowing = false; + isSlowing = false; } function Update () { fallingSpeed(); -// Debug.Log("Slowdown = " + Slowdown); + // Debug.Log("Slowdown = " + Slowdown); } // I also tried moving fallingSpeed function to fixedUpdate, but it actually made the game slower, @@ -185,7 +181,9 @@ function fallingSpeed () { if (fingerCount > 0) { //speedUp(); - if (Slowdown < 1) {speedingUp = 2; Slowdown = maxSlowdown; speedsUp(); + if (Slowdown < 1) { + speedingUp = 2; Slowdown = maxSlowdown; + speedsUp(); //GA.API.Design.NewEvent("Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); } //if (Slowdown < 1) @@ -220,41 +218,19 @@ function fallingSpeed () { } function speedsUp () { - if (speedingUp == 2) { - speedingUp = 1; - //SpeedLinesTextureScript.LinesFlash (0.25, FadeDir.In); - SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); - FallingPlayer.UIscriptComponent.showThreatBar(1); - if (audioSource && shouldChangePitch == true) {lerpPitchUp(.5, 2, .3);} - } - else { - //SpeedLinesTextureScript.LinesFlashOut (0.75, FadeDir.In); - SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); - FallingPlayer.UIscriptComponent.hideThreatBar(.5); - if (audioSource && shouldChangePitch == true && changingPitch == false) {lerpPitchDown(1, 1, 1);} -} -} - -function speedUp () { - Slowdown = maxSlowdown; - Camera.main.SendMessage("speedLinesUp"); -// SendMessage is slow; rephrase if I ever use this speedUp method again. - -// UIscriptComponent.speedLinesNow(); - -// if (speedingUp == true) { -// SpeedLinesTextureScript.FadeFlash (0.25, FadeDir.In); -// yield WaitForSeconds(.25);} -// else { -// SpeedLinesTextureScript.FadeFlash (0.5, FadeDir.Out); -// yield WaitForSeconds(.5);} -} - -function speedDown () { - Slowdown = 0; - //SpeedLinesTextureScript.LinesFlash (1.0, FadeDir.Out); - SpeedLinesMeshScript.LinesFlash (1.0, FadeDir.Out); - yield WaitForSeconds(1.0); + if (speedingUp == 2) { + speedingUp = 1; + //SpeedLinesTextureScript.LinesFlash (0.25, FadeDir.In); + SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); + FallingPlayer.UIscriptComponent.showThreatBar(1); + if (audioSource && shouldChangePitch == true) {lerpPitchUp(.5, 2, .3);} + } + else { + //SpeedLinesTextureScript.LinesFlashOut (0.75, FadeDir.In); + SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); + FallingPlayer.UIscriptComponent.hideThreatBar(.5); + if (audioSource && shouldChangePitch == true && changingPitch == false) {lerpPitchDown(1, 1, 1);} + } } function slowDown () { From 5933c66c3f1dde8d9404399aabe28f16e9914ab1 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 6 Jan 2017 01:31:16 -0500 Subject: [PATCH 04/77] Reparent camera in VR to allow looking forward, not down --- MoveController.js | 4 +++- setVRMode.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/MoveController.js b/MoveController.js index 8aaeeda..b4eed00 100644 --- a/MoveController.js +++ b/MoveController.js @@ -96,7 +96,9 @@ function FixedUpdate () { // TODO: Don't use accelerometer-derived movement at all in VR mode! // But for now, ignore axis inversion prefs in VR mode: - if (FallingLaunch.isVRMode) {movePlayer(1, 1);} + if (FallingLaunch.isVRMode) { + movePlayer(1, 1); + } else { // Or use the axis settings from player prefs: movePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); diff --git a/setVRMode.js b/setVRMode.js index e51743b..4796994 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -1,5 +1,9 @@ #pragma strict +var GvrViewerMainObject : GameObject; +var cameraVRParent : GameObject; + +private var cameraObj : GameObject; private var VRViewer : Component; function Start () { @@ -8,13 +12,17 @@ function Start () { // http://answers.unity3d.com/questions/507580/bce0019-enabled-is-not-a-member-of-unityenginecomp-3.html // Also better to use a type below, not a string, but it's necessary due to C# + JS: // https://docs.unity3d.com/ScriptReference/Component.GetComponent.html - VRViewer = GetComponent("GvrViewer"); + VRViewer = GvrViewerMainObject.GetComponent("GvrViewer"); + cameraObj = transform.FindChild("Camera").gameObject; + if (FallingLaunch.isVRMode && VRViewer) { (VRViewer as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' + // Re-parent camera for 90deg tilt offset (so player can look forward in VR): + cameraObj.transform.parent = cameraVRParent.transform; } if (!FallingLaunch.isVRMode) { - gameObject.SetActive(false); // disable our own gameObject to stop blank viewer from rendering + GvrViewerMainObject.SetActive(false); // disable the GvrViewerMain gameObject to stop blank viewer from rendering } } \ No newline at end of file From 8db3b55ef2a1b6a09c9295386b90bd1f5d5a271a Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 7 Jan 2017 12:35:24 -0500 Subject: [PATCH 05/77] Improve VR positioning/movement; add optional recentering; clean up Camera refs --- AudioVolumeInterpolate.js | 2 +- FallingPlayer.js | 2 +- MoveController.js | 128 +++++++++++++++++++------------------- changeBackdrop.js | 2 +- setVRMode.js | 22 +++++-- 5 files changed, 83 insertions(+), 73 deletions(-) diff --git a/AudioVolumeInterpolate.js b/AudioVolumeInterpolate.js index dd8cd69..5753ff8 100644 --- a/AudioVolumeInterpolate.js +++ b/AudioVolumeInterpolate.js @@ -14,7 +14,7 @@ function Start () { aSource = GetComponent(AudioSource); aSource.volume = 0f; // findPlayer(); - player = GameObject.Find("Player/Camera").transform; + player = Camera.main.transform; } function OnTriggerEnter (other : Collider) { diff --git a/FallingPlayer.js b/FallingPlayer.js index adc7c16..215ad39 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -95,7 +95,7 @@ function Awake() { } function Start() { - myMainCamera = myTransform.FindChild("Camera").GetComponent.(); + myMainCamera = Camera.main; myBackdrop = GameObject.Find("plane-close"); BackdropMist = GameObject.Find("Cylinder"); myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; diff --git a/MoveController.js b/MoveController.js index b4eed00..d4393fd 100644 --- a/MoveController.js +++ b/MoveController.js @@ -1,10 +1,6 @@ #pragma strict -public var force:float = 1.0; -public var simulateAccelerometer:boolean = false; -public var touchedBy:boolean = false; var dir : Vector3 = Vector3.zero; -var endPoint = 0.0; var touch : Touch; var fingerCount = 0; @@ -18,12 +14,15 @@ static var isSlowing : boolean = false; static var speedingUp : int = 1; static var controlMultiplier : float = 1; +private var controlModifierTotal : float; -var mainCamera : GameObject; -var script : ScoreController; +var mainCameraObj : GameObject; +private var mainCamera : Camera; + +private var myHead : GvrHead; +var GvrViewerMainObject : GameObject; // In each scene, manually add the GvrViewerMain obj via Inspector -var SpeedLinesTexture : GameObject; -var SpeedLinesTextureScript : GUITextureLaunch; +var script : ScoreController; var SpeedLinesMesh : GameObject; static var SpeedLinesMeshScript : SpeedLines; @@ -38,7 +37,6 @@ static var pauseButtonArea : Rect; function Awake() { myTransform = transform; script = GetComponent("ScoreController"); - SpeedLinesTextureScript = SpeedLinesTexture.GetComponent("GUITextureLaunch"); SpeedLinesMeshScript = SpeedLinesMesh.GetComponent("SpeedLines"); } @@ -47,60 +45,50 @@ function Start() { // HACK: Force landscape left orientation for Cardboard compatibility. // TODO: make conditional on isVRMode? + // Or is this best off just being removed? + // NB: If your phone is tilted a little beyond flat (away from you) on level load, + // then all other game objects will be behind you when you look up: 180deg wrong + // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse + // quaternion in some cases based on Head gaze direction/ gameObj position, + // or in the menu UI, ensure the phone orientation is not flat before + // letting the user load the scene... Screen.orientation = ScreenOrientation.LandscapeLeft; -// Screen.sleepTimeout = 0.0f; -// deprecated, now should use NeverSleep + // Screen.sleepTimeout = 0.0f; + // deprecated, now should use NeverSleep Screen.sleepTimeout = SleepTimeout.NeverSleep; startTime = Time.time; Slowdown = FallingLaunch.levelEndSlowdown; - mainCamera = transform.FindChild("Camera").gameObject; + if (mainCameraObj) { + mainCamera = mainCameraObj.GetComponent.(); + } + else { // if it wasn't set already via the Inspector UI... + mainCameraObj = GameObject.FindWithTag("MainCamera"); + mainCamera = Camera.main; + } + audioSource = mainCamera.GetComponent.(); - + //Calibrate(); lerpSlowdown(.5); lerpControl(3); //pauseButtonArea = Rect(0, 0, Screen.width / 2, Screen.height / 2); pauseButtonArea = Rect(Screen.width * .9, Screen.height * .8, Screen.width * .1, Screen.height * .2); + } function FixedUpdate () { var dir : Vector3 = Vector3.zero; - -// if (simulateAccelerometer) -// { - // using joystick input instead of iPhone accelerometer -// dir.x = Input.GetAxis("Horizontal"); -// dir.z = Input.GetAxis("Vertical"); -// } -// else - - // we assume that device is held parallel to the ground - // and Home button is in the right hand - - // remap device acceleration axis to game coordinates - // 1) XY plane of the device is mapped onto XZ plane - // 2) rotated 90 degrees around Y axis - // dir.x = -Input.acceleration.y; -// dir.z = Input.acceleration.x; - -// print("Your X and Z accel are: " + dir.x + ", " + dir.z); - - // clamp acceleration vector to unit sphere -// if (dir.sqrMagnitude > 1) -// dir.Normalize(); - if (FallingPlayer.isAlive == 1 && FallingLaunch.tiltable == true) { - - // TODO: Don't use accelerometer-derived movement at all in VR mode! - // But for now, ignore axis inversion prefs in VR mode: - if (FallingLaunch.isVRMode) { - movePlayer(1, 1); + // In VR mode, use Cardboard gaze direction (e.g. as applied to head object) + // to determine any movement that's not downwards/gravity-driven: + if (FallingLaunch.isVRMode && GvrViewerMainObject) { + if (myHead) {movePlayerVR();} } else { - // Or use the axis settings from player prefs: + // if not in VR mode, call movePlayer and honor the playerPrefs axis settings: movePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); } } @@ -108,6 +96,29 @@ function FixedUpdate () { } +function movePlayerVR () { + // Using TransformDirection so it's in world space, not local. + controlModifierTotal = FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier; + dir.x = 3 * transform.TransformDirection(myHead.Gaze.direction).x * controlModifierTotal; + dir.z = 3 * transform.TransformDirection(myHead.Gaze.direction).z * controlModifierTotal; + + // Debug.Log('head direction: ' + myHead.Gaze.direction); + // Debug.Log('dir x pre-clamping ' + dir.x); + // Debug.Log('dir z pre-clamping ' + dir.z); + + // Only using X and Z: no y-traversal in world axis, + // since scene gravity handles the Y dimension. + dir.x = Mathf.Clamp(dir.x, -2.0, 2.0); + dir.z = Mathf.Clamp(dir.z, -2.0, 2.0); + + // Debug.Log('dir x final ' + dir.x); + // Debug.Log('dir z final ' + dir.z); + + // Clamped to 2 units/frame (and avoiding speed multiplier) to keep it as + // more 'realistic' 1:1 movement, with just a little amplification: + myTransform.Translate (dir, Space.World); +} + function movePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { FallingLaunch.hasSetAccel = true; FallingLaunch.accelerator = FallingLaunch.calibrationRotation * Input.acceleration; @@ -147,6 +158,14 @@ function ResumeSpeed () { } function Update () { + // TODO: make coroutine instead? http://answers.unity3d.com/answers/1281517/view.html + // Find head for VR (can't live in Start because the GVR plugin takes > 1 frame to set up): + if (FallingLaunch.isVRMode && GvrViewerMainObject && !myHead) { + if (mainCameraObj.GetComponent.()) { + myHead = mainCameraObj.GetComponent.().Head; + } + } + fallingSpeed(); // Debug.Log("Slowdown = " + Slowdown); } @@ -182,39 +201,29 @@ function fallingSpeed () { if (fingerCount > 0) { - //speedUp(); if (Slowdown < 1) { speedingUp = 2; Slowdown = maxSlowdown; speedsUp(); //GA.API.Design.NewEvent("Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); } - //if (Slowdown < 1) - //{speedingUp = 2; speedsUp(); Slowdown = maxSlowdown; } } else if (fingerCount < 1) { - // slowDown(); - //if (Slowdown > 0) {speedDown(); yield;} - //Slowdown = 0; if (Slowdown > 0) { speedingUp = 0; speedsUp(); lerpSlowdown(.5); } - //else if (Slowdown > 0) {speedingUp = 0; speedsUp(); } } } else { Slowdown = 0; speedingUp = 1; - //SpeedLinesTextureScript.LinesOff(); SpeedLinesMeshScript.LinesOff(); - //mainCamera.audio.pitch = 1; - //mainCamera.audio.volume = 1; if (shouldChangePitch == true && changingPitch == false) {lerpPitchDown(.5, 1, 1);} dir = Vector3.zero; FallingPlayer.UIscriptComponent.hideThreatBar(0.1); } -// Debug.Log("Slowdown = " + Slowdown + ", speedingUp = " + speedingUp ); -// Debug.Log("You have " + fingerCount + " fingers touching the screen." ); + // Debug.Log("Slowdown = " + Slowdown + ", speedingUp = " + speedingUp ); + // Debug.Log("You have " + fingerCount + " fingers touching the screen." ); GetComponent.().relativeForce = (Vector3.down * Slowdown); } @@ -222,13 +231,11 @@ function fallingSpeed () { function speedsUp () { if (speedingUp == 2) { speedingUp = 1; - //SpeedLinesTextureScript.LinesFlash (0.25, FadeDir.In); SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); FallingPlayer.UIscriptComponent.showThreatBar(1); if (audioSource && shouldChangePitch == true) {lerpPitchUp(.5, 2, .3);} } else { - //SpeedLinesTextureScript.LinesFlashOut (0.75, FadeDir.In); SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); FallingPlayer.UIscriptComponent.hideThreatBar(.5); if (audioSource && shouldChangePitch == true && changingPitch == false) {lerpPitchDown(1, 1, 1);} @@ -259,7 +266,6 @@ function lerpSlowdown (timer : float) { if (Slowdown > 17999) {break;} } yield WaitForSeconds (timer); - //speedingUp = 1; } @@ -310,12 +316,6 @@ function lerpPitchDown (timer : float, endPitch : float, endVolume : float) { changingPitch = false; } -function SpeedLinesOff (timer : float) { - SpeedLinesTextureScript.FadeOut (timer); - yield WaitForSeconds(timer); - SpeedLinesTextureScript.LinesOff(); -} - function lerpControl(timer : float) { var start = 0.0; diff --git a/changeBackdrop.js b/changeBackdrop.js index ea8fd49..2c4715a 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -32,7 +32,7 @@ var farClipPlaneFadeTime2 : float = 2; function Start () { if (oceanLevel == true) { - mainCamera = transform.FindChild("Camera").gameObject; + if (!mainCamera) {mainCamera = transform.FindChild("Camera").gameObject;} oceanCamera = transform.FindChild("Camera-for-ocean").gameObject; backdropMist = transform.FindChild("Cylinder").gameObject; diff --git a/setVRMode.js b/setVRMode.js index 4796994..5ccd3af 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -3,8 +3,10 @@ var GvrViewerMainObject : GameObject; var cameraVRParent : GameObject; -private var cameraObj : GameObject; -private var VRViewer : Component; +var cameraObj : GameObject; +private var VRViewerComponent : Component; +var VRViewer : GvrViewer; +private var hasCentered : boolean = false; function Start () { // NOTE: Would be best to perform these lookups elsewhere, but @@ -12,14 +14,22 @@ function Start () { // http://answers.unity3d.com/questions/507580/bce0019-enabled-is-not-a-member-of-unityenginecomp-3.html // Also better to use a type below, not a string, but it's necessary due to C# + JS: // https://docs.unity3d.com/ScriptReference/Component.GetComponent.html - VRViewer = GvrViewerMainObject.GetComponent("GvrViewer"); + VRViewerComponent = GvrViewerMainObject.GetComponent("GvrViewer"); - cameraObj = transform.FindChild("Camera").gameObject; + if (!cameraObj) {cameraObj = transform.FindChild("Camera").gameObject;} - if (FallingLaunch.isVRMode && VRViewer) { - (VRViewer as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' + if (FallingLaunch.isVRMode && VRViewerComponent) { + (VRViewerComponent as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' // Re-parent camera for 90deg tilt offset (so player can look forward in VR): cameraObj.transform.parent = cameraVRParent.transform; + + // center cardboard view post-instantiation: + // TODO: This recentering needs some kind of rotational offset to account for the parent head's 90-degree (we want to map 'forward' in cardboard to 'down' in world space) + // if (!hasCentered) { + // VRViewer = GvrViewerMainObject.GetComponent.(); + // VRViewer.Instance.Recenter(); + // hasCentered = true; + // } } if (!FallingLaunch.isVRMode) { From 05d9e0a75945a8541afea89097e7a48214d97671 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 7 Jan 2017 15:30:46 -0500 Subject: [PATCH 06/77] Refactor screen press speedup for VR --- FallingPlayer.js | 4 +- MoveController.js | 262 +++++++++++++++++++++++++++------------------- 2 files changed, 158 insertions(+), 108 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 215ad39..8f3a5ed 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -265,8 +265,8 @@ function changeLevelBackdrop () { } function Update () { - // playerTilt moves camera on device tilt. Enable if not in VR mode, and there's no VR viewer object: - if (!FallingLaunch.isVRMode && !myVRViewer) { + // playerTilt moves camera on device tilt. Enable if not in VR mode: + if (!FallingLaunch.isVRMode) { playerTilt (); } diff --git a/MoveController.js b/MoveController.js index d4393fd..503c0e7 100644 --- a/MoveController.js +++ b/MoveController.js @@ -1,6 +1,5 @@ #pragma strict -var dir : Vector3 = Vector3.zero; var touch : Touch; var fingerCount = 0; @@ -9,6 +8,16 @@ private var startTime : float; static var Slowdown : int = 0; static var maxSlowdown : float = 18000.0; +static var lateralSpeedBoost : float = 0.0; +static var maxLateralSpeed : float = 1.5; + +var forceComponent : ConstantForce; + +private var extraForceRaw : Vector3; +var extraForce : Vector3; +private var clampedModifierVR : float; + +private var dir : Vector3 = Vector3.zero; var speed : float = 2.4; static var isSlowing : boolean = false; static var speedingUp : int = 1; @@ -35,16 +44,17 @@ var shouldChangePitch : boolean = true; static var pauseButtonArea : Rect; function Awake() { - myTransform = transform; - script = GetComponent("ScoreController"); - SpeedLinesMeshScript = SpeedLinesMesh.GetComponent("SpeedLines"); + myTransform = transform; + script = GetComponent("ScoreController"); + SpeedLinesMeshScript = SpeedLinesMesh.GetComponent("SpeedLines"); + forceComponent = GetComponent.(); + extraForce = Vector3.zero; } function Start() { - // HACK: Force landscape left orientation for Cardboard compatibility. - // TODO: make conditional on isVRMode? + // HACK: Force landscape left orientation in VR for Cardboard compatibility. // Or is this best off just being removed? // NB: If your phone is tilted a little beyond flat (away from you) on level load, // then all other game objects will be behind you when you look up: 180deg wrong @@ -52,13 +62,13 @@ function Start() { // quaternion in some cases based on Head gaze direction/ gameObj position, // or in the menu UI, ensure the phone orientation is not flat before // letting the user load the scene... - Screen.orientation = ScreenOrientation.LandscapeLeft; + if (FallingLaunch.isVRMode) {Screen.orientation = ScreenOrientation.LandscapeLeft;} - // Screen.sleepTimeout = 0.0f; - // deprecated, now should use NeverSleep - Screen.sleepTimeout = SleepTimeout.NeverSleep; + // Screen.sleepTimeout = 0.0f; + // deprecated, now should use NeverSleep + Screen.sleepTimeout = SleepTimeout.NeverSleep; startTime = Time.time; - Slowdown = FallingLaunch.levelEndSlowdown; + Slowdown = FallingLaunch.levelEndSlowdown; if (mainCameraObj) { mainCamera = mainCameraObj.GetComponent.(); @@ -67,36 +77,40 @@ function Start() { mainCameraObj = GameObject.FindWithTag("MainCamera"); mainCamera = Camera.main; } - - audioSource = mainCamera.GetComponent.(); + + audioSource = mainCamera.GetComponent.(); - //Calibrate(); + //Calibrate(); - lerpSlowdown(.5); - lerpControl(3); - //pauseButtonArea = Rect(0, 0, Screen.width / 2, Screen.height / 2); - pauseButtonArea = Rect(Screen.width * .9, Screen.height * .8, Screen.width * .1, Screen.height * .2); + lerpSlowdown(.5); + lerpControl(3); + //pauseButtonArea = Rect(0, 0, Screen.width / 2, Screen.height / 2); + pauseButtonArea = Rect(Screen.width * .9, Screen.height * .8, Screen.width * .1, Screen.height * .2); } function FixedUpdate () { - var dir : Vector3 = Vector3.zero; + dir = Vector3.zero; + + // Address any x/z movement due to device tilts or VR head gaze positon: if (FallingPlayer.isAlive == 1 && FallingLaunch.tiltable == true) { // In VR mode, use Cardboard gaze direction (e.g. as applied to head object) // to determine any movement that's not downwards/gravity-driven: if (FallingLaunch.isVRMode && GvrViewerMainObject) { - if (myHead) {movePlayerVR();} + if (myHead) { MovePlayerVR(); } } else { // if not in VR mode, call movePlayer and honor the playerPrefs axis settings: - movePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); + MovePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); } } else {dir = Vector3.zero;} + // Address any speedups due to screen presses: + FallingSpeed(); } -function movePlayerVR () { +function MovePlayerVR () { // Using TransformDirection so it's in world space, not local. controlModifierTotal = FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier; dir.x = 3 * transform.TransformDirection(myHead.Gaze.direction).x * controlModifierTotal; @@ -114,12 +128,18 @@ function movePlayerVR () { // Debug.Log('dir x final ' + dir.x); // Debug.Log('dir z final ' + dir.z); - // Clamped to 2 units/frame (and avoiding speed multiplier) to keep it as - // more 'realistic' 1:1 movement, with just a little amplification: - myTransform.Translate (dir, Space.World); + // Cap the lateral speed (it should be translation, not a force, + // so you don't keep moving after you lift the trigger): + lateralSpeedBoost = Mathf.Max((Slowdown/maxSlowdown) * maxLateralSpeed, 0.0); + // Debug.Log('lateralSpeedBoost: ' + lateralSpeedBoost); + + // Clamped to 2 units/frame (and avoiding speed multiplier) to obtain + // more 'realistic' 1:1 movement, with just a little amplification, + // and with lateralSpeedBoost as the extra if you're touching the screen. + myTransform.Translate (dir * (1.0 + lateralSpeedBoost), Space.World); } -function movePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { +function MovePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { FallingLaunch.hasSetAccel = true; FallingLaunch.accelerator = FallingLaunch.calibrationRotation * Input.acceleration; //Debug.Log(FallingLaunch.accelerator); @@ -134,7 +154,7 @@ function movePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { function SmoothSlowdown () { - isSlowing = true; + isSlowing = true; iTween.ValueTo ( gameObject, { "from" : maxSlowdown, @@ -150,7 +170,7 @@ function SmoothSlowdown () { function ChangeSpeed ( i : int ) { Slowdown = i; - // Debug.Log("Your current speed score is " + ScoreController.visibleScore); + // Debug.Log("Your current speed score is " + ScoreController.visibleScore); } function ResumeSpeed () { @@ -165,90 +185,120 @@ function Update () { myHead = mainCameraObj.GetComponent.().Head; } } - - fallingSpeed(); - // Debug.Log("Slowdown = " + Slowdown); + // fallingSpeed(); + // Debug.Log("Slowdown = " + Slowdown); } +// Old perf note (moved fallingSpeed to fixedUpdate on 1/7/2017): // I also tried moving fallingSpeed function to fixedUpdate, but it actually made the game slower, // since iOS is usually 30fps and fixedUpdate needs to run at 50fps (0.02 fixed timestep) for // decent collision detection. -function fallingSpeed () { - - fingerCount = 0; - - if (FallingPlayer.isAlive == 1 && FallingPlayer.isPausable == true) { - //for (touch in Input.touches) { - // if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) { - for (var i = 0; i < Input.touchCount; ++i) { - if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { - fingerCount++; - - if (pauseButtonArea.Contains(Input.GetTouch(i).position)) { - // Debug.Log("Returning!"); - return; - } - - // if (pauseButtonArea.Contains(touch.position)) { - // Debug.Log("Touching pause area!"); - // } - // else { - // Debug.Log("Not in pause area."); - // } - } - } - - - if (fingerCount > 0) { - if (Slowdown < 1) { +function FallingSpeed () { + + fingerCount = 0; + + if (FallingPlayer.isAlive == 1 && FallingPlayer.isPausable == true) { + //for (touch in Input.touches) { + // if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) { + for (var i = 0; i < Input.touchCount; ++i) { + if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { + fingerCount++; + + if (pauseButtonArea.Contains(Input.GetTouch(i).position)) { + // Debug.Log("Returning!"); + return; + } + + // if (pauseButtonArea.Contains(touch.position)) { + // Debug.Log("Touching pause area!"); + // } + // else { + // Debug.Log("Not in pause area."); + // } + } + } + + + if (fingerCount > 0) { + if (Slowdown < 1) { speedingUp = 2; Slowdown = maxSlowdown; speedsUp(); - //GA.API.Design.NewEvent("Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); - } - - } - else if (fingerCount < 1) { - if (Slowdown > 0) { speedingUp = 0; speedsUp(); lerpSlowdown(.5); } - } - } - - else { - Slowdown = 0; - speedingUp = 1; - SpeedLinesMeshScript.LinesOff(); - if (shouldChangePitch == true && changingPitch == false) {lerpPitchDown(.5, 1, 1);} - dir = Vector3.zero; - FallingPlayer.UIscriptComponent.hideThreatBar(0.1); - } - - // Debug.Log("Slowdown = " + Slowdown + ", speedingUp = " + speedingUp ); - // Debug.Log("You have " + fingerCount + " fingers touching the screen." ); - - GetComponent.().relativeForce = (Vector3.down * Slowdown); + //GA.API.Design.NewEvent("Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); + } + + } + else if (fingerCount < 1) { + if (Slowdown > 0) { speedingUp = 0; speedsUp(); lerpSlowdown(.5); } + } + } + + else { + Slowdown = 0; + speedingUp = 1; + SpeedLinesMeshScript.LinesOff(); + if (shouldChangePitch == true && changingPitch == false) {lerpPitchDown(.5, 1, 1);} + dir = Vector3.zero; + FallingPlayer.UIscriptComponent.hideThreatBar(0.1); + } + + // Debug.Log("Slowdown = " + Slowdown + ", speedingUp = " + speedingUp ); + // Debug.Log("You have " + fingerCount + " fingers touching the screen." ); + + // if (myHead) {Debug.Log('myHead.Gaze.direction: ' + myHead.Gaze.direction);} + + // In non-VR mode, relativeForce assumes the Player GameObject transform is tilted + // (by the device accelerometer) in space; it relies on device tilt + // to provide some worldspace lateral speedup to the local (relative) down vector. + + // In VR, the head's gaze direction supplies our y vector, which is attenuated + // based on the gaze x/z (clampedModifierVR). + // That vector is multiplied by Slowdown to get a final downwards force. + + // The x/z movement during a speed boost is handled in MovePlayerVR, since applying + // sideways forces pushes the player too far away from the main level. + if (myHead) { + extraForceRaw = myHead.Gaze.direction; + Debug.Log('extraForceRaw: ' + extraForceRaw); + + clampedModifierVR = + Mathf.Max(Mathf.Abs(myHead.Gaze.direction.x), Mathf.Abs(myHead.Gaze.direction.z)); + // Debug.Log('clampedModifierVR: ' + clampedModifierVR); + extraForce = Vector3.ClampMagnitude(extraForceRaw, (1.0 - clampedModifierVR)); + + // Mutate into a downwards vector that insists on negative y values + // (so you can't fly upwards). + extraForce = Vector3(0, Mathf.Min(extraForce.y, 0.0) * Slowdown, 0); + } + else { + extraForce = Vector3.down * Slowdown; + } + + Debug.Log('extraForce: ' + extraForce); + forceComponent.relativeForce = extraForce; } function speedsUp () { - if (speedingUp == 2) { - speedingUp = 1; - SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); - FallingPlayer.UIscriptComponent.showThreatBar(1); - if (audioSource && shouldChangePitch == true) {lerpPitchUp(.5, 2, .3);} - } - else { - SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); - FallingPlayer.UIscriptComponent.hideThreatBar(.5); - if (audioSource && shouldChangePitch == true && changingPitch == false) {lerpPitchDown(1, 1, 1);} - } + if (speedingUp == 2) { + speedingUp = 1; + SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); + FallingPlayer.UIscriptComponent.showThreatBar(1); + if (audioSource && shouldChangePitch == true) {lerpPitchUp(.5, 2, .3);} + } + else { + SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); + FallingPlayer.UIscriptComponent.hideThreatBar(.5); + if (audioSource && shouldChangePitch == true && changingPitch == false) {lerpPitchDown(1, 1, 1);} + } } function slowDown () { if ((Slowdown > 0) && (isSlowing == false)) { - SmoothSlowdown (); - } - else {Slowdown = 0;} -// the above Slowdown = 0 statement breaks the tweened slowdown, but prevents a nasty bug where newly-loaded levels don't slow properly -// else { Camera.main.SendMessage("speedLinesDown"); } + SmoothSlowdown (); + } + else {Slowdown = 0;} +// the above Slowdown = 0 statement breaks the tweened slowdown, but prevents a nasty bug where newly-loaded levels don't slow properly +// else { Camera.main.SendMessage("speedLinesDown"); } } function lerpSlowdown (timer : float) { @@ -264,7 +314,7 @@ function lerpSlowdown (timer : float) { yield; if (Slowdown > 17999) {break;} - } + } yield WaitForSeconds (timer); } @@ -287,7 +337,7 @@ function lerpPitchUp (timer : float, endPitch : float, endVolume : float) { yield; if (Slowdown < 1) {break;} - } + } yield WaitForSeconds (timer); } @@ -310,7 +360,7 @@ function lerpPitchDown (timer : float, endPitch : float, endVolume : float) { yield; if (Slowdown > 17999) {changingPitch = false; break;} - } + } yield WaitForSeconds (timer); changingPitch = false; @@ -328,14 +378,14 @@ function lerpControl(timer : float) { i += step * Time.deltaTime; controlMultiplier = Mathf.Lerp(start, end, i); yield; - //Debug.Log("My flipmultiplier is " + FallingLaunch.flipMultiplier + " and my end is " + end); - } + //Debug.Log("My flipmultiplier is " + FallingLaunch.flipMultiplier + " and my end is " + end); + } yield WaitForSeconds (timer); } function Calibrate () { - FallingLaunch.tiltable = false; - var acceleratorSnapshot = Input.acceleration; - FallingLaunch.calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, FallingLaunch.restPosition); - FallingLaunch.tiltable = true; + FallingLaunch.tiltable = false; + var acceleratorSnapshot = Input.acceleration; + FallingLaunch.calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, FallingLaunch.restPosition); + FallingLaunch.tiltable = true; } \ No newline at end of file From 5160ff90cd2170aefc3932e052bcf92dcf73d519 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 7 Jan 2017 16:03:45 -0500 Subject: [PATCH 07/77] Clarify approach to VR speedup calculations --- MoveController.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/MoveController.js b/MoveController.js index 503c0e7..8bfae47 100644 --- a/MoveController.js +++ b/MoveController.js @@ -9,15 +9,15 @@ private var startTime : float; static var Slowdown : int = 0; static var maxSlowdown : float = 18000.0; static var lateralSpeedBoost : float = 0.0; -static var maxLateralSpeed : float = 1.5; +static var maxLateralSpeed : float = 0.5; var forceComponent : ConstantForce; -private var extraForceRaw : Vector3; -var extraForce : Vector3; +private var extraForceRaw = Vector3.zero; +var extraForce = Vector3.zero; private var clampedModifierVR : float; -private var dir : Vector3 = Vector3.zero; +private var dir = Vector3.zero; var speed : float = 2.4; static var isSlowing : boolean = false; static var speedingUp : int = 1; @@ -48,7 +48,6 @@ function Awake() { script = GetComponent("ScoreController"); SpeedLinesMeshScript = SpeedLinesMesh.GetComponent("SpeedLines"); forceComponent = GetComponent.(); - extraForce = Vector3.zero; } @@ -245,27 +244,30 @@ function FallingSpeed () { // Debug.Log("Slowdown = " + Slowdown + ", speedingUp = " + speedingUp ); // Debug.Log("You have " + fingerCount + " fingers touching the screen." ); - // if (myHead) {Debug.Log('myHead.Gaze.direction: ' + myHead.Gaze.direction);} - // In non-VR mode, relativeForce assumes the Player GameObject transform is tilted // (by the device accelerometer) in space; it relies on device tilt // to provide some worldspace lateral speedup to the local (relative) down vector. - // In VR, the head's gaze direction supplies our y vector, which is attenuated - // based on the gaze x/z (clampedModifierVR). + // In VR, the head's gaze direction supplies our y vector, which is attenuated + // based on the gaze x/z (clampedModifierVR). // That vector is multiplied by Slowdown to get a final downwards force. - // The x/z movement during a speed boost is handled in MovePlayerVR, since applying + // Any x/z movement during a speed boost is handled in MovePlayerVR, since applying // sideways forces pushes the player too far away from the main level. if (myHead) { extraForceRaw = myHead.Gaze.direction; - Debug.Log('extraForceRaw: ' + extraForceRaw); + // Debug.Log('extraForceRaw: ' + extraForceRaw); + // Debug.Log('myHead.Gaze.direction: ' + myHead.Gaze.direction); clampedModifierVR = Mathf.Max(Mathf.Abs(myHead.Gaze.direction.x), Mathf.Abs(myHead.Gaze.direction.z)); - // Debug.Log('clampedModifierVR: ' + clampedModifierVR); extraForce = Vector3.ClampMagnitude(extraForceRaw, (1.0 - clampedModifierVR)); - + // Debug.Log('clampedModifierVR: ' + clampedModifierVR); + + // If you wanted to directly set the downward vector, + // you could use set extraForce.y to be myHead.Gaze.direction.y below... + // but the attenuated version is easier on the neck to control! + // Mutate into a downwards vector that insists on negative y values // (so you can't fly upwards). extraForce = Vector3(0, Mathf.Min(extraForce.y, 0.0) * Slowdown, 0); @@ -274,7 +276,7 @@ function FallingSpeed () { extraForce = Vector3.down * Slowdown; } - Debug.Log('extraForce: ' + extraForce); + // Debug.Log('extraForce: ' + extraForce); forceComponent.relativeForce = extraForce; } From ab5b0be266ed55d0e48edaada4f7eefdaefd3d09 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 7 Jan 2017 18:33:20 -0500 Subject: [PATCH 08/77] Auto-instantiate and parent main VR camera --- FallingLaunch.js | 6 +++--- MoveController.js | 38 ++++---------------------------------- SpeedLines.js | 8 ++++---- setVRMode.js | 21 ++++++++++++++++----- 4 files changed, 27 insertions(+), 46 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 286c690..e9374c4 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -1,7 +1,7 @@ #pragma strict -static var flipMultiplier : float = 1; +static var flipMultiplier : float = 1.0; static var landscapeFlipped : boolean = false; -static var levelEndSlowdown : int = 0; +static var levelEndSlowdown : float = 0.0; static var alreadyLaunched : boolean = false; static var hasSetOrientation : boolean = false; static var NewGamePlus : boolean = false; @@ -26,7 +26,7 @@ static var invertVertAxisVal : int; static var LoadedLatestLevel : boolean = false; static var levelAchieved : int; -static var debugMode : boolean = false; +static var debugMode : boolean = true; //false; var testFlightToken : String; diff --git a/MoveController.js b/MoveController.js index 8bfae47..840c724 100644 --- a/MoveController.js +++ b/MoveController.js @@ -6,7 +6,7 @@ var fingerCount = 0; private var myTransform : Transform; private var startTime : float; -static var Slowdown : int = 0; +static var Slowdown : float = 0.0; static var maxSlowdown : float = 18000.0; static var lateralSpeedBoost : float = 0.0; static var maxLateralSpeed : float = 0.5; @@ -19,7 +19,6 @@ private var clampedModifierVR : float; private var dir = Vector3.zero; var speed : float = 2.4; -static var isSlowing : boolean = false; static var speedingUp : int = 1; static var controlMultiplier : float = 1; @@ -151,31 +150,11 @@ function MovePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { myTransform.Translate (dir * speed, Space.World); } -function SmoothSlowdown () { - - isSlowing = true; - iTween.ValueTo ( gameObject, - { - "from" : maxSlowdown, - "to" : 0, - "onupdate" : "ChangeSpeed", - "time" : 1, - "easetype": "easeOutExpo", - "oncomplete": "ResumeSpeed" - } - ); - -} - function ChangeSpeed ( i : int ) { Slowdown = i; // Debug.Log("Your current speed score is " + ScoreController.visibleScore); } -function ResumeSpeed () { - isSlowing = false; -} - function Update () { // TODO: make coroutine instead? http://answers.unity3d.com/answers/1281517/view.html // Find head for VR (can't live in Start because the GVR plugin takes > 1 frame to set up): @@ -219,13 +198,13 @@ function FallingSpeed () { } - if (fingerCount > 0) { + if (fingerCount > 0) { if (Slowdown < 1) { - speedingUp = 2; Slowdown = maxSlowdown; + Slowdown = maxSlowdown; + speedingUp = 2; speedsUp(); //GA.API.Design.NewEvent("Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); } - } else if (fingerCount < 1) { if (Slowdown > 0) { speedingUp = 0; speedsUp(); lerpSlowdown(.5); } @@ -294,15 +273,6 @@ function speedsUp () { } } -function slowDown () { - if ((Slowdown > 0) && (isSlowing == false)) { - SmoothSlowdown (); - } - else {Slowdown = 0;} -// the above Slowdown = 0 statement breaks the tweened slowdown, but prevents a nasty bug where newly-loaded levels don't slow properly -// else { Camera.main.SendMessage("speedLinesDown"); } -} - function lerpSlowdown (timer : float) { var start = Slowdown; diff --git a/SpeedLines.js b/SpeedLines.js index e49eab8..c57efee 100644 --- a/SpeedLines.js +++ b/SpeedLines.js @@ -31,8 +31,8 @@ function FadeFlash (timer : float, fadeType : FadeDir) { function LinesFlash (timer : float, fadeType : FadeDir) { - var start = fadeType == FadeDir.In? speedLinesMaterial.color.a : peakValue; - var end = fadeType == FadeDir.In? peakValue : 0.0; + var start = (fadeType == FadeDir.In) ? speedLinesMaterial.color.a : peakValue; + var end = (fadeType == FadeDir.In) ? peakValue : 0.0; var audioStart = speedLinesAudio2.volume; var audioEnd = 1.0; var i = 0.0; @@ -63,8 +63,8 @@ function LinesFlash (timer : float, fadeType : FadeDir) { function LinesFlashOut (timer : float, fadeType : FadeDir) { - var start = fadeType == FadeDir.In? 0.0 : peakValue; - var end = fadeType == FadeDir.In? speedLinesMaterial.color.a : 0.0; + var start = (fadeType == FadeDir.In) ? 0.0 : peakValue; + var end = (fadeType == FadeDir.In) ? speedLinesMaterial.color.a : 0.0; var audioStart = speedLinesAudio2.volume; var audioEnd = 0.0; var i = 0.0; diff --git a/setVRMode.js b/setVRMode.js index 5ccd3af..8928cda 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -1,13 +1,20 @@ #pragma strict var GvrViewerMainObject : GameObject; -var cameraVRParent : GameObject; + +// should be a prefab tilted 90 degrees in X axis, so the user faces forward in headset: +var cameraVRParentPrefab : GameObject; +private var cameraVRParent : GameObject; var cameraObj : GameObject; private var VRViewerComponent : Component; -var VRViewer : GvrViewer; +// var VRViewer : GvrViewer; private var hasCentered : boolean = false; +function Awake () { + if (!cameraObj) {cameraObj = transform.FindChild("Camera").gameObject;} +} + function Start () { // NOTE: Would be best to perform these lookups elsewhere, but // due to JS/C# interactions and compilation order it's less feasible. @@ -16,12 +23,16 @@ function Start () { // https://docs.unity3d.com/ScriptReference/Component.GetComponent.html VRViewerComponent = GvrViewerMainObject.GetComponent("GvrViewer"); - if (!cameraObj) {cameraObj = transform.FindChild("Camera").gameObject;} - if (FallingLaunch.isVRMode && VRViewerComponent) { (VRViewerComponent as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' // Re-parent camera for 90deg tilt offset (so player can look forward in VR): - cameraObj.transform.parent = cameraVRParent.transform; + cameraVRParent = + Instantiate(cameraVRParentPrefab); + + // Make the camera-VR-parent object (post-instantiation) a child of this (player) gameObject transform, + // then make the Camera (cameraObj) a child of the camera-VR-parent object: + cameraVRParent.transform.SetParent(transform); + cameraObj.transform.SetParent(cameraVRParent.transform); // center cardboard view post-instantiation: // TODO: This recentering needs some kind of rotational offset to account for the parent head's 90-degree (we want to map 'forward' in cardboard to 'down' in world space) From 96cea0958649ba378281f6d3f76f3314e0620d01 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 11 Jan 2017 23:00:07 -0500 Subject: [PATCH 09/77] Restore FallingSpeed to FixedUpdate for proper touch start and end detection --- MoveController.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MoveController.js b/MoveController.js index 840c724..b9e9d30 100644 --- a/MoveController.js +++ b/MoveController.js @@ -104,8 +104,8 @@ function FixedUpdate () { } else {dir = Vector3.zero;} - // Address any speedups due to screen presses: - FallingSpeed(); + // Address any speedups due to screen presses in FixedUpdate, not here! + // FallingSpeed(); } function MovePlayerVR () { @@ -163,7 +163,8 @@ function Update () { myHead = mainCameraObj.GetComponent.().Head; } } - // fallingSpeed(); + + FallingSpeed(); // Debug.Log("Slowdown = " + Slowdown); } From 520a1d981a31fb9f2d562b27e825e7d16b7e36d8 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Tue, 5 Sep 2017 21:37:49 -0700 Subject: [PATCH 10/77] Toggle GVR toolkit via VRModeEnabled instance property --- FallingLaunch.js | 2 +- setVRMode.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index e9374c4..ceba182 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -49,7 +49,7 @@ enum iPads { }; function Awake () { - isVRMode = true; // TODO: Let user pick this via UI + isVRMode = false; // TODO: Let user pick this via UI } function Start () { diff --git a/setVRMode.js b/setVRMode.js index 8928cda..b2ae344 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -22,9 +22,10 @@ function Start () { // Also better to use a type below, not a string, but it's necessary due to C# + JS: // https://docs.unity3d.com/ScriptReference/Component.GetComponent.html VRViewerComponent = GvrViewerMainObject.GetComponent("GvrViewer"); - + if (FallingLaunch.isVRMode && VRViewerComponent) { (VRViewerComponent as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' + (VRViewerComponent as GvrViewer).VRModeEnabled = true; // Re-parent camera for 90deg tilt offset (so player can look forward in VR): cameraVRParent = Instantiate(cameraVRParentPrefab); @@ -41,6 +42,8 @@ function Start () { // VRViewer.Instance.Recenter(); // hasCentered = true; // } + } else if (VRViewerComponent) { + (VRViewerComponent as GvrViewer).VRModeEnabled = false; } if (!FallingLaunch.isVRMode) { From e847d98ea95fbf5350cbef1fdcc2e49dbfc01502 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Tue, 19 Sep 2017 23:54:41 -0700 Subject: [PATCH 11/77] Fix level 4 fog clearing at end --- EndSequence1stPerson.js | 8 ++- FallingPlayer.js | 11 +++- changeBackdrop.js | 110 ++++++++++++++++++++++++++++------------ 3 files changed, 93 insertions(+), 36 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index fc73a19..adbb72d 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -19,6 +19,8 @@ var UIscriptEndMenuComponent : FallingEndMenuUI; var outroCompletedOrb : GameObject; var outroCompletionPoint : GameObject; +var anim : Animation; + function Start () { PlayerController = GetComponent("MoveController"); ScoreController = GetComponent("ScoreController"); @@ -26,6 +28,8 @@ function Start () { MusicBedInterpolated = OutroMusicBedObject.GetComponent("AudioVolumeInterpolate"); UIscriptEndMenuComponent = UIscriptEndMenuName.GetComponent("FallingEndMenuUI"); EndTriggerComponent = EndTriggerName.GetComponent("EndSequenceTrigger"); + + anim = GetComponent.(); } function PlayOutro () { @@ -54,7 +58,9 @@ function PlayOutro () { //LerpIntoDiamond(14); MusicBedInterpolated.falsifyCheckDistance(); FadeMusic(8, OutroMusicBed); - GetComponent.().Play("end-player-anim"); + + anim.Play("end-player-anim"); // TODO: FIXME + EndTriggerComponent.AddDiamondCore(5); yield WaitForSeconds (1); EndTriggerComponent.AddDiamond3DCore(6); diff --git a/FallingPlayer.js b/FallingPlayer.js index 8f3a5ed..4c395e8 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -3,6 +3,7 @@ // 2 = 255 for rgba in this color array static var startingFogColor : Color = Color(1.17, 1.17, 1.17, 2); static var startingFogEndDistance : int = 1500; +static var startingFogStartDistance : int = 150; static var startingCameraFarClipPlane : int = 1700; static var startingCloudsAlpha : float = .25f; // Unity 4 used .39f (99 in RGBA) @@ -104,6 +105,8 @@ function Start() { // startingFogColor = RenderSettings.fogColor * 2; startingFogEndDistance = RenderSettings.fogEndDistance; + startingFogStartDistance = RenderSettings.fogStartDistance; + startingCameraFarClipPlane = myMainCamera.farClipPlane; isAlive = 1; UIscriptComponent = UIscriptName.GetComponent(fallingUITest); @@ -197,6 +200,7 @@ function DeathRespawn () { isAlive = 1; RenderSettings.fogEndDistance = startingFogEndDistance; + RenderSettings.fogStartDistance = startingFogStartDistance; // Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); @@ -228,7 +232,8 @@ function LatestCheckpointRespawn () { isAlive = 1; RenderSettings.fogEndDistance = startingFogEndDistance; - + RenderSettings.fogStartDistance = startingFogStartDistance; + GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); myTransform.position = respawnPosition; // + Vector3.up; @@ -257,11 +262,13 @@ function changeLevelBackdrop () { // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); RenderSettings.fogEndDistance = startingFogEndDistance; + RenderSettings.fogStartDistance = startingFogStartDistance; + if (myMainCamera) {myMainCamera.farClipPlane = startingCameraFarClipPlane;} if (myBackdropRenderer) { myBackdropRenderer.materials = [origMat]; } - iTween.ColorTo(BackdropMist,{"a":startingCloudsAlpha,"time":.5}); + iTween.ColorTo(BackdropMist,{"a": startingCloudsAlpha,"time": .5}); } function Update () { diff --git a/changeBackdrop.js b/changeBackdrop.js index 2c4715a..ba02331 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -1,7 +1,6 @@ #pragma strict var newMat : Material; - var origMat : Material; var fadeTex : Texture2D; @@ -9,15 +8,23 @@ var fadeTex : Texture2D; var mainCamera : GameObject; var cam : Camera; +var closePlaneTransform : Transform; +static var closePlaneRenderer : Renderer; +var cloudCylinderObj : GameObject; +static var cloudCylinderRenderer : Renderer; + +static var startingCloudAlpha : float; // Unity 4 used .39f (99 in RGBA) +var newCloudAlpha : float = .3f; +static var cloudOriginalMaterial : Material; + static var oceanCamera : GameObject; -var backdropMist : GameObject; static var oceanRenderer : Renderer; static var cloudRenderer : Renderer; static var endSphereRenderer : Renderer; + //var foo : Material; //set this in the editor //var bar : Material; //set this in the editor var oceanLevel : boolean = false; -var mistLevel : boolean = false; var ShouldUseOceanCamera : boolean = false; var ShouldChangeBackdrop : boolean = false; var FogOnly : boolean = false; @@ -30,12 +37,10 @@ var fogEndValue2 : int = 1500; var farClipPlaneFadeTime2 : float = 2; function Start () { - if (oceanLevel == true) { if (!mainCamera) {mainCamera = transform.FindChild("Camera").gameObject;} oceanCamera = transform.FindChild("Camera-for-ocean").gameObject; - backdropMist = transform.FindChild("Cylinder").gameObject; oceanRenderer = gameObject.Find("sky-water-ocean/Mesh").GetComponent.(); oceanRenderer.enabled = false; @@ -45,47 +50,76 @@ function Start () { endSphereRenderer = gameObject.Find("score-orbs-end/score-orb/Mesh").GetComponent.(); endSphereRenderer.enabled = false; - } + } - if (mistLevel == true) { - backdropMist = transform.FindChild("Cylinder").gameObject; - } cam = mainCamera.GetComponent.(); + + // Warn re. plane-close/Cylinder if they haven't been manually associated via the Inspector: + if (ShouldChangeBackdrop || oceanLevel) { + if (!cloudCylinderObj) { + Debug.Log('Did you forget to link your cloudCylinderObj in the Inspector?'); + } + if (cloudCylinderObj) { + cloudCylinderRenderer = cloudCylinderObj.GetComponent.(); + cloudOriginalMaterial = cloudCylinderRenderer.material; + startingCloudAlpha = cloudOriginalMaterial.color.a; // Storing for later use. + } + + if (!closePlaneTransform) { + closePlaneTransform = transform.Find("plane-close"); + } + if (closePlaneTransform) { + closePlaneRenderer = closePlaneTransform.GetComponent.(); + } + } + } function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("changeBackdrop")) { -// not needed if not actually changing backdrop -// transform.Find("plane-close").renderer.materials = [newMat]; - if (ShouldChangeBackdrop == true) { - transform.Find("plane-close").GetComponent.().materials = [newMat];} + if (ShouldChangeBackdrop && closePlaneRenderer) { + closePlaneRenderer.materials = [newMat]; + } + + if ((ShouldChangeBackdrop || oceanLevel) && cloudOriginalMaterial) { + iTween.ColorTo(cloudCylinderObj,{"a": newCloudAlpha, "time": 1}); + } // FadeBetweenCameras (); // Enable the above method to re-add the fade 2d image backdrop on trigger enter. -// Debug.Log("You hit a changeBackdrop trigger!"); + // Debug.Log("You hit a changeBackdrop trigger! " + other.gameObject); FadeCameraFarClipPlane (1); - if (FogOnly == true) {SmoothFogFade (1);} + if (FogOnly == true) {SmoothFogFade (3);} if (ShouldUseOceanCamera == true) {enableOceanCamera(); SmoothFogFade (1);} - else if (mistLevel == true) {iTween.ColorTo(backdropMist,{"a":0.0f,"time":4});} } else if (other.gameObject.CompareTag ("changeBackdrop2")) { - //Debug.Log("You hit an alt changeBackdrop trigger!"); + // Debug.Log("You hit an alt changeBackdrop trigger!"); FadeCameraFarClipPlane (2); if (FogOnly == true) {SmoothFogFade (2);} if (ShouldUseOceanCamera == true) {enableOceanCamera(); SmoothFogFade (2);} - else if (mistLevel == true) {iTween.ColorTo(backdropMist,{"a":0.0f,"time":4});} } } +function OnTriggerExit (other : Collider) { + if (other.gameObject.CompareTag ("changeBackdrop") && cloudCylinderObj && + ShouldChangeBackdrop == true && closePlaneRenderer) { + closePlaneRenderer.materials = [origMat]; + + // Restore old clouds alpha on death: + if ((ShouldChangeBackdrop || oceanLevel) && cloudOriginalMaterial) { + iTween.ColorTo(cloudCylinderObj,{"a": startingCloudAlpha, "time": .5}); + } + } +} + function changeCameraFadeLayer() { var cameraFadeObject : GameObject = GameObject.Find ("iTween Camera Fade"); - if(cameraFadeObject) - cameraFadeObject.layer = 4; + if (cameraFadeObject) {cameraFadeObject.layer = 4;} } function FadeCameraFarClipPlane (type : int) { @@ -114,7 +148,6 @@ function FadeCameraFarClipPlane (type : int) { function SmoothFogFade (type : int) { if (type == 2) { - iTween.ValueTo ( gameObject, { "from" : FallingPlayer.startingFogEndDistance, @@ -123,9 +156,7 @@ function SmoothFogFade (type : int) { "time" : farClipPlaneFadeTime2, "easetype" : "easeInExpo" }); - } - else { - + } else if (type == 2) { iTween.ValueTo ( gameObject, { "from" : FallingPlayer.startingFogEndDistance, @@ -135,7 +166,24 @@ function SmoothFogFade (type : int) { "easetype" : "easeInExpo" // "oncomplete" : "CameraFadeEnd" }); - } + } else if (type == 3) { + iTween.ValueTo ( gameObject, + { + "from" : FallingPlayer.startingFogStartDistance, + "to" : fogEndValue - 100, // Effectively zeroes out fog + "onupdate" : "ChangeFogStartDistance", + "time" : 3, + "easetype" : "easeInExpo" + }); + iTween.ValueTo ( gameObject, + { + "from" : FallingPlayer.startingFogEndDistance, + "to" : fogEndValue, + "onupdate" : "ChangeFogEndDistance", + "time" : 3, + "easetype" : "easeInExpo" + }); + } } @@ -153,7 +201,10 @@ function CameraFadeEnd () { function ChangeFogEndDistance (i : int) { RenderSettings.fogEndDistance = i; - //RenderSettings.fogStartDistance = .5*i; +} + +function ChangeFogStartDistance (i : int) { + RenderSettings.fogStartDistance = i; } function ChangeCameraFarClipPlane (i : int) { @@ -165,11 +216,4 @@ function enableOceanCamera () { oceanRenderer.enabled = true; cloudRenderer.enabled = true; endSphereRenderer.enabled = true; - iTween.ColorTo(backdropMist,{"a":0.0f,"time":4}); -} - -function OnTriggerExit (other : Collider) { - if (other.gameObject.CompareTag ("changeBackdrop") && ShouldChangeBackdrop == true) { - transform.Find("plane-close").GetComponent.().materials = [origMat]; - } } \ No newline at end of file From a71a0f3f3c4a5b655d6bdf25d8a6341019051986 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 20 Sep 2017 21:54:23 -0700 Subject: [PATCH 12/77] Level 4 ending animation via iTween --- EndSequence1stPerson.js | 40 ++++++++++++++++++++++++++++++++++------ EndSequenceTrigger.js | 8 ++++++-- SpeedLines.js | 2 -- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index adbb72d..9ef5a07 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -19,8 +19,6 @@ var UIscriptEndMenuComponent : FallingEndMenuUI; var outroCompletedOrb : GameObject; var outroCompletionPoint : GameObject; -var anim : Animation; - function Start () { PlayerController = GetComponent("MoveController"); ScoreController = GetComponent("ScoreController"); @@ -29,7 +27,10 @@ function Start () { UIscriptEndMenuComponent = UIscriptEndMenuName.GetComponent("FallingEndMenuUI"); EndTriggerComponent = EndTriggerName.GetComponent("EndSequenceTrigger"); - anim = GetComponent.(); + + // Skip to the outro for testing. + // Make sure to disable EndSequenceTrigger's PlayOutro call so they don't compete: + // PlayOutro(); } function PlayOutro () { @@ -55,18 +56,31 @@ function PlayOutro () { LerpTowardsDiamond(10); RotateTowardsDiamond(10); yield WaitForSeconds (10); - //LerpIntoDiamond(14); + + // LerpIntoDiamond(14); MusicBedInterpolated.falsifyCheckDistance(); FadeMusic(8, OutroMusicBed); - anim.Play("end-player-anim"); // TODO: FIXME + // 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", "easeInOutSine" + )); + // 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); + yield WaitForSeconds (6); ScoreController.enabled = true; LifeController.enabled = true; @@ -105,6 +119,20 @@ function LerpTowardsDiamond (timer : float) { 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; + transform.rotation = Quaternion.Slerp(startRotation, endRotation, i); + + yield; + } +} + function RotateTowardsDiamond (timer : float) { var i = 0.0; var step = 1.0/timer; diff --git a/EndSequenceTrigger.js b/EndSequenceTrigger.js index 1060664..1219303 100644 --- a/EndSequenceTrigger.js +++ b/EndSequenceTrigger.js @@ -25,9 +25,9 @@ function OnTriggerEnter (other : Collider) { lifeCountdown.inOutro = true; MoveController.SpeedLinesMeshScript.LinesLerpOut(3); - + if (EndScriptComponent) { - EndScriptComponent.PlayOutro(); + EndScriptComponent.PlayOutro(); } for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) @@ -50,6 +50,10 @@ function GetChildren(obj : GameObject) : Array{ return children; } +function getDiamondCenter() { + return diamondCore.transform.position; +} + function SwapDiamonds(timer : float){ FallingPlayer.ScoreFlashTextureScript.FadeFlash (3.0, FadeDir.Out); FallingPlayer.UIscriptComponent.OutroDiamondFlash(2); diff --git a/SpeedLines.js b/SpeedLines.js index c57efee..6b9ceb2 100644 --- a/SpeedLines.js +++ b/SpeedLines.js @@ -39,8 +39,6 @@ function LinesFlash (timer : float, fadeType : FadeDir) { var step = 1.0/timer; speedLinesRenderer.enabled = true; -// if (controllerITween2.speedingUp == 2) { -// if ((controllerITween2.speedingUp == 2) && (controllerITween2.Slowdown < 1)) { if (i == 0.0) { if (!speedLinesAudio1.isPlaying) {speedLinesAudio1.Play();} From daab6afae7973bbc857a77ca76c04a7aa747e4fe Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 20 Sep 2017 22:59:17 -0700 Subject: [PATCH 13/77] Use easeOutSine for ending camera easing curve --- EndSequence1stPerson.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 9ef5a07..e2d1f55 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -56,7 +56,7 @@ function PlayOutro () { LerpTowardsDiamond(10); RotateTowardsDiamond(10); yield WaitForSeconds (10); - + // LerpIntoDiamond(14); MusicBedInterpolated.falsifyCheckDistance(); FadeMusic(8, OutroMusicBed); @@ -69,7 +69,7 @@ function PlayOutro () { // "looktarget", EndTriggerComponent.getDiamondCenter(), // "axis", "y", "time", 13, - "easetype", "easeInOutSine" + "easetype", "easeOutSine" )); // start rotating player camera to end at the same time as the above tween path traveling. From 67cdb57283ed9c9442c8ea79e99d74f5237fa7ab Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 20 Sep 2017 23:45:27 -0700 Subject: [PATCH 14/77] Explain level 4 fog ending tweening --- changeBackdrop.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/changeBackdrop.js b/changeBackdrop.js index ba02331..b283321 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -167,10 +167,15 @@ function SmoothFogFade (type : int) { // "oncomplete" : "CameraFadeEnd" }); } else if (type == 3) { + // Effectively zeroes out fog via gentler distance dispersal. + // Assumes that fogEndValue is large enough that halving it + // will still place the fog start far from the camera. + var fogStartType3 : float = fogEndValue * .5; + iTween.ValueTo ( gameObject, { "from" : FallingPlayer.startingFogStartDistance, - "to" : fogEndValue - 100, // Effectively zeroes out fog + "to" : fogStartType3, "onupdate" : "ChangeFogStartDistance", "time" : 3, "easetype" : "easeInExpo" From 650aa7bd95ad193b50c25d688f5e58d849387a8e Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 21 Sep 2017 08:52:37 -0700 Subject: [PATCH 15/77] Clarify checkpoint-saving approach --- Respawn.js | 13 +++++++------ fallingStartMenuUI.js | 10 +++++----- fallingUITest.js | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Respawn.js b/Respawn.js index 80998a1..7a9f915 100644 --- a/Respawn.js +++ b/Respawn.js @@ -65,8 +65,8 @@ function Start() // Assign the respawn point to be this one - Since the player is positioned on top of a respawn point, it will come in and overwrite it. // This is just to make sure that we always have a respawn point. - //mainRespawnScript boolean is to keep multiple instances of Respawn from all trying to write - //to PlayerPrefs within a single Update call. + // mainRespawnScript boolean is to keep multiple instances of Respawn from all trying to write + // to PlayerPrefs within a single Update call. if (mainRespawnScript) { if (PlayerPrefs.HasKey("LatestLevel") && PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) { @@ -88,9 +88,6 @@ function Start() currentRespawn = initialRespawn; } } - // else { - // currentRespawn = initialRespawn; - // } SaveCheckpoint(); } @@ -109,7 +106,6 @@ function OnTriggerEnter(other : Collider) // Set the current respawn point to be us and make it visible. currentRespawn = this; - //SetActive (); } } } @@ -120,6 +116,11 @@ function OnApplicationPause(pauseStatus: boolean) { } } +// NB: We currently only persistently save checkpoints on pause +// (including app-to-background auto-pausing) and level loading. +// Writing to PlayerPrefs can be slow and introduce visual stutter, so we do NOT +// save in prefs when you pass a checkpoint during gameplay, although we do update the global +// currentRespawn var, so respawn works. function SaveCheckpoint() { if (mainRespawnScript) { myCheckpoint = currentRespawn.transform.name; diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index fccf0fd..ba582de 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -1195,8 +1195,8 @@ function AutoOrientToLandscape () { FallingLaunch.hasSetOrientation = true; } -function StopCompensatingSensors() { - //this is necessary to override Unity 4's auto-orientation code - Input.compensateSensors = false; - yield; -} \ No newline at end of file +// function StopCompensatingSensors() { +// //this is necessary to override Unity 4's auto-orientation code +// Input.compensateSensors = false; +// yield; +// } \ No newline at end of file diff --git a/fallingUITest.js b/fallingUITest.js index af049e2..b87315b 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -594,8 +594,7 @@ function LevelComplete() { player.GetComponent.().isKinematic = true; AudioListener.pause = true; Application.LoadLevel(levelToLoad); -// not necessary because Respawn.js resets the latest checkpoint in its Start -// PlayerPrefs.SetString("LatestLevel", levelToLoad); + FallingLaunch.levelAchieved = (Application.loadedLevel + 1); PlayerPrefs.SetInt("HighestLevel", (Application.loadedLevel + 1)); Time.timeScale = savedTimeScale; From e91cdbb69d05ee10a607724257be4fed0bd0b1d3 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 27 Sep 2017 23:13:38 -0700 Subject: [PATCH 16/77] Attempt to fix autorotation crashes --- fallingStartMenuUI.js | 190 +++++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 86 deletions(-) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index ba582de..2b18a7e 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -89,24 +89,42 @@ var fallingLaunchComponent : FallingLaunch; function Awake () { //Input.compensateSensors = true; - Debug.Log("My orientation is " + Screen.orientation); + Debug.Log("My screen orientation is " + Screen.orientation); //Screen.orientation = ScreenOrientation.AutoRotation; // if (FallingLaunch.hasSetOrientation == false) { // AutoOrientToLandscape(); // } if (!FallingLaunch.hasSetOrientation) { + // Just to be safe, exclude portrait modes from potential autorotation: + Screen.autorotateToPortrait = false; + Screen.autorotateToPortraitUpsideDown = false; + + // We have to use autoRotation here, due to crashes on force-changing Screen.orientation + // in conjunction with permitted-via-settings autoRotation + // (if app launches mid-screen-rotation?). + // Source: https://forum.unity.com/threads/unitydefaultviewcontroller-should-be-used-only-if-unity-is-set-to-autorotate.314542/#post-2833628 + Screen.orientation = ScreenOrientation.AutoRotation; + if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; - //Debug.Log("I'm in LandscapeRight!"); - Screen.orientation = ScreenOrientation.LandscapeRight; + // Screen.orientation = ScreenOrientation.LandscapeRight; + + // Permit [auto]rotation to landscapeRight only: + Screen.autorotateToLandscapeLeft = false; + Screen.autorotateToLandscapeRight = true; + FallingLaunch.landscapeFlipped = true; FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; - } - else { Screen.orientation = ScreenOrientation.LandscapeLeft; + } else { + // Screen.orientation = ScreenOrientation.LandscapeLeft; FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; //Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; + + // Permit [auto]rotation to landscapeLeft only: + Screen.autorotateToLandscapeLeft = true; + Screen.autorotateToLandscapeRight = false; } FallingLaunch.hasSetOrientation = true; @@ -1113,87 +1131,87 @@ function upLevel4() { } } -function SetOrientationNow() { - if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { - Screen.orientation = ScreenOrientation.LandscapeRight; - FallingLaunch.flipMultiplier = -1; - Debug.Log("I'm in LandscapeRight!"); - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; - } - else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft){ - Screen.orientation = ScreenOrientation.LandscapeLeft; - FallingLaunch.flipMultiplier = 1; - Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; - } - - //this is necessary to override Unity 4's auto-orientation code - Input.compensateSensors = false; - yield; - return; -} - - -function FixWrongInitialScreenOrientation () { - if ( (Screen.height > Screen.width && Input.deviceOrientation.ToString().ToLower().StartsWith("landscape")) - || (Screen.width > Screen.height && Input.deviceOrientation.ToString().ToLower().StartsWith("portrait")) - ) { - Debug.LogWarning("Fixing wrong screen orientation ("+ Screen.orientation +") to right device orientation: "+ Input.deviceOrientation); - switch (Input.deviceOrientation) { - case DeviceOrientation.LandscapeLeft: - Screen.orientation = ScreenOrientation.LandscapeLeft; - break; - case DeviceOrientation.LandscapeRight: - Screen.orientation = ScreenOrientation.LandscapeRight; - break; - case DeviceOrientation.PortraitUpsideDown: - Screen.orientation = ScreenOrientation.PortraitUpsideDown; - break; - case DeviceOrientation.Portrait: - Screen.orientation = ScreenOrientation.Portrait; - break; - } - } - yield; -} - -function AutoOrientToLandscape () { - - // if (Input.deviceOrientation == DeviceOrientation.FaceUp) { - // if (Screen.orientation == ScreenOrientation.LandscapeRight) { - // Debug.Log("Device is FaceUp, and ScreenOrientation is LandscapeRight"); - // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; - // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; - // } - // else { - // Debug.Log("Device is FaceUp, and ScreenOrientation is NOT LandscapeRight"); - // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; - // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; - // } - - // Screen.autorotateToLandscapeRight = false; - // Screen.autorotateToLandscapeLeft = false; - // Screen.autorotateToPortrait = false; - // Screen.autorotateToPortraitUpsideDown = false; - - // } - - if (Vector3.Dot(Input.acceleration.normalized, Vector3(1,0,0)) > 0) - //else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) - { - Screen.orientation = ScreenOrientation.LandscapeRight; - FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; - } - else if(Vector3.Dot(Input.acceleration.normalized, Vector3(-1,0,0)) > 0) - //else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) - { - Screen.orientation = ScreenOrientation.LandscapeLeft; - FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; - } - FallingLaunch.hasSetOrientation = true; -} +// function SetOrientationNow() { +// if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { +// Screen.orientation = ScreenOrientation.LandscapeRight; +// FallingLaunch.flipMultiplier = -1; +// Debug.Log("I'm in LandscapeRight!"); +// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; +// } +// else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft){ +// Screen.orientation = ScreenOrientation.LandscapeLeft; +// FallingLaunch.flipMultiplier = 1; +// Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); +// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; +// } + +// //this is necessary to override Unity 4's auto-orientation code +// Input.compensateSensors = false; +// yield; +// return; +// } + + +// function FixWrongInitialScreenOrientation () { +// if ( (Screen.height > Screen.width && Input.deviceOrientation.ToString().ToLower().StartsWith("landscape")) +// || (Screen.width > Screen.height && Input.deviceOrientation.ToString().ToLower().StartsWith("portrait")) +// ) { +// Debug.LogWarning("Fixing wrong screen orientation ("+ Screen.orientation +") to right device orientation: "+ Input.deviceOrientation); +// switch (Input.deviceOrientation) { +// case DeviceOrientation.LandscapeLeft: +// Screen.orientation = ScreenOrientation.LandscapeLeft; +// break; +// case DeviceOrientation.LandscapeRight: +// Screen.orientation = ScreenOrientation.LandscapeRight; +// break; +// case DeviceOrientation.PortraitUpsideDown: +// Screen.orientation = ScreenOrientation.PortraitUpsideDown; +// break; +// case DeviceOrientation.Portrait: +// Screen.orientation = ScreenOrientation.Portrait; +// break; +// } +// } +// yield; +// } + +// function AutoOrientToLandscape () { + +// // if (Input.deviceOrientation == DeviceOrientation.FaceUp) { +// // if (Screen.orientation == ScreenOrientation.LandscapeRight) { +// // Debug.Log("Device is FaceUp, and ScreenOrientation is LandscapeRight"); +// // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; +// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; +// // } +// // else { +// // Debug.Log("Device is FaceUp, and ScreenOrientation is NOT LandscapeRight"); +// // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; +// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; +// // } + +// // Screen.autorotateToLandscapeRight = false; +// // Screen.autorotateToLandscapeLeft = false; +// // Screen.autorotateToPortrait = false; +// // Screen.autorotateToPortraitUpsideDown = false; + +// // } + +// if (Vector3.Dot(Input.acceleration.normalized, Vector3(1,0,0)) > 0) +// //else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) +// { +// Screen.orientation = ScreenOrientation.LandscapeRight; +// FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; +// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; +// } +// else if(Vector3.Dot(Input.acceleration.normalized, Vector3(-1,0,0)) > 0) +// //else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) +// { +// Screen.orientation = ScreenOrientation.LandscapeLeft; +// FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; +// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; +// } +// FallingLaunch.hasSetOrientation = true; +// } // function StopCompensatingSensors() { // //this is necessary to override Unity 4's auto-orientation code From 22fc35480528c2b405b43432e46223f92026efd3 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 28 Sep 2017 09:12:32 -0700 Subject: [PATCH 17/77] Smoother lerping for end sequence cinematics --- EndSequence1stPerson.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index e2d1f55..cfd40a8 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -110,7 +110,8 @@ function LerpTowardsDiamond (timer : float) { while (i <= 1.0) { // transform.LookAt(diamondLookTarget); i += step * Time.deltaTime; - transform.position = Vector3.Slerp(start, end, i); + 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; @@ -127,7 +128,8 @@ function FinalRotation (timer : float) { while (i <= 1.0) { i += step * Time.deltaTime; - transform.rotation = Quaternion.Slerp(startRotation, endRotation, i); + var t : float = i*i*i * (i * (6f*i - 15f) + 10f); // smootherstep lerp + transform.rotation = Quaternion.Slerp(startRotation, endRotation, t); yield; } @@ -141,29 +143,30 @@ function RotateTowardsDiamond (timer : float) { while (i <= 1.0) { i += step * Time.deltaTime; - transform.rotation = Quaternion.Slerp(startRotation, endRotation, i); + var t : float = i*i * (3f - 2f*i); // smoothstep lerp + transform.rotation = Quaternion.Slerp(startRotation, endRotation, 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; +// 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); +// while (i <= 1.0) { +// i += step * Time.deltaTime; +// transform.position = Vector3.Slerp(start, end, i); +// transform.rotation = Quaternion.Slerp(startRotation, endRotation, i); - yield; - } +// yield; +// } -} +// } function FadeEndMenuLogo(timer:float){ From 783379cda160a2d28d58bb976d7c783813999dde Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 28 Sep 2017 20:39:48 -0700 Subject: [PATCH 18/77] Restore GameAnalytics integration, with custom design events --- EndSequence1stPerson.js | 9 ++++-- FallingPlayer.js | 18 ++++++----- MoveController.js | 5 ++- ProjectileDestroy.js | 14 ++++++--- fallingUITest.js | 68 +++++++++++++++++++++++++++++------------ lifeCountdown.js | 13 ++++++-- 6 files changed, 91 insertions(+), 36 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index cfd40a8..54d5af1 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -35,9 +35,14 @@ function Start () { function PlayOutro () { //GameAnalytics events for beating the game + var isNewGamePlus : String = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; + FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); - // GA.API.Design.NewEvent("GameComplete:" + FallingPlayer.isNewGamePlus, FallingLaunch.secondsInLevel, transform.position); - + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "GameComplete:" + isNewGamePlus, + FallingLaunch.secondsInLevel + ); + // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); // TestFlightUnity.TestFlight.PassCheckpoint( "GameComplete"); diff --git a/FallingPlayer.js b/FallingPlayer.js index 4c395e8..f070bce 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -48,7 +48,6 @@ isAlive = lifeCountdown.isAlive; static var lifeStartTime : float = 0; static var levelStartTime : float = 0; -static var isNewGamePlus : String; static var isTiltable : boolean = true; @@ -353,11 +352,10 @@ function OnCollisionEnter (collision : Collision) { if (audioDeath) {audioDeath.Play();} - // GA.API.Design.NewEvent("Death:Collision:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, myTransform.position); - - //var deathCollideEvent : GAEvent = new GAEvent("Death", "Collision", FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive); - //GoogleAnalytics.instance.Add(deathCollideEvent); - //GoogleAnalytics.instance.Dispatch(); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "Death:Collision:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsAlive + ); //Debug.Log("you died in the area " + FallingLaunch.thisLevelArea); //Debug.Log("You died in a fatal collision with " + collision.gameObject); @@ -420,10 +418,14 @@ function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("LevelEnd") && isExitingLevel == false) { isExitingLevel = true; isPausable = false; - isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; + var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - levelStartTime); - // GA.API.Design.NewEvent("LevelComplete:" + isNewGamePlus, FallingLaunch.secondsInLevel, myTransform.position); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "LevelComplete:" + isNewGamePlus, + FallingLaunch.secondsInLevel + ); + // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); // to keep you from dying after you strike the levelend trigger diff --git a/MoveController.js b/MoveController.js index b9e9d30..59de050 100644 --- a/MoveController.js +++ b/MoveController.js @@ -204,7 +204,10 @@ function FallingSpeed () { Slowdown = maxSlowdown; speedingUp = 2; speedsUp(); - //GA.API.Design.NewEvent("Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsAlive + ); } } else if (fingerCount < 1) { diff --git a/ProjectileDestroy.js b/ProjectileDestroy.js index 7b4fea2..5267093 100644 --- a/ProjectileDestroy.js +++ b/ProjectileDestroy.js @@ -13,10 +13,16 @@ function Start () { // this is so fireballs that hit the player don't interfere with newly-spawned ones in the scene. function OnCollisionEnter (collision : Collision) { if (collision.gameObject.CompareTag ("Player")) { -// throw an analytics event! - // GA.API.Design.NewEvent("Projectile:Collision:" + ProjectileName, FallingLaunch.secondsAlive, transform.position); - gameObject.GetComponent.().isKinematic = true; - Destroy(gameObject, 1); + + // throw an analytics event! + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "Projectile:Collision:" + ProjectileName, + FallingLaunch.secondsAlive + ); + + gameObject.GetComponent.().isKinematic = true; + + Destroy(gameObject, 1); } // but if one fireball hits another, destroy immediately. diff --git a/fallingUITest.js b/fallingUITest.js index b87315b..6af7f77 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -406,28 +406,51 @@ function Start () { animateProgressBar (lifeBar); // Loop (); - // GA.API.Design.NewEvent("LevelBegin:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel, transform.parent.position); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "LevelBegin:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsInLevel + ); + // Analytics reporting for tilt prefs, and horizontal/vertical axis prefs, respectively: if (FallingLaunch.restPosition == FallingLaunch.neutralPosFlat) { - // GA.API.Design.NewEvent("TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, 0.0f, transform.parent.position); - } - else if (FallingLaunch.restPosition == FallingLaunch.neutralPosVertical) { - // GA.API.Design.NewEvent("TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, 90.0f, transform.parent.position); - } - else { - // GA.API.Design.NewEvent("TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, 45.0f, transform.parent.position); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, + 0.0 + ); + } else if (FallingLaunch.restPosition == FallingLaunch.neutralPosVertical) { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, + 90.0f + ); + } else { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, + 45.0f + ); } + if (FallingLaunch.invertHorizAxisVal == 1) { - // GA.API.Design.NewEvent("AxesPreference:Horizontal:" + SceneManagement.SceneManager.GetActiveScene().name, 1.0f, transform.parent.position); - } - else if (FallingLaunch.invertHorizAxisVal == -1) { - // GA.API.Design.NewEvent("AxesPreference:Horizontal:" + SceneManagement.SceneManager.GetActiveScene().name, -1.0f, transform.parent.position); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "AxesPreference:Horizontal:" + SceneManagement.SceneManager.GetActiveScene().name, + 1.0f + ); + } else if (FallingLaunch.invertHorizAxisVal == -1) { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "AxesPreference:Horizontal:" + SceneManagement.SceneManager.GetActiveScene().name, + -1.0f + ); } + if (FallingLaunch.invertVertAxisVal == -1) { - // GA.API.Design.NewEvent("AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, -1.0f, transform.parent.position); - } - else if (FallingLaunch.invertVertAxisVal == 1) { - // GA.API.Design.NewEvent("AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, 1.0f, transform.parent.position); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, + -1.0f + ); + } else if (FallingLaunch.invertVertAxisVal == 1) { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, + 1.0f + ); } } @@ -478,7 +501,11 @@ function PauseGame() { FallingPlayer.isPausable = false; FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); - // GA.API.Design.NewEvent("GUI:PauseGame:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel, transform.parent.position); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "GUI:PauseGame:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsInLevel + ); //Debug.Log("you paused at " + transform.parent.position); circleReticle.hidden = true; @@ -563,8 +590,11 @@ function RestartLevel() { FallingPlayer.isPausable = false; // Camera.main.SendMessage("fadeOut"); //fadeOut(); - - // GA.API.Design.NewEvent("GUI:RestartLevel:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel, transform.parent.position); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "GUI:RestartLevel:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsInLevel + ); Respawn.currentRespawn = initialRespawn; HideGUI(); diff --git a/lifeCountdown.js b/lifeCountdown.js index 5fbedd7..3d9f271 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -59,12 +59,21 @@ function TickingAway (delay : float) { FallingPlayer.isPausable = false; LifeFlashTextureScript.FadeFlash (1, FadeDir.Out); FallingLaunch.secondsAlive = (Time.time - FallingPlayer.lifeStartTime); - // GA.API.Design.NewEvent("Death:Drained:"+Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive, transform.position); + //Debug.Log("You died!"); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "Death:Drained:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsAlive + ); + yield GetComponent(FallingPlayer).DeathRespawn (); GetComponent(FallingPlayer).ShowDeathHelp(); - // GameAnalytics syntax: GA.API.Design.NewEvent(String eventName, float eventValue, Vector3 trackPosition); + + // New GameAnalytics "Design" event syntax: + // GameAnalytics.NewDesignEvent (string eventName, float eventValue); + + // Original GameAnalytics syntax: GA.API.Design.NewEvent(String eventName, float eventValue, Vector3 trackPosition); } } From a2e570071640d344883cbeaf19047f94c419633c Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sun, 1 Oct 2017 22:11:44 -0700 Subject: [PATCH 19/77] Update centering of level-select icons --- MoveController.js | 8 ++++---- fallingStartMenuUI.js | 39 ++++++++++++++++++++++++++++++++++----- fallingUITest.js | 24 +++++++++++++++++++++--- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/MoveController.js b/MoveController.js index 59de050..4d842b7 100644 --- a/MoveController.js +++ b/MoveController.js @@ -204,10 +204,10 @@ function FallingSpeed () { Slowdown = maxSlowdown; speedingUp = 2; speedsUp(); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, - FallingLaunch.secondsAlive - ); + // GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + // "Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + // FallingLaunch.secondsAlive + // ); } } else if (fingerCount < 1) { diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 2b18a7e..b31e7e5 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -132,6 +132,8 @@ function Awake () { fallingLaunch = GameObject.Find("LaunchGameObject"); fallingLaunchComponent = fallingLaunch.GetComponent("FallingLaunch"); + ScreenH = Screen.height; + ScreenW = Screen.width; screenAspectRatio = (ScreenH / ScreenW); } @@ -196,10 +198,10 @@ function Start () { pauseButton.hidden = true; if (UIT.isHD == true) { - buttonScaleFactor = (((Screen.height / 2.0) - 100.0) / Screen.height); + buttonScaleFactor = (((Screen.height / 2.0) - 100.0) / Screen.height); } else { - buttonScaleFactor = (((Screen.height / 2.0) - 50.0) / Screen.height); + buttonScaleFactor = (((Screen.height / 2.0) - 50.0) / Screen.height); } boldText = new UIText( "font-bold", "font-bold.png" ); @@ -377,9 +379,32 @@ function Start () { loadLevelOne.onTouchUpInside += LoadLevel1ViaStart; loadLevelOne.onTouchUp += upLevel1; loadLevelOne.onTouchDown += downLevel1; - + + var calculatedMiddleIconRatio : float = 0.0f; + + if (ScreenW > 2200) { + calculatedMiddleIconRatio = 0.36f; + } else if (ScreenW > 1600) { + calculatedMiddleIconRatio = 0.33f; + } else if (ScreenW > 1200) { + calculatedMiddleIconRatio = 0.32f; + } else if (ScreenW > 1000) { + calculatedMiddleIconRatio = 0.31f; + } else { + calculatedMiddleIconRatio = 0.3f; + } + + var middleIconAdjustRatio : float = UIT.isHD ? calculatedMiddleIconRatio : 0.3f; + + // Debug.Log("buttonScaleFactor: " + buttonScaleFactor); + // Debug.Log("ScreenW: " + ScreenW); + // Debug.Log("calculatedMiddleIconRatio: " + calculatedMiddleIconRatio); + // Debug.Log("middleIconAdjustRatio: " + middleIconAdjustRatio); + loadLevelTwo = UIButton.create("level2.png","level2.png", 0, 0); - loadLevelTwo.positionFromTopLeft(buttonScaleFactor,0.3f); + + loadLevelTwo.positionFromTopLeft(buttonScaleFactor, middleIconAdjustRatio); + if (level2Unlocked) { loadLevelTwo.onTouchUpInside += LoadLevel2ViaStart; loadLevelTwo.onTouchUp += upLevel2; @@ -388,7 +413,11 @@ function Start () { else {loadLevelTwo.onTouchUpInside += DoNothing;} loadLevelThree = UIButton.create("level3.png","level3.png", 0, 0); - loadLevelThree.positionFromTopRight(buttonScaleFactor,0.3f); + + // var level3Space : float = (ScreenW * 0.9f) / 3.0; + + loadLevelThree.positionFromTopRight(buttonScaleFactor, middleIconAdjustRatio); + if (level3Unlocked) { loadLevelThree.onTouchUpInside += LoadLevel3ViaStart; loadLevelThree.onTouchUp += upLevel3; diff --git a/fallingUITest.js b/fallingUITest.js index 6af7f77..0daf7cf 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -80,6 +80,8 @@ private var savedTimeScale:float; // private var lifeBar = UIProgressBar.create( "lifeBarRedTest.png", 0, 0 ); function Awake () { + ScreenH = Screen.height; + ScreenW = Screen.width; screenAspectRatio = (ScreenH / ScreenW); } @@ -215,6 +217,22 @@ function Start () { nextLevelLabel.positionCenter(); nextLevelLabel.hidden = true; + var calculatedMiddleIconRatio : float = 0.0f; + + if (ScreenW > 2200) { + calculatedMiddleIconRatio = 0.36f; + } else if (ScreenW > 1600) { + calculatedMiddleIconRatio = 0.33f; + } else if (ScreenW > 1200) { + calculatedMiddleIconRatio = 0.32f; + } else if (ScreenW > 1000) { + calculatedMiddleIconRatio = 0.31f; + } else { + calculatedMiddleIconRatio = 0.3f; + } + + var middleIconAdjustRatio : float = UIT.isHD ? calculatedMiddleIconRatio : 0.3f; + if (level1 == SceneManagement.SceneManager.GetActiveScene().name) { loadLevelOne = UIButton.create("level1.png","level1.png", 0, 0); loadLevelOne.alphaTo( 0.01f, 0.75f, Easing.Sinusoidal.easeOut); @@ -241,8 +259,8 @@ function Start () { loadLevelTwo.onTouchUpInside += LoadLevel2ViaMenu; } } - loadLevelTwo.positionFromTopLeft(buttonScaleFactor,0.3f); - + loadLevelTwo.positionFromTopLeft(buttonScaleFactor, middleIconAdjustRatio); + if (level3 == SceneManagement.SceneManager.GetActiveScene().name) { loadLevelThree = UIButton.create("level3.png","level3.png", 0, 0); loadLevelThree.alphaTo( 0.01f, 0.75f, Easing.Sinusoidal.easeOut); @@ -258,7 +276,7 @@ function Start () { loadLevelThree.onTouchUpInside += LoadLevel3ViaMenu; } } - loadLevelThree.positionFromTopRight(buttonScaleFactor,0.3f); + loadLevelThree.positionFromTopRight(buttonScaleFactor, middleIconAdjustRatio); if (level4 == SceneManagement.SceneManager.GetActiveScene().name) { loadLevelFour = UIButton.create("level4.png","level4.png", 0, 0); From 870ec9d35038438179ad329d825efb4394ba8896 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sun, 1 Oct 2017 23:17:59 -0700 Subject: [PATCH 20/77] Disable debugMode --- FallingLaunch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index ceba182..6bc9132 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -26,7 +26,7 @@ static var invertVertAxisVal : int; static var LoadedLatestLevel : boolean = false; static var levelAchieved : int; -static var debugMode : boolean = true; //false; +static var debugMode : boolean = false; // true; var testFlightToken : String; @@ -77,7 +77,7 @@ function Start () { // hasSetOrientation = true; // } - //this is necessary to override Unity 4's auto-orientation code + // this is necessary to override Unity 4's auto-orientation code Input.compensateSensors = false; // NB: still doesn't work, sensor 'correctness' depends on starting device orientation as read by Cardboard. From c54ba6b409a0e8d0ae29c6516e2eefc8197145ab Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Mon, 2 Oct 2017 21:56:47 -0700 Subject: [PATCH 21/77] Support left/right device orientation with 90-degree tilt mode --- FallingLaunch.js | 14 +++++++------- FallingPlayer.js | 26 ++++++++++++++++++-------- MoveController.js | 27 +++++++++++++++------------ fallingStartMenuUI.js | 16 +++++++++++++++- 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 6bc9132..8e594d8 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -1,6 +1,5 @@ #pragma strict static var flipMultiplier : float = 1.0; -static var landscapeFlipped : boolean = false; static var levelEndSlowdown : float = 0.0; static var alreadyLaunched : boolean = false; static var hasSetOrientation : boolean = false; @@ -15,7 +14,9 @@ static var restPosition : Vector3; static var neutralPosFlat : Vector3 = Vector3(0,0,-1.0); static var neutralPosTiltedRegular : Vector3 = Vector3(.6,0,-.9); static var neutralPosTiltedFlipped : Vector3 = Vector3(-.6,0,-.9); -static var neutralPosVertical : Vector3 = Vector3(1.0,0,0.0); +static var neutralPosVerticalRegular = Vector3(1.0,0,0.0); +static var neutralPosVerticalFlipped = Vector3(-1.0,0,0.0); +static var neutralPosVertical : Vector3; static var neutralPosTilted : Vector3; static var accelerator : Vector3; static var calibrationRotation : Quaternion; @@ -58,14 +59,13 @@ function Start () { if (!alreadyLaunched) { // TestFlightUnity.TestFlight.TakeOff( testFlightToken ); - Debug.Log("Your screen orientation is " + Input.deviceOrientation + "!"); + Debug.Log("Your device orientation is " + Input.deviceOrientation + "!"); // if (!hasSetOrientation) { // if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) { // flipMultiplier = flipMultiplier * -1; // //Debug.Log("I'm in LandscapeRight!"); // Screen.orientation = ScreenOrientation.LandscapeRight; - // landscapeFlipped = true; // neutralPosTilted = neutralPosTiltedFlipped; // } // else { Screen.orientation = ScreenOrientation.LandscapeLeft; @@ -158,7 +158,7 @@ function OnLevelWasLoaded (level : int) { //Debug.Log("my loaded level is... " + Application.loadedLevelName); } -function SetAxesRotation () { +function SetAxesInversion () { if (PlayerPrefs.GetInt("invertHorizAxis", 0) == 1) {invertHorizAxisVal = -1;} else {invertHorizAxisVal = 1;} if (PlayerPrefs.GetInt("invertVertAxis", 0) == 1) {invertVertAxisVal = -1;} @@ -172,7 +172,7 @@ function Calibrate () { else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} else {restPosition = neutralPosFlat;} - SetAxesRotation(); + SetAxesInversion(); //acceleratorSnapshot = Input.acceleration; acceleratorSnapshot = Vector3(0.0,0.0,-1.0); calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition); @@ -187,7 +187,7 @@ function CalibrateInLevel () { else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} else {restPosition = neutralPosFlat;} - SetAxesRotation(); + SetAxesInversion(); calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition); tiltable = true; diff --git a/FallingPlayer.js b/FallingPlayer.js index f070bce..539c054 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -132,8 +132,10 @@ function Start() { } function LevelStartFade () { - if (PlayerPrefs.HasKey("LatestLevel") && PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) - {FallingLaunch.LoadedLatestLevel = true;} + if (PlayerPrefs.HasKey("LatestLevel") && + PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) { + FallingLaunch.LoadedLatestLevel = true; + } if (FallingLaunch.LoadedLatestLevel == false) { introFade(); @@ -273,14 +275,14 @@ function changeLevelBackdrop () { function Update () { // playerTilt moves camera on device tilt. Enable if not in VR mode: if (!FallingLaunch.isVRMode) { - playerTilt (); + playerTilt(); } //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); //Debug.Log("your current acceleration is: " + FallingLaunch.accelerator); } -function playerTilt () { +function playerTilt() { if (isTiltable == true) { var dir : Vector3 = Vector3.zero; @@ -328,13 +330,21 @@ function lerpControlOut(timer : float) { while (i <= 1.0) { i += step * Time.deltaTime; - MoveController.controlMultiplier = Mathf.Lerp(start, end, i); - if (isAlive == 0) {MoveController.controlMultiplier = start; break;} + var t : float = i*i * (3f - 2f*i); // smoothstep lerp + MoveController.controlMultiplier = Mathf.Lerp(start, end, t); + if (isAlive == 0) { + MoveController.controlMultiplier = start; + break; + } + yield; - if (i >= 1.0 || isAlive == 0) {MoveController.controlMultiplier = start; break;} - } + if (i >= 1.0 || isAlive == 0) { + MoveController.controlMultiplier = start; + break; + } + } yield WaitForSeconds (timer); } diff --git a/MoveController.js b/MoveController.js index 4d842b7..9567ad1 100644 --- a/MoveController.js +++ b/MoveController.js @@ -60,7 +60,10 @@ function Start() { // quaternion in some cases based on Head gaze direction/ gameObj position, // or in the menu UI, ensure the phone orientation is not flat before // letting the user load the scene... - if (FallingLaunch.isVRMode) {Screen.orientation = ScreenOrientation.LandscapeLeft;} + if (FallingLaunch.isVRMode) { + // TODO FIXME FOR VR MODE: see above + Screen.orientation = ScreenOrientation.LandscapeLeft; + } // Screen.sleepTimeout = 0.0f; // deprecated, now should use NeverSleep @@ -96,8 +99,7 @@ function FixedUpdate () { // to determine any movement that's not downwards/gravity-driven: if (FallingLaunch.isVRMode && GvrViewerMainObject) { if (myHead) { MovePlayerVR(); } - } - else { + } else { // if not in VR mode, call movePlayer and honor the playerPrefs axis settings: MovePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); } @@ -137,15 +139,23 @@ function MovePlayerVR () { myTransform.Translate (dir * (1.0 + lateralSpeedBoost), Space.World); } -function MovePlayer (horizAxisInversionVal: int, vertAxisInversionVal: int) { +function MovePlayer(horizAxisInversionVal: int, vertAxisInversionVal: int) { FallingLaunch.hasSetAccel = true; FallingLaunch.accelerator = FallingLaunch.calibrationRotation * Input.acceleration; - //Debug.Log(FallingLaunch.accelerator); + + // Debug.Log("MoveController FallingLaunch.calibrationRotation: " + FallingLaunch.calibrationRotation); + // Debug.Log("Input.acceleration: " + Input.acceleration); + // Debug.Log( "MoveController FallingLaunch.flipMultiplier: " + FallingLaunch.flipMultiplier ); + + // Debug.Log("MoveController FallingLaunch.accelerator: " + FallingLaunch.accelerator); + dir.x = 4 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * -((FallingLaunch.accelerator.y) * Mathf.Abs(FallingLaunch.accelerator.y)); dir.z = 3 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * ((FallingLaunch.accelerator.x) * Mathf.Abs(FallingLaunch.accelerator.x)); dir.x = horizAxisInversionVal * Mathf.Clamp(dir.x, -2.0, 2.0); dir.z = vertAxisInversionVal * Mathf.Clamp(dir.z, -2.0, 2.0); + // Debug.Log("dir.x final: " + dir.x); + // Debug.Log("dir.z final: " + dir.z); myTransform.Translate (dir * speed, Space.World); } @@ -358,10 +368,3 @@ function lerpControl(timer : float) { } yield WaitForSeconds (timer); } - -function Calibrate () { - FallingLaunch.tiltable = false; - var acceleratorSnapshot = Input.acceleration; - FallingLaunch.calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, FallingLaunch.restPosition); - FallingLaunch.tiltable = true; -} \ No newline at end of file diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index b31e7e5..52b9e86 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -90,6 +90,7 @@ function Awake () { //Input.compensateSensors = true; Debug.Log("My screen orientation is " + Screen.orientation); + //Screen.orientation = ScreenOrientation.AutoRotation; // if (FallingLaunch.hasSetOrientation == false) { // AutoOrientToLandscape(); @@ -108,23 +109,35 @@ function Awake () { if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; + + // Debug.Log("LandscapeRight FallingLaunch.flipMultiplier: " + FallingLaunch.flipMultiplier); // Screen.orientation = ScreenOrientation.LandscapeRight; // Permit [auto]rotation to landscapeRight only: Screen.autorotateToLandscapeLeft = false; Screen.autorotateToLandscapeRight = true; - FallingLaunch.landscapeFlipped = true; + // Enforce a landscape direction: + // Screen.orientation = ScreenOrientation.LandscapeRight; + FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; + FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalFlipped; } else { // Screen.orientation = ScreenOrientation.LandscapeLeft; FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; + + // Debug.Log("Non-LandscapeRight FallingLaunch.flipMultiplier: " + FallingLaunch.flipMultiplier); //Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; + FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalRegular; // Permit [auto]rotation to landscapeLeft only: Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = false; + + // Enforce a landscape direction: + // Screen.orientation = ScreenOrientation.LandscapeLeft; + } FallingLaunch.hasSetOrientation = true; @@ -845,6 +858,7 @@ function ShowTiltNeutralOptions () { function StartLevelLoad(levelName: String) { //yield StopCompensatingSensors(); fallingLaunchComponent.Calibrate(); + if (aboutToLoad == false) { aboutToLoad = true; FadeAudio (fadeTime); From 73c17a58a080dfa7263111f15c8fdc3bdcefc185 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Tue, 3 Oct 2017 00:30:29 -0700 Subject: [PATCH 22/77] Tweak levelComplete analytics event --- FallingPlayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 539c054..18ab78d 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -432,7 +432,7 @@ function OnTriggerEnter (other : Collider) { FallingLaunch.secondsInLevel = (Time.time - levelStartTime); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "LevelComplete:" + isNewGamePlus, + "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, FallingLaunch.secondsInLevel ); From 48a13a83edd9d851e01ca241d432227f1ef085e9 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 12 Oct 2017 21:41:32 -0700 Subject: [PATCH 23/77] Tablet-detection flipMultiplier optimizations --- FallingLaunch.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 8e594d8..5c7453f 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -87,8 +87,9 @@ function Start () { var iOSGen = iOS.Device.generation; - // Debug.Log("this is an " + iOSGen + " device!"); - // Debug.Log("Your screen dpi is " + Screen.dpi + "!"); + // Debug.Log("this is an " + iOSGen + " device!"); + + // Reduce target framerate for very old iOS devices: if (iOSGen == UnityEngine.iOS.DeviceGeneration.iPad1Gen || iOSGen == UnityEngine.iOS.DeviceGeneration.iPad2Gen || iOSGen == UnityEngine.iOS.DeviceGeneration.iPhone4 || iOSGen == UnityEngine.iOS.DeviceGeneration.iPodTouch4Gen || iOSGen.ToString().Contains("iPhone3G")) { @@ -98,20 +99,22 @@ function Start () { else { targetFPS = 60; } - - if (iOSGen.ToString().Contains("iPad")) { + + var screenDPI : float = Screen.dpi; + var screenWidthInInches: float = (Screen.width / screenDPI); + var screenHeightInInches: float = (Screen.height / screenDPI); + + var hasLargeScreen: boolean = screenDPI > 0 && (screenWidthInInches > 8 && screenHeightInInches > 5); + // Debug.Log("Screen DPI: " + screenDPI); + // Debug.Log("Screen width in inches: " + screenWidthInInches); + // Debug.Log("Screen height in inches: " + screenHeightInInches); + + if (iOSGen.ToString().Contains("iPad") || hasLargeScreen) { + // Debug.Log("Looks like a tablet!"); isTablet = true; - } - - if (Screen.dpi > 0) { - if ((Screen.width / Screen.dpi) > 5 || (Screen.height / Screen.dpi) > 5) { - isTablet = true; - //Debug.Log("Looks like a tablet!"); - } - else { - isTablet = false; - //Debug.Log("Based on reported screen size, not a tablet..."); - } + } else { + // Debug.Log("Based on reported screen size, not a tablet..."); + isTablet = false; } if (!Input.gyro.enabled) { @@ -121,7 +124,7 @@ function Start () { // if ((iOSGen && // (iPads.iPad1Gen | iPads.iPad2Gen | iPads.iPad3Gen | iPads.iPad4Gen | iPads.iPadMini1Gen | iPads.iPadUnknown)) != 0) { - flipMultiplier = (isTablet == true) ? (2 * flipMultiplier) : (1.5 * flipMultiplier); + flipMultiplier = isTablet ? 2 * flipMultiplier : 1.5 * flipMultiplier; DontDestroyOnLoad (this); alreadyLaunched = true; From af86ddbcd2d75237607ba19f843932dae7c1da07 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Mon, 16 Oct 2017 23:07:51 -0700 Subject: [PATCH 24/77] Delay orientation locking, with better mismatch handling --- FallingLaunch.js | 15 ++++- fallingStartMenuUI.js | 129 ++++++++++++++++++++++++++++++------------ 2 files changed, 106 insertions(+), 38 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 5c7453f..9a050fc 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -9,6 +9,9 @@ var targetFPS : int = 30; static var isTablet : boolean = false; static var tiltable : boolean = false; + +static var initialInputDeviceOrientation : DeviceOrientation; + static var hasSetAccel : boolean = false; static var restPosition : Vector3; static var neutralPosFlat : Vector3 = Vector3(0,0,-1.0); @@ -16,8 +19,8 @@ static var neutralPosTiltedRegular : Vector3 = Vector3(.6,0,-.9); static var neutralPosTiltedFlipped : Vector3 = Vector3(-.6,0,-.9); static var neutralPosVerticalRegular = Vector3(1.0,0,0.0); static var neutralPosVerticalFlipped = Vector3(-1.0,0,0.0); -static var neutralPosVertical : Vector3; -static var neutralPosTilted : Vector3; +static var neutralPosVertical : Vector3 = neutralPosVerticalRegular; +static var neutralPosTilted : Vector3 = neutralPosTiltedRegular; static var accelerator : Vector3; static var calibrationRotation : Quaternion; static var acceleratorSnapshot : Vector3; @@ -59,7 +62,11 @@ function Start () { if (!alreadyLaunched) { // TestFlightUnity.TestFlight.TakeOff( testFlightToken ); - Debug.Log("Your device orientation is " + Input.deviceOrientation + "!"); + if (Debug.isDebugBuild) { + Debug.Log("Your device orientation is " + Input.deviceOrientation + "!"); + } + + initialInputDeviceOrientation = Input.deviceOrientation; // if (!hasSetOrientation) { // if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) { @@ -80,6 +87,8 @@ function Start () { // this is necessary to override Unity 4's auto-orientation code Input.compensateSensors = false; + // Debug.Log("Device orientation after Input.compensateSensors = false is " + Input.deviceOrientation); + // NB: still doesn't work, sensor 'correctness' depends on starting device orientation as read by Cardboard. // HACK: Force landscape left orientation for Cardboard compatibility. // TODO: make conditional on isVRMode? diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 52b9e86..a53e499 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -89,7 +89,12 @@ var fallingLaunchComponent : FallingLaunch; function Awake () { //Input.compensateSensors = true; - Debug.Log("My screen orientation is " + Screen.orientation); + if (Debug.isDebugBuild) { + Debug.Log("My screen orientation is " + Screen.orientation); + + Debug.Log("My Input.deviceOrientation orientation is " + Input.deviceOrientation); + Debug.Log("Cached FallingLaunch Input.deviceOrientation is " + FallingLaunch.initialInputDeviceOrientation); + } //Screen.orientation = ScreenOrientation.AutoRotation; // if (FallingLaunch.hasSetOrientation == false) { @@ -106,39 +111,18 @@ function Awake () { // (if app launches mid-screen-rotation?). // Source: https://forum.unity.com/threads/unitydefaultviewcontroller-should-be-used-only-if-unity-is-set-to-autorotate.314542/#post-2833628 Screen.orientation = ScreenOrientation.AutoRotation; - - if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { - FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; - - // Debug.Log("LandscapeRight FallingLaunch.flipMultiplier: " + FallingLaunch.flipMultiplier); - // Screen.orientation = ScreenOrientation.LandscapeRight; - - // Permit [auto]rotation to landscapeRight only: - Screen.autorotateToLandscapeLeft = false; - Screen.autorotateToLandscapeRight = true; - - // Enforce a landscape direction: - // Screen.orientation = ScreenOrientation.LandscapeRight; - - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; - FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalFlipped; - } else { - // Screen.orientation = ScreenOrientation.LandscapeLeft; - FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; - - // Debug.Log("Non-LandscapeRight FallingLaunch.flipMultiplier: " + FallingLaunch.flipMultiplier); - //Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; - FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalRegular; - - // Permit [auto]rotation to landscapeLeft only: - Screen.autorotateToLandscapeLeft = true; - Screen.autorotateToLandscapeRight = false; - - // Enforce a landscape direction: - // Screen.orientation = ScreenOrientation.LandscapeLeft; - - } + + // on iPhones, we could probably assume input to be landscape-left most of the time, + // unless the device is known to be in landscape-right + // (the edge cases are iPads lying on a flat surface, which could have either screen orientation): + + // This function waits an [arbitrary] second for iOS's autorotation to settle, then locks it. + // It's not yielded, so it doesn't delay execution of the `hasSetOrientation = true` below. + LockDeviceOrientation(1.0f); + + if (Debug.isDebugBuild) { + Debug.Log("My final screen orientation is " + Screen.orientation); + } FallingLaunch.hasSetOrientation = true; } @@ -150,6 +134,81 @@ function Awake () { screenAspectRatio = (ScreenH / ScreenW); } +function LockDeviceOrientation (waitTime: float) { + // iOS/Unity can give strange/wrong orientation values while screen is mid-rotation + //or close to flat, so we manually add a wait yield. + yield WaitForSeconds(waitTime); + + Screen.autorotateToLandscapeLeft = false; + Screen.autorotateToLandscapeRight = false; + + switch (Input.deviceOrientation) { + case DeviceOrientation.LandscapeLeft: + LockLandscapeLeftOrientation(); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeLeft", 0.0); + break; + case DeviceOrientation.LandscapeRight: + LockLandscapeRightOrientation(); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeRight", 0.0); + break; + default: + HandleDeviceOrientationMismatch(); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationCheck:NonLandscape:" + Input.deviceOrientation, 0.0); + break; + } + + return; +} + + +function HandleDeviceOrientationMismatch() { + if (FallingLaunch.initialInputDeviceOrientation != Input.deviceOrientation) { + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "DeviceOrientationCheck:CachedAndCurrentMismatch:" + Input.deviceOrientation + ":" + FallingLaunch.initialInputDeviceOrientation, + 0.0 + ); + + if (FallingLaunch.initialInputDeviceOrientation == DeviceOrientation.LandscapeLeft) { + if (Debug.isDebugBuild) { + Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape left..."); + } + LockLandscapeLeftOrientation(); + } else if (FallingLaunch.initialInputDeviceOrientation == DeviceOrientation.LandscapeRight) { + if (Debug.isDebugBuild) { + Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape right..."); + } + LockLandscapeRightOrientation(); + } + + } else { + if (Debug.isDebugBuild) { + Debug.Log( + "No need to manually set Screen.orientation, since initialInputDeviceOrientation and Input.deviceOrientation do match, as " + Input.deviceOrientation + ); + } + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:CachedAndCurrentMatch:" + Input.deviceOrientation, 0.0); + } + + return; +} + +function LockLandscapeLeftOrientation () { + Screen.orientation = ScreenOrientation.LandscapeLeft; + FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; + FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalRegular; +} + +function LockLandscapeRightOrientation () { + Screen.orientation = ScreenOrientation.LandscapeRight; + FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; + FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalFlipped; + FallingLaunch.flipMultiplier = -FallingLaunch.flipMultiplier; +} + function Start () { if (PlayerPrefs.HasKey("HighestLevel") == false) { @@ -519,7 +578,7 @@ function Start () { yield WaitForSeconds (1); canShowStart = true; // ShowStart(); - } +} function ShowStart() { tiltWarning.hidden = true; From 97869360847fcf28f1c4a22a473207e3da2736ca Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 18 Oct 2017 00:02:10 -0700 Subject: [PATCH 25/77] Lerp player speed down on level completion; clean up timings --- FallingPlayer.js | 84 ++++++++++++++++++++++++++++++++-------- MoveController.js | 6 ++- SimpleVelocityLimiter.js | 6 ++- fallingUITest.js | 16 ++++---- 4 files changed, 86 insertions(+), 26 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 18ab78d..6adee59 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -63,6 +63,9 @@ var whiteFader : FadeInOutAlt; var introComponent : IntroSequence1stPerson; introComponent = GetComponent("IntroSequence1stPerson"); +var simpleVelocityLimiterComponent : SimpleVelocityLimiter; +simpleVelocityLimiterComponent = GetComponent("SimpleVelocityLimiter"); + var playAltScoreAudio : boolean = false; var clipToPlay : float; var audioToPlay : AudioSource; @@ -129,6 +132,9 @@ function Start() { } LevelStartFade(); + + // since it was probably lerped down to zero at previous levelEnd, initialize it here. + MoveController.controlMultiplier = 1; } function LevelStartFade () { @@ -216,7 +222,7 @@ function DeathRespawn () { MoveController.controlMultiplier = 1; - lerpControlIn(3); + lerpControlIn(3.0); yield UIscriptComponent.fadeIn(true); } @@ -323,31 +329,73 @@ function lerpControlIn(timer : float) { function lerpControlOut(timer : float) { - var start = MoveController.controlMultiplier; - var end = 0.0; + var startControl : float = MoveController.controlMultiplier; + var end : float = 0.0; + var startMaxVelocity : float = simpleVelocityLimiterComponent.GetMaxVelocity(); + var endVelocity : float = 0; // startMaxVelocity * .15; // / 3; + + // timer 1 and 2 run sequentially via the two `yields` / + // inner `while` looops below, adding up to the overall `timer` argument: + var timer2 : float = 0.65; + var timer1 : float = timer - timer2; + var i = 0.0; - var step = 1.0/timer; - + var step = 1.0/timer1; + while (i <= 1.0) { i += step * Time.deltaTime; - var t : float = i*i * (3f - 2f*i); // smoothstep lerp - MoveController.controlMultiplier = Mathf.Lerp(start, end, t); + + var controlT : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp + + MoveController.controlMultiplier = Mathf.Lerp(startControl, end, controlT); if (isAlive == 0) { - MoveController.controlMultiplier = start; + MoveController.controlMultiplier = startControl; + simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); break; } yield; - if (i >= 1.0 || isAlive == 0) { - MoveController.controlMultiplier = start; + // the && is because the smootherstep math can overshoot 1.0 on its own: + if (i >= 1.0 && isAlive == 0) { + MoveController.controlMultiplier = startControl; + simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); break; } } - yield WaitForSeconds (timer); + + // In the final bit of time (timer2), lerp the speed cap down to zero: + var i2 : float = 0.0; + var step2 = 1.0/timer2; + + while (i2 <= 1.0) { + i2 += step2 * Time.deltaTime; + + // var maxVelocityT : float = i2*i2*i2 * (i2 * (6f*i2 - 15f) + 10f); // smootherstep lerp + var maxVelocityT : float = Mathf.Sin(i2 * Mathf.PI * 0.5f); // ease-out lerp + + var newMaxVelocity : float = Mathf.Lerp(startMaxVelocity, endVelocity, maxVelocityT); + + simpleVelocityLimiterComponent.SetMaxVelocity(newMaxVelocity); + + if (isAlive == 0) { + MoveController.controlMultiplier = startControl; + simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); + break; + } + + yield; + + // the && is because the smootherstep math can overshoot 1.0 on its own: + if (i2 >= 1.0 && isAlive == 0) { + MoveController.controlMultiplier = startControl; + simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); + break; + } + } } - + function OnCollisionEnter (collision : Collision) { // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); // Screen.sleepTimeout = 0.0f; @@ -435,6 +483,9 @@ function OnTriggerEnter (other : Collider) { "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, FallingLaunch.secondsInLevel ); + + // reset the level area identifier for analytics purposes: + FallingLaunch.thisLevelArea = "0-start"; // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); @@ -442,10 +493,11 @@ function OnTriggerEnter (other : Collider) { script.IncrementScore(25); audioLevelEnd.Play(); - lerpControlOut(3); - //yield WaitForSeconds (audioLevelEnd.clip.length - 3); - //yield WaitForSeconds (1); - UIscriptComponent.LevelComplete(); + + // the lerpControlOut timer argument must be equal to levelComplete's first argument + // for a convincing slowdown lerp and UI/camera fadeout: + lerpControlOut(3.0); + UIscriptComponent.LevelComplete(3.0, 1.0); } } diff --git a/MoveController.js b/MoveController.js index 9567ad1..c8b5063 100644 --- a/MoveController.js +++ b/MoveController.js @@ -21,7 +21,7 @@ private var dir = Vector3.zero; var speed : float = 2.4; static var speedingUp : int = 1; -static var controlMultiplier : float = 1; +static var controlMultiplier : float = 1.0; private var controlModifierTotal : float; var mainCameraObj : GameObject; @@ -83,6 +83,10 @@ function Start() { //Calibrate(); + // resetting controlMultiplier in case it was zeroed from the previous level + // (since as a global/static var, it's cached across level loads); + controlMultiplier = 1.0; + lerpSlowdown(.5); lerpControl(3); //pauseButtonArea = Rect(0, 0, Screen.width / 2, Screen.height / 2); diff --git a/SimpleVelocityLimiter.js b/SimpleVelocityLimiter.js index 8a94b74..a16e8db 100644 --- a/SimpleVelocityLimiter.js +++ b/SimpleVelocityLimiter.js @@ -29,7 +29,11 @@ function SetMaxVelocity(maxVelocity : float){ sqrMaxVelocity = maxVelocity * maxVelocity; } -// FixedUpdate is a built-in unity function that is called every fixed framerate frame. +function GetMaxVelocity() { + return maxVelocity; +} + +// FixedUpdate is a built-in Unity function that is called every fixed framerate frame. // We use FixedUpdate instead of Update here because the docs recommend doing so when // dealing with rigidbodies. // For more info, see: diff --git a/fallingUITest.js b/fallingUITest.js index 0daf7cf..579eec6 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -620,25 +620,25 @@ function RestartLevel() { UnPauseGame(false); } -function LevelComplete() { +function LevelComplete(timer1 : float, timer2 : float) { HideGUI(); FallingPlayer.isPausable = false; MoveController.Slowdown = 0; bgSprite.hidden = false; - bgSprite.alphaFromTo( 3.0f, 0.0f, 0.97f, Easing.Sinusoidal.easeIn); + bgSprite.alphaFromTo( timer1, 0.0f, 0.97f, Easing.Sinusoidal.easeIn); FallingLaunch.levelEndSlowdown = MoveController.Slowdown; - - yield WaitForSeconds (3); -// fade in congrats menu / buttons here + yield WaitForSeconds(timer1); + + // fade in congrats menu / buttons here savedTimeScale = Time.timeScale; //loadingLabel.hidden = false; //loadingLabel.alphaFromTo( 0.75f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); nextLevelLabel.hidden = false; - nextLevelLabel.alphaFromTo( 1.0f, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); + nextLevelLabel.alphaFromTo( timer2, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); fallingPlayerComponent.FadeAudio (.9, FadeDir.Out); - yield WaitForSeconds (1); -// Time.timeScale = 0; + yield WaitForSeconds (timer2); + // Time.timeScale = 0; player.GetComponent.().isKinematic = true; AudioListener.pause = true; Application.LoadLevel(levelToLoad); From 36c720c0f7e8c39670ab67c6d7e8861306074b33 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 19 Oct 2017 19:18:27 -0700 Subject: [PATCH 26/77] Tweak level-end speed-down lerp --- EndSequence1stPerson.js | 5 +- FallingPlayer.js | 127 ++++++++++++++++++++-------------------- fallingUITest.js | 64 +++++++++----------- 3 files changed, 95 insertions(+), 101 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 54d5af1..20e7662 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -48,8 +48,9 @@ function PlayOutro () { FallingPlayer.isPausable = false; ScoreController.enabled = false; - LifeController.enabled = false; - FallingPlayer.isTiltable = false; + LifeController.enabled = false; + FallingPlayer.isTiltable = false; + PlayerController.lerpSlowdown(1); OutroMusic.Play(); //PlayerController.SpeedLinesOff(1); diff --git a/FallingPlayer.js b/FallingPlayer.js index 6adee59..f0a96ef 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -336,7 +336,7 @@ function lerpControlOut(timer : float) { // timer 1 and 2 run sequentially via the two `yields` / // inner `while` looops below, adding up to the overall `timer` argument: - var timer2 : float = 0.65; + var timer2 : float = 1.25; var timer1 : float = timer - timer2; var i = 0.0; @@ -427,77 +427,76 @@ function OnCollisionEnter (collision : Collision) { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Score")){ + // Debug.Log("You scored!"); + // Camera.main.SendMessage("flashOut"); + ScoreFlashTextureScript.FadeFlash (0.8, FadeDir.Out); -// Debug.Log("You scored!"); -// Camera.main.SendMessage("flashOut"); - ScoreFlashTextureScript.FadeFlash (0.8, FadeDir.Out); - - script.IncrementScore(6); - UIscriptComponent.flashProgressBar(1); - - if (audioScore) { - //Debug.Log(Random.Range(0,2)); - myVol = ((MoveController.Slowdown / MoveController.maxSlowdown) * peakVol); - clipToPlay = Random.Range(0.3f, 0.9f); - pitchRand = Random.Range(0.98f,1.03f); - - if (playAltScoreAudio) { - audioToPlay = audioScoreAlt; - playAltScoreAudio = false; - } - else { - audioToPlay = audioScore; - playAltScoreAudio = true; - } - - audioToPlay.pitch = pitchRand; - - //if (clipToPlay == 1) {audioToPlay = audioScoreAlt;} - if (clipToPlay > 0.6f) { - audioToPlay.panStereo = (-clipToPlay/2); - audioToPlay.volume = Mathf.Clamp(myVol, (peakVol/2), peakVol); - } - else { - audioToPlay.volume = clipToPlay; - audioToPlay.panStereo = (clipToPlay/2); - } - - //audioToPlay.volume = Mathf.Clamp(myVol, (peakVol * .5), peakVol); - audioToPlay.Play(); - } - - //yield WaitForSeconds(.2); - -// try using PlayClipAtPoint here so score sound fades away in 3D space as you fall? + script.IncrementScore(6); + UIscriptComponent.flashProgressBar(1); + + if (audioScore) { + //Debug.Log(Random.Range(0,2)); + myVol = ((MoveController.Slowdown / MoveController.maxSlowdown) * peakVol); + clipToPlay = Random.Range(0.3f, 0.9f); + pitchRand = Random.Range(0.98f,1.03f); + + if (playAltScoreAudio) { + audioToPlay = audioScoreAlt; + playAltScoreAudio = false; + } + else { + audioToPlay = audioScore; + playAltScoreAudio = true; + } + + audioToPlay.pitch = pitchRand; + + //if (clipToPlay == 1) {audioToPlay = audioScoreAlt;} + if (clipToPlay > 0.6f) { + audioToPlay.panStereo = (-clipToPlay/2); + audioToPlay.volume = Mathf.Clamp(myVol, (peakVol/2), peakVol); + } + else { + audioToPlay.volume = clipToPlay; + audioToPlay.panStereo = (clipToPlay/2); + } + + //audioToPlay.volume = Mathf.Clamp(myVol, (peakVol * .5), peakVol); + audioToPlay.Play(); + } + + //yield WaitForSeconds(.2); -// Camera.main.SendMessage("flashUp"); + // try using PlayClipAtPoint here so score sound fades away in 3D space as you fall? + // Camera.main.SendMessage("flashUp"); } if (other.gameObject.CompareTag ("LevelEnd") && isExitingLevel == false) { isExitingLevel = true; - isPausable = false; + isPausable = false; var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; - FallingLaunch.secondsInLevel = (Time.time - levelStartTime); - - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, - FallingLaunch.secondsInLevel - ); - - // reset the level area identifier for analytics purposes: - FallingLaunch.thisLevelArea = "0-start"; + FallingLaunch.secondsInLevel = (Time.time - levelStartTime); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, + FallingLaunch.secondsInLevel + ); + + // reset the level area identifier for analytics purposes: + FallingLaunch.thisLevelArea = "0-start"; + + // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); + + // to keep you from dying after you strike the levelend trigger + script.IncrementScore(25); + + audioLevelEnd.Play(); - // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); - - // to keep you from dying after you strike the levelend trigger - script.IncrementScore(25); - - audioLevelEnd.Play(); - - // the lerpControlOut timer argument must be equal to levelComplete's first argument - // for a convincing slowdown lerp and UI/camera fadeout: - lerpControlOut(3.0); - UIscriptComponent.LevelComplete(3.0, 1.0); + // the lerpControlOut timer argument must be equal to, or just less than, + // the sum of levelComplete's first argument, + // in order to create a convincing slowdown lerp and UI/camera fadeout: + lerpControlOut(4.0); + UIscriptComponent.LevelComplete(3.0, 1.5); } } diff --git a/fallingUITest.js b/fallingUITest.js index 579eec6..4b77162 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -74,7 +74,7 @@ var level4Unlocked : boolean = false; static var holdingPauseButton : boolean = false; static var origPauseButtonArea : Rect; -private var savedTimeScale:float; +private var savedTimeScale : float; //var x:float; //var y:float; // private var lifeBar = UIProgressBar.create( "lifeBarRedTest.png", 0, 0 ); @@ -108,8 +108,7 @@ function Start () { bgSprite.hidden = true; //Debug.Log("your highest level achieved is " + FallingLaunch.levelAchieved); - if (FallingLaunch.levelAchieved == 5) { - //loadLevelTwo.alphaTo(0.01f, 0.0f, Easing.Sinusoidal.easeOut); + if (FallingLaunch.debugMode || FallingLaunch.levelAchieved == 5) { level2Unlocked = true; level3Unlocked = true; level4Unlocked = true; @@ -122,12 +121,6 @@ function Start () { level2Unlocked = true; } - if (FallingLaunch.debugMode) { - level2Unlocked = true; - level3Unlocked = true; - level4Unlocked = true; - } - var tiltPlacementRatio : float; if (UIT.isHD == true) { @@ -636,16 +629,25 @@ function LevelComplete(timer1 : float, timer2 : float) { //loadingLabel.alphaFromTo( 0.75f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); nextLevelLabel.hidden = false; nextLevelLabel.alphaFromTo( timer2, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); - fallingPlayerComponent.FadeAudio (.9, FadeDir.Out); + fallingPlayerComponent.FadeAudio (.9 * timer2, FadeDir.Out); + yield WaitForSeconds (timer2); + // Time.timeScale = 0; player.GetComponent.().isKinematic = true; AudioListener.pause = true; - Application.LoadLevel(levelToLoad); - FallingLaunch.levelAchieved = (Application.loadedLevel + 1); - PlayerPrefs.SetInt("HighestLevel", (Application.loadedLevel + 1)); + // Only increment `HighestLevel` pref if it's higher than the current `levelAchieved` value + // (fixes bug where beaten levels reset on beating level one of New Game Plus): + if ((Application.loadedLevel + 1) > FallingLaunch.levelAchieved) { + FallingLaunch.levelAchieved = (Application.loadedLevel + 1); + PlayerPrefs.SetInt("HighestLevel", (Application.loadedLevel + 1)); + } + Time.timeScale = savedTimeScale; + Application.LoadLevel(levelToLoad); + + // Calling Save right after loadLevel, since saving to disk can cause a potential FPS hiccup: PlayerPrefs.Save(); } @@ -655,28 +657,20 @@ function BeginOutroUI() { player.GetComponent.().isKinematic = true; } -function OldGameCompleteUI() { - bgSprite.hidden = false; - bgSprite.alphaFromTo( 4.5f, 0.0f, 0.99f, Easing.Sinusoidal.easeInOut); - fallingPlayerComponent.FadeAudio (2.0, FadeDir.Out); - yield WaitForSeconds (1.0); - yield WaitForSeconds (2.0); -} - -function GameComplete() { - bgSprite.hidden = false; - bgSprite.alphaFromTo( 1.5f, 0.0f, 0.90f, Easing.Sinusoidal.easeIn); - fallingPlayerComponent.FadeAudio (1.5, FadeDir.Out); - yield WaitForSeconds (.5); - savedTimeScale = Time.timeScale; -// loadingLabel.hidden = false; -// loadingLabel.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - yield WaitForSeconds (1); - AudioListener.pause = true; - FallingPlayer.isTiltable = true; - Application.LoadLevel(levelToLoad); - Time.timeScale = savedTimeScale; -} +// function GameComplete() { +// bgSprite.hidden = false; +// bgSprite.alphaFromTo( 1.5f, 0.0f, 0.90f, Easing.Sinusoidal.easeIn); +// fallingPlayerComponent.FadeAudio (1.5, FadeDir.Out); +// yield WaitForSeconds (.5); +// savedTimeScale = Time.timeScale; +// // loadingLabel.hidden = false; +// // loadingLabel.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); +// yield WaitForSeconds (1); +// AudioListener.pause = true; +// FallingPlayer.isTiltable = true; +// Application.LoadLevel(levelToLoad); +// Time.timeScale = savedTimeScale; +// } function GameCompleteUI() { bgSprite.hidden = false; From a71cb377994aa221bd9701884cdf09b66e384dc6 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 19 Oct 2017 19:53:43 -0700 Subject: [PATCH 27/77] Fix SmoothFogFade condition for level2 --- changeBackdrop.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/changeBackdrop.js b/changeBackdrop.js index b283321..94d9042 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -98,6 +98,7 @@ function OnTriggerEnter (other : Collider) { else if (other.gameObject.CompareTag ("changeBackdrop2")) { // Debug.Log("You hit an alt changeBackdrop trigger!"); + FadeCameraFarClipPlane (2); if (FogOnly == true) {SmoothFogFade (2);} if (ShouldUseOceanCamera == true) {enableOceanCamera(); SmoothFogFade (2);} @@ -147,25 +148,25 @@ function FadeCameraFarClipPlane (type : int) { } function SmoothFogFade (type : int) { - if (type == 2) { - iTween.ValueTo ( gameObject, - { - "from" : FallingPlayer.startingFogEndDistance, - "to" : fogEndValue2, - "onupdate" : "ChangeFogEndDistance", - "time" : farClipPlaneFadeTime2, - "easetype" : "easeInExpo" - }); - } else if (type == 2) { - iTween.ValueTo ( gameObject, - { - "from" : FallingPlayer.startingFogEndDistance, - "to" : fogEndValue, - "onupdate" : "ChangeFogEndDistance", - "time" : 3, - "easetype" : "easeInExpo" -// "oncomplete" : "CameraFadeEnd" - }); + if (type == 1) { + iTween.ValueTo ( gameObject, + { + "from" : FallingPlayer.startingFogEndDistance, + "to" : fogEndValue, + "onupdate" : "ChangeFogEndDistance", + "time" : 3, + "easetype" : "easeInExpo" + // "oncomplete" : "CameraFadeEnd" + }); + } else if (type == 2) { + iTween.ValueTo ( gameObject, + { + "from" : FallingPlayer.startingFogEndDistance, + "to" : fogEndValue2, + "onupdate" : "ChangeFogEndDistance", + "time" : farClipPlaneFadeTime2, + "easetype" : "easeInExpo" + }); } else if (type == 3) { // Effectively zeroes out fog via gentler distance dispersal. // Assumes that fogEndValue is large enough that halving it From 629abeb49605a7b5c8007d352fd176845739c351 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 21 Oct 2017 15:40:05 -0700 Subject: [PATCH 28/77] Minor audioListener fadeout cleanup --- FallingPlayer.js | 5 ++--- FallingStartMenu.js | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index f0a96ef..76b8cce 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -24,7 +24,7 @@ public var force:float = 1.0; var dir : Vector3 = Vector3.zero; enum FadeDir {In, Out} -var fadeTime = 0.75; +var fadeTime : float = 0.75; var origMat : Material; //var thisOceanCamera : Component; @@ -193,8 +193,7 @@ function DeathRespawn () { changeLevelBackdrop (); } -// fadeOutAudio (); - FadeAudio ((fadeTime), FadeDir.Out); + FadeAudio (fadeTime, FadeDir.Out); script.ResetScore(0); diff --git a/FallingStartMenu.js b/FallingStartMenu.js index 166e521..3567a09 100644 --- a/FallingStartMenu.js +++ b/FallingStartMenu.js @@ -107,8 +107,7 @@ function DeathRespawn () { changeLevelBackdrop (); } -// fadeOutAudio (); - FadeAudio ((fadeTime/2), FadeDir.Out); + FadeAudio (fadeTime/2, FadeDir.Out); gameObject.SendMessage ("ResetScore", 0); yield WaitForSeconds(1); From 89071ed2645e1c5d40acb6f256d331423fc8a320 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 21 Oct 2017 15:40:39 -0700 Subject: [PATCH 29/77] Audio ducking and speedup/slowdown lerp fixes --- AudioDuckingRegion.js | 9 +++++---- MoveController.js | 47 +++++++++++++++++++++++++++++++------------ lifeCountdown.js | 9 ++++++--- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/AudioDuckingRegion.js b/AudioDuckingRegion.js index ec80464..b2703c2 100644 --- a/AudioDuckingRegion.js +++ b/AudioDuckingRegion.js @@ -1,12 +1,14 @@ #pragma strict var duckingObject : GameObject; +var moveControllerComponent : MoveController; var duckingVal : float = .5f; var StopAudioOnComplete : boolean = false; var audioSource : AudioSource; function Start () { audioSource = duckingObject.GetComponent.(); + moveControllerComponent = duckingObject.transform.parent.GetComponent.(); } function OnTriggerEnter (other : Collider) { @@ -22,7 +24,6 @@ function OnTriggerExit (other : Collider) { } function lerpDuck (timer : float, endVal : float) { - var start = audioSource.volume; var end = endVal; var i = 0.0; @@ -30,9 +31,9 @@ function lerpDuck (timer : float, endVal : float) { while (i <= 1.0) { i += step * Time.deltaTime; - audioSource.volume = Mathf.Lerp(start, end, i); - yield; - } + moveControllerComponent.setMaxDuckedVolume( Mathf.Lerp(start, end, i) ); + yield; + } yield WaitForSeconds (timer); if (StopAudioOnComplete) {audioSource.Stop();} diff --git a/MoveController.js b/MoveController.js index c8b5063..ec853b4 100644 --- a/MoveController.js +++ b/MoveController.js @@ -8,6 +8,8 @@ private var startTime : float; static var Slowdown : float = 0.0; static var maxSlowdown : float = 18000.0; +private var maxSlowdownThreshold : float = maxSlowdown - 1; + static var lateralSpeedBoost : float = 0.0; static var maxLateralSpeed : float = 0.5; @@ -38,8 +40,13 @@ static var SpeedLinesMeshScript : SpeedLines; var audioSource : AudioSource; var changingPitch : boolean = false; + +// this is on for all levels but lvl1/tutorial, which has music baked +// into the background wind sound, and thus shouldn't get pitch-shifted: var shouldChangePitch : boolean = true; +var maxDuckedVolume : float = 1.0; + static var pauseButtonArea : Rect; function Awake() { @@ -51,7 +58,6 @@ function Awake() { function Start() { - // HACK: Force landscape left orientation in VR for Cardboard compatibility. // Or is this best off just being removed? // NB: If your phone is tilted a little beyond flat (away from you) on level load, @@ -177,7 +183,7 @@ function Update () { myHead = mainCameraObj.GetComponent.().Head; } } - + FallingSpeed(); // Debug.Log("Slowdown = " + Slowdown); } @@ -223,9 +229,13 @@ function FallingSpeed () { // FallingLaunch.secondsAlive // ); } - } - else if (fingerCount < 1) { - if (Slowdown > 0) { speedingUp = 0; speedsUp(); lerpSlowdown(.5); } + } else if (fingerCount < 1) { + // rounding Slowdown, since as lerp approaches zero, floating-point errors creep in + if (Mathf.Round(Slowdown) > 0) { + speedingUp = 0; speedsUp(); lerpSlowdown(.5); + } else { + audioSource.volume = maxDuckedVolume; + } } } @@ -282,7 +292,11 @@ function speedsUp () { speedingUp = 1; SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); FallingPlayer.UIscriptComponent.showThreatBar(1); - if (audioSource && shouldChangePitch == true) {lerpPitchUp(.5, 2, .3);} + if (audioSource && shouldChangePitch == true) { + // a bit of randomness to vary the end wind-noise pitch; + // generally, we want a value near 2: + lerpPitchUp(.5, Random.Range(1.85, 2.25), .3); + } } else { SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); @@ -291,8 +305,15 @@ function speedsUp () { } } -function lerpSlowdown (timer : float) { +function getMaxDuckedVolume() { + return maxDuckedVolume; +} +function setMaxDuckedVolume(maxVol : float) { + maxDuckedVolume = maxVol; +} + +function lerpSlowdown (timer : float) { var start = Slowdown; var end = 0.0; var i = 0.0; @@ -303,7 +324,7 @@ function lerpSlowdown (timer : float) { Slowdown = Mathf.Lerp(start, end, i); yield; - if (Slowdown > 17999) {break;} + if (Slowdown > maxSlowdownThreshold) {break;} } yield WaitForSeconds (timer); @@ -323,11 +344,11 @@ function lerpPitchUp (timer : float, endPitch : float, endVolume : float) { while (i <= 1.0) { i += step * Time.deltaTime; audioSource.pitch = Mathf.Lerp(start, end, i); - audioSource.volume = Mathf.SmoothStep(startVol, endVol, i); + audioSource.volume = Mathf.SmoothStep(startVol, endVol * maxDuckedVolume, i); yield; if (Slowdown < 1) {break;} - } + } yield WaitForSeconds (timer); } @@ -346,11 +367,11 @@ function lerpPitchDown (timer : float, endPitch : float, endVolume : float) { while (i <= 1.0) { i += step * Time.deltaTime; audioSource.pitch = Mathf.Lerp(start, end, i); - audioSource.volume = Mathf.SmoothStep(startVol, endVol, i); + audioSource.volume = Mathf.SmoothStep(startVol, endVol * maxDuckedVolume, i); yield; - if (Slowdown > 17999) {changingPitch = false; break;} - } + if (Slowdown > maxSlowdownThreshold) {changingPitch = false; break;} + } yield WaitForSeconds (timer); changingPitch = false; diff --git a/lifeCountdown.js b/lifeCountdown.js index 3d9f271..2ca1990 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -8,11 +8,14 @@ static var inOutro : boolean = false; static var isAlive : int = 0; var UIscriptName : GameObject; +private var maxSlowdownThreshold : float; + function Awake () { - script = GetComponent("ScoreController"); + script = GetComponent("ScoreController"); } function Start () { + maxSlowdownThreshold = MoveController.maxSlowdown - 1; isAlive = 1; Loop (); Loop2 (); @@ -43,12 +46,12 @@ function ScoreLerpLoop () { function TickingAway (delay : float) { if (script.currentScore > 0) { - if (MoveController.Slowdown > 17999) { + if (MoveController.Slowdown > maxSlowdownThreshold) { script.DecrementScore(delay); yield WaitForSeconds((delay/4)); } - else if (MoveController.Slowdown < 18000) { + else if (MoveController.Slowdown < MoveController.maxSlowdown) { script.DecrementScore(delay); yield WaitForSeconds(delay); } From 9be7fca4eb61fa90b9fbf9f4e49dc8969e1c7e77 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Mon, 23 Oct 2017 22:53:53 -0700 Subject: [PATCH 30/77] VR tilt control finesse during speed boosting --- AudioDuckingRegion.js | 5 ++++- FallingLaunch.js | 2 +- MoveController.js | 30 +++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/AudioDuckingRegion.js b/AudioDuckingRegion.js index b2703c2..49b0e72 100644 --- a/AudioDuckingRegion.js +++ b/AudioDuckingRegion.js @@ -8,7 +8,10 @@ var audioSource : AudioSource; function Start () { audioSource = duckingObject.GetComponent.(); - moveControllerComponent = duckingObject.transform.parent.GetComponent.(); + // go one or two levels up: + moveControllerComponent = + duckingObject.transform.parent.GetComponent.() || + duckingObject.transform.parent.parent.GetComponent.(); } function OnTriggerEnter (other : Collider) { diff --git a/FallingLaunch.js b/FallingLaunch.js index 9a050fc..cb6b215 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -53,7 +53,7 @@ enum iPads { }; function Awake () { - isVRMode = false; // TODO: Let user pick this via UI + isVRMode = true; // TODO: Let user pick this via UI } function Start () { diff --git a/MoveController.js b/MoveController.js index ec853b4..11b1740 100644 --- a/MoveController.js +++ b/MoveController.js @@ -10,8 +10,8 @@ static var Slowdown : float = 0.0; static var maxSlowdown : float = 18000.0; private var maxSlowdownThreshold : float = maxSlowdown - 1; -static var lateralSpeedBoost : float = 0.0; -static var maxLateralSpeed : float = 0.5; +private var lateralSpeedBoost : float = 0.0; +private var maxLateralSpeed : float = 0.5; var forceComponent : ConstantForce; @@ -20,7 +20,8 @@ var extraForce = Vector3.zero; private var clampedModifierVR : float; private var dir = Vector3.zero; -var speed : float = 2.4; +private var speed : float = 2.4; + static var speedingUp : int = 1; static var controlMultiplier : float = 1.0; @@ -113,8 +114,9 @@ function FixedUpdate () { // if not in VR mode, call movePlayer and honor the playerPrefs axis settings: MovePlayer(FallingLaunch.invertHorizAxisVal, FallingLaunch.invertVertAxisVal); } + } else { + dir = Vector3.zero; } - else {dir = Vector3.zero;} // Address any speedups due to screen presses in FixedUpdate, not here! // FallingSpeed(); @@ -138,15 +140,25 @@ function MovePlayerVR () { // Debug.Log('dir x final ' + dir.x); // Debug.Log('dir z final ' + dir.z); + var speedRatio : float = Slowdown / maxSlowdown; + // Cap the lateral speed (it should be translation, not a force, - // so you don't keep moving after you lift the trigger): - lateralSpeedBoost = Mathf.Max((Slowdown/maxSlowdown) * maxLateralSpeed, 0.0); + // so you don't keep moving after you lift the trigger). + // Distinguish between two categories of movement: + // while in boost mode and just afterwards (speedRatio > .25; value range is 1.25-2.4), + // vs. regular (speedRatio < .25) movement. + // The latter is more constrained (possible value range 1-1.5). + lateralSpeedBoost = speedRatio > .25 ? + Mathf.Max(1.25, speedRatio * speed) : 1.0 + (speedRatio * maxLateralSpeed); + // Debug.Log('lateralSpeedBoost: ' + lateralSpeedBoost); - // Clamped to 2 units/frame (and avoiding speed multiplier) to obtain - // more 'realistic' 1:1 movement, with just a little amplification, + // Dir is clamped to +/-2 units/frame (and avoiding direct use of the speed multiplier) + // to obtain more 'realistic' 1:1 movement, with just a little amplification, // and with lateralSpeedBoost as the extra if you're touching the screen. - myTransform.Translate (dir * (1.0 + lateralSpeedBoost), Space.World); + // myTransform.Translate (dir * (1.0 + lateralSpeedBoost), Space.World); + // myTransform.Translate (dir * lateralSpeedBoost, Space.World); + myTransform.Translate (dir * lateralSpeedBoost, Space.World); } function MovePlayer(horizAxisInversionVal: int, vertAxisInversionVal: int) { From d586279cb09abf9a3e49615a0187559414dec002 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 25 Oct 2017 21:38:40 -0700 Subject: [PATCH 31/77] VR spherical fadeouts, score/hit flashes, and health reticle --- AudioDuckingRegion.js | 2 +- FallingLaunch.js | 2 +- FallingPlayer.js | 118 ++++++++++++++++++++++++++++++++++++------ VRLifeMeter.js | 62 ++++++++++++++++++++++ fallingStartMenuUI.js | 23 +++++++- fallingUITest.js | 95 +++++++++++++++++----------------- lifeCountdown.js | 55 ++++++++++++++++---- 7 files changed, 281 insertions(+), 76 deletions(-) create mode 100644 VRLifeMeter.js diff --git a/AudioDuckingRegion.js b/AudioDuckingRegion.js index 49b0e72..67ff86c 100644 --- a/AudioDuckingRegion.js +++ b/AudioDuckingRegion.js @@ -8,7 +8,7 @@ var audioSource : AudioSource; function Start () { audioSource = duckingObject.GetComponent.(); - // go one or two levels up: + // go one or two levels up, since in VR the parent may be shifted around: moveControllerComponent = duckingObject.transform.parent.GetComponent.() || duckingObject.transform.parent.parent.GetComponent.(); diff --git a/FallingLaunch.js b/FallingLaunch.js index cb6b215..9a050fc 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -53,7 +53,7 @@ enum iPads { }; function Awake () { - isVRMode = true; // TODO: Let user pick this via UI + isVRMode = false; // TODO: Let user pick this via UI } function Start () { diff --git a/FallingPlayer.js b/FallingPlayer.js index 76b8cce..ed661e6 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -1,7 +1,8 @@ #pragma strict +// 10/25/2017: `Color` uses a 0-1 float range, not 0-2, in Unity. // 2 = 255 for rgba in this color array -static var startingFogColor : Color = Color(1.17, 1.17, 1.17, 2); +// static var startingFogColor : Color = Color(1.17, 1.17, 1.17, 2); static var startingFogEndDistance : int = 1500; static var startingFogStartDistance : int = 150; static var startingCameraFarClipPlane : int = 1700; @@ -57,6 +58,19 @@ var isExitingLevel : boolean = false; var UIscriptName : GameObject; static var UIscriptComponent : fallingUITest; +// todo: handle spherical fade-out UI in script +// var blackUIVR : GameObject; + +var deathUIVR : GameObject; + +var scoreUIVR : GameObject; +var scoreUIVRRenderer : Renderer; +var scoreUIVRMatl : Material; +var peakScoreFlashValueVR : float = 1.0; + +var reticleVRUIObj : GameObject; +var reticleVRUIScript : VRLifeMeter; + var clearDestroyedObjects : boolean = false; var whiteFader : FadeInOutAlt; @@ -103,7 +117,19 @@ function Start() { BackdropMist = GameObject.Find("Cylinder"); myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; - myVRViewer = GameObject.Find("GvrViewerMain"); + if (FallingLaunch.isVRMode) { + myVRViewer = GameObject.Find("GvrViewerMain"); + scoreUIVRRenderer = scoreUIVR.GetComponent.(); + scoreUIVRMatl = scoreUIVRRenderer.material; + scoreUIVRMatl.color.a = 0; + if (reticleVRUIObj) { + reticleVRUIScript = reticleVRUIObj.GetComponent.(); + } else { + Debug.LogError("You forgot to assign an object for the VR reticle... trying to look up manually"); + reticleVRUIScript = GameObject.Find("vr-radial-life-meter").GetComponent.(); + } + reticleVRUIScript.FadeReticleIn(1.5); + } // startingFogColor = RenderSettings.fogColor * 2; startingFogEndDistance = RenderSettings.fogEndDistance; @@ -184,8 +210,8 @@ function DeathRespawn () { isPausable = false; rb.isKinematic = true; lifeStartTime = Time.time; - var respawnPosition = Respawn.currentRespawn.transform.position; - + var respawnPosition = Respawn.currentRespawn.transform.position; + UIscriptComponent.fadeOut(); // Camera.main.SendMessage("fadeOut"); @@ -220,9 +246,39 @@ function DeathRespawn () { // isAlive = 1; MoveController.controlMultiplier = 1; - - lerpControlIn(3.0); - yield UIscriptComponent.fadeIn(true); + + if (FallingLaunch.isVRMode && deathUIVR) { + + rb.isKinematic = true; + isAlive = 0; + + deathUIVR.SetActive(true); + reticleVRUIScript.FadeReticleOut(0.5); + + yield UIscriptComponent.fadeIn(false); + + yield WaitForSeconds(4); + + yield UIscriptComponent.fadeOut(); + // UIscriptComponent.UnPauseGame(true); + rb.isKinematic = false; + + // TODO: Fade out material here instead of toggling the whole object outright? + deathUIVR.SetActive(false); + + lerpControlIn(3.0); + + yield UIscriptComponent.fadeIn(false); + yield WaitForSeconds(1); + + reticleVRUIScript.FadeReticleIn(1.5); + + isPausable = true; + isAlive = 1; + } else { + lerpControlIn(3.0); + yield UIscriptComponent.fadeIn(true); + } } function LatestCheckpointRespawn () { @@ -254,13 +310,13 @@ function LatestCheckpointRespawn () { } function ShowDeathHelp() { - if (introComponent) { - introComponent.DeathHelp(); - } + if (introComponent && !FallingLaunch.isVRMode) { + introComponent.DeathHelp(); + } } function changeLevelBackdrop () { - changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; + changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; changeBackdrop.oceanRenderer.enabled = false; changeBackdrop.cloudRenderer.enabled = false; changeBackdrop.endSphereRenderer.enabled = false; @@ -268,12 +324,12 @@ function changeLevelBackdrop () { // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); RenderSettings.fogEndDistance = startingFogEndDistance; - RenderSettings.fogStartDistance = startingFogStartDistance; + RenderSettings.fogStartDistance = startingFogStartDistance; - if (myMainCamera) {myMainCamera.farClipPlane = startingCameraFarClipPlane;} - if (myBackdropRenderer) { - myBackdropRenderer.materials = [origMat]; - } + if (myMainCamera) {myMainCamera.farClipPlane = startingCameraFarClipPlane;} + if (myBackdropRenderer) { + myBackdropRenderer.materials = [origMat]; + } iTween.ColorTo(BackdropMist,{"a": startingCloudsAlpha,"time": .5}); } @@ -283,6 +339,16 @@ function Update () { playerTilt(); } + // disable VR mode and return to menu on screen touch while dead: + if (FallingLaunch.isVRMode && isAlive == 0 && deathUIVR.activeInHierarchy) { + for (var i = 0; i < Input.touchCount; ++i) { + if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { + FallingLaunch.isVRMode = false; + Application.LoadLevel("Falling-scene-menu"); + } + } + } + //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); //Debug.Log("your current acceleration is: " + FallingLaunch.accelerator); } @@ -395,6 +461,20 @@ function lerpControlOut(timer : float) { } } +function ScoreFlashVR (timer : float, fadeType : FadeDir) { + + var start = fadeType == FadeDir.In? 0.0 : peakScoreFlashValueVR; + var end = fadeType == FadeDir.In? peakScoreFlashValueVR : 0.0; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + scoreUIVRMatl.color.a = Mathf.Lerp(start, end, i); + yield; + } +} + function OnCollisionEnter (collision : Collision) { // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); // Screen.sleepTimeout = 0.0f; @@ -428,7 +508,11 @@ function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Score")){ // Debug.Log("You scored!"); // Camera.main.SendMessage("flashOut"); - ScoreFlashTextureScript.FadeFlash (0.8, FadeDir.Out); + if (FallingLaunch.isVRMode) { + ScoreFlashVR(0.8, FadeDir.Out); + } else { + ScoreFlashTextureScript.FadeFlash (0.8, FadeDir.Out); + } script.IncrementScore(6); UIscriptComponent.flashProgressBar(1); diff --git a/VRLifeMeter.js b/VRLifeMeter.js new file mode 100644 index 0000000..bcc180c --- /dev/null +++ b/VRLifeMeter.js @@ -0,0 +1,62 @@ +#pragma strict + +var thisImage : UnityEngine.UI.Image; +// private var thisImageMatl : Material; +var fullColor: Color = Color32(255, 255, 255, 165); +var emptyColor: Color = Color.red; // Color32(156, 24, 24, 255); +private var lifePercentage : float = 1; + +private var peakOpacity : float = 1.0; + +private var isVisible : boolean = false; + +function Awake() { + peakOpacity = fullColor.a; +} + +function FadeReticle(timer : float, fadeType : FadeDir) { + + var start = fadeType == FadeDir.In ? 0.0 : peakOpacity; + var end = fadeType == FadeDir.In ? peakOpacity : 0.0; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + thisImage.color.a = Mathf.Lerp(start, end, i); + // If you want to also change the color of the reticle center, modify the material + // instead of Sprite color, via: + // thisImageMatl.color.a = Mathf.Lerp(start, end, i); + + // Debug.Log('fading with fadeType ' + fadeType + ' and alpha ' + thisImageMatl.color.a); + yield; + } +} + +function FadeReticleIn (timer : float) { + isVisible = true; + yield FadeReticle(timer, FadeDir.In); +} + +function FadeReticleOut (timer : float) { + yield FadeReticle(timer, FadeDir.Out); + isVisible = false; +} + +function Update () { + // Deactivate this and early return if we're not in VR mode. + if (!FallingLaunch.isVRMode) { + gameObject.SetActive(false); + return; + } + if (FallingPlayer.isAlive == 1 && isVisible) { + lifePercentage = parseFloat(ScoreController.visibleScore)/parseFloat(ScoreController.maxScore); + thisImage.fillAmount = lifePercentage; + + // Fade reticle from white down to crimson once the player's life is below ~60%: + // For a fancier squared-ratio lerp (starts at roughly 2/3 life ratio): (lifePercentage*lifePercentage)*2 + thisImage.color = Color.Lerp(emptyColor, fullColor, Mathf.Clamp(lifePercentage*2 - .2, 0.0, 1.0) ); + } else { + thisImage.color.a = 0; + } +} \ No newline at end of file diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index a53e499..2bca88e 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -70,6 +70,8 @@ var isSaving : boolean = false; var openSiteButtonText : UIButton; +var vrModeButton : UIButton; +var vrModeLabel : UITextInstance; private var savedTimeScale:float; @@ -300,8 +302,23 @@ function Start () { 0, 0, 0.8f, 1, Color.white, UITextAlignMode.Center, UITextVerticalAlignMode.Bottom ); text3.positionFromBottom(.3f); + // TODO: Use real VR Mode icon and button sprite here. + // HACK: reusing existing button sprite as a transparent background + // for the "VR Mode" text label (which is not clickable): + vrModeButton = UIButton.create("newgame.png", "newgame.png", 0,0); + vrModeButton.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + vrModeButton.normalTouchOffsets = new UIEdgeOffsets( 40 ); + vrModeButton.highlightedTouchOffsets = new UIEdgeOffsets( 40 ); + vrModeButton.onTouchUpInside += LaunchVRMode; + vrModeButton.alphaTo(0.01f, 0.0f, Easing.Sinusoidal.easeOut); + + // vrModeButton.hidden = true; + + vrModeLabel = boldText.addTextInstance( "VR MODE", 0, 0 ); + vrModeLabel.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); optionsButton = UIButton.create("options.png", "options.png", 0,0); + //optionsButton.positionFromBottomRight( .05f, .05f ); //optionsButton.pixelsFromBottomRight ( 14, 14 ); optionsButton.positionFromBottomRight ( .05f, (.05f * screenAspectRatio) ); @@ -987,6 +1004,11 @@ function OpenAbout() { text3.alphaFromTo(1.5f, 0.0f, 0.6f, Easing.Sinusoidal.easeInOut); } +function LaunchVRMode() { + FallingLaunch.isVRMode = true; + ResumeGame(); +} + function ShowOptions() { fadeInOptions(); DisplayTiltChooser(); @@ -1208,7 +1230,6 @@ function downLevel4() { } } - function upLevel1() { if (aboutToLoad == false) { loadLevelOne.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); diff --git a/fallingUITest.js b/fallingUITest.js index 4b77162..d92412e 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -477,13 +477,13 @@ function animateProgressBar(lifeBar : UIProgressBar) { } } -function animateThreatBar(lifeBar : UIProgressBar) { - while (true) - { - lifeBar.value = (1 - (parseFloat(ScoreController.visibleScore)/parseFloat(ScoreController.maxScore))); - yield 0; - } -} +// function animateThreatBar(lifeBar : UIProgressBar) { +// while (true) +// { +// lifeBar.value = (1 - (parseFloat(ScoreController.visibleScore)/parseFloat(ScoreController.maxScore))); +// yield 0; +// } +// } function flashProgressBar(delay : float) { lifeBar.alphaTo( 0.01f, 1.0f, Easing.Sinusoidal.easeOut); @@ -508,7 +508,7 @@ function flashThreatBar(delay : float) { } function PauseGame() { - if (FallingPlayer.isPausable == true) { + if (FallingPlayer.isPausable) { FallingPlayer.isPausable = false; FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); @@ -532,7 +532,7 @@ function PauseGame() { yield WaitForSeconds (.1); Time.timeScale = 0; AudioListener.pause = true; - + rightArrow.hidden = false; //leftArrow.hidden = false; if (level2Unlocked) {loadNewLevelButton.hidden = false;} @@ -549,6 +549,7 @@ function PauseGame() { initialRespawn.SaveCheckpoint(); FallingPlayer.isPausable = true; + return; } } @@ -576,7 +577,7 @@ function UnPauseGame(resume : boolean) { FallingPlayer.isPausable = resume; holdingPauseButton = false; MoveController.pauseButtonArea = origPauseButtonArea; - } +} function IsGamePaused() { return Time.timeScale==0; @@ -968,11 +969,11 @@ function OpenSite() { } function HideGUI() { - pauseButton.hidden = true; - circleReticle.hidden = true; - lifeBar.hidden = true; - lifeBarOutline.hidden = true; - lifeBarThreat.hidden = true; + pauseButton.hidden = true; + circleReticle.hidden = true; + lifeBar.hidden = true; + lifeBarOutline.hidden = true; + lifeBarThreat.hidden = true; } function FadeOutGUI() { @@ -991,36 +992,36 @@ function FadeOutGUI() { function UnhideGUI() { - pauseButton.hidden = false; - circleReticle.hidden = false; - lifeBar.hidden = false; - lifeBarOutline.hidden = false; - lifeBarThreat.hidden = true; - + pauseButton.hidden = false; + circleReticle.hidden = false; + lifeBar.hidden = false; + lifeBarOutline.hidden = false; + lifeBarThreat.hidden = true; + // lifeBarThreat.alphaFrom( 1.0f, 0.0f, Easing.Quartic.easeIn); - pauseButton.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); - lifeBar.alphaFromTo( 1.0f, 0.0f, 0.5f, Easing.Quartic.easeIn); - lifeBarOutline.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); - circleReticle.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); - yield WaitForSeconds (1.0); - FallingPlayer.isPausable = true; + pauseButton.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); + lifeBar.alphaFromTo( 1.0f, 0.0f, 0.5f, Easing.Quartic.easeIn); + lifeBarOutline.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); + circleReticle.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); + yield WaitForSeconds (1.0); + FallingPlayer.isPausable = true; // lifeBarThreat.hidden = false; } function fadeIn( shouldUnhideGUI : boolean ) { - fadeSprite.hidden = false; - fadeSprite.alphaTo( 1.0f, 0.0f, Easing.Sinusoidal.easeOut); - yield WaitForSeconds(.5); - if (shouldUnhideGUI == true) {UnhideGUI();} - yield WaitForSeconds(.5); - fadeSprite.hidden = true; + fadeSprite.hidden = false; + fadeSprite.alphaTo( 1.0f, 0.0f, Easing.Sinusoidal.easeOut); + yield WaitForSeconds(.5); + if (shouldUnhideGUI == true) {UnhideGUI();} + yield WaitForSeconds(.5); + fadeSprite.hidden = true; } function fadeOut() { - fadeSprite.hidden = false; - fadeSprite.alphaTo( 1.0f, 1.0f, Easing.Sinusoidal.easeOut); - yield WaitForSeconds(1); - fadeSprite.hidden = true; + fadeSprite.hidden = false; + fadeSprite.alphaTo( 1.0f, 1.0f, Easing.Sinusoidal.easeOut); + yield WaitForSeconds(1); + fadeSprite.hidden = true; } @@ -1054,16 +1055,16 @@ function PauseGameNow() { //DisplayTiltOnPause(); } -function PauseGameBackgroundCheck() { - if (FallingPlayer.isPausable == true) { - if (Time.timeScale == 0) { - UnPauseGame(true); - } - else { - PauseGameNow(); - } - } -} +// function PauseGameBackgroundCheck() { +// if (FallingPlayer.isPausable == true) { +// if (Time.timeScale == 0) { +// UnPauseGame(true); +// } +// else { +// PauseGameNow(); +// } +// } +// } function setHoldingPauseButtonTrue() { holdingPauseButton = true; diff --git a/lifeCountdown.js b/lifeCountdown.js index 2ca1990..e9b1e47 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -3,6 +3,12 @@ var script : ScoreController; var LifeFlashTexture : GameObject; static var LifeFlashTextureScript : GUITextureLaunch; LifeFlashTextureScript = LifeFlashTexture.GetComponent("GUITextureLaunch"); + +var lifeFlashUIVR : GameObject; +var lifeFlashUIRenderer : Renderer; +var lifeFlashUIMatl : Material; +var peakLifeFlashValueVR : float = 0.33; + static var inOutro : boolean = false; static var isAlive : int = 0; @@ -15,6 +21,12 @@ function Awake () { } function Start () { + if (FallingLaunch.isVRMode) { + lifeFlashUIRenderer = lifeFlashUIVR.GetComponent.(); + lifeFlashUIMatl = lifeFlashUIRenderer.material; + lifeFlashUIMatl.color.a = 0; + } + maxSlowdownThreshold = MoveController.maxSlowdown - 1; isAlive = 1; Loop (); @@ -42,8 +54,21 @@ function ScoreLerpLoop () { yield WaitForSeconds(.25); } } - - + +function FadeFlashVR (timer : float, fadeType : FadeDir) { + + var start = fadeType == FadeDir.In? 0.0 : peakLifeFlashValueVR; + var end = fadeType == FadeDir.In? peakLifeFlashValueVR : 0.0; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + lifeFlashUIMatl.color.a = Mathf.Lerp(start, end, i); + yield; + } +} + function TickingAway (delay : float) { if (script.currentScore > 0) { if (MoveController.Slowdown > maxSlowdownThreshold) { @@ -55,12 +80,16 @@ function TickingAway (delay : float) { script.DecrementScore(delay); yield WaitForSeconds(delay); } - } - - else { + } else { isAlive = 0; FallingPlayer.isPausable = false; - LifeFlashTextureScript.FadeFlash (1, FadeDir.Out); + + if (FallingLaunch.isVRMode) { + FadeFlashVR (1, FadeDir.Out); + } else { + LifeFlashTextureScript.FadeFlash (1, FadeDir.Out); + } + FallingLaunch.secondsAlive = (Time.time - FallingPlayer.lifeStartTime); //Debug.Log("You died!"); @@ -86,11 +115,19 @@ function LifeFlashCheck (delay : float, score : int) { if (script.currentScore < score && inOutro == false) { //Camera.main.SendMessage("lifeFlashOut"); - LifeFlashTextureScript.FadeFlash (delay, FadeDir.In); + if (FallingLaunch.isVRMode) { + FadeFlashVR(delay, FadeDir.In); + } else { + LifeFlashTextureScript.FadeFlash (delay, FadeDir.In); + } yield WaitForSeconds(delay); // Camera.main.SendMessage("lifeFlashUp"); - LifeFlashTextureScript.FadeFlash (delay, FadeDir.Out); - yield WaitForSeconds((delay*3)); + if (FallingLaunch.isVRMode) { + FadeFlashVR(delay, FadeDir.Out); + } else { + LifeFlashTextureScript.FadeFlash (delay, FadeDir.Out); + } + yield WaitForSeconds((delay*3)); // stagger the flash timing (compare w/ `delay` above) } } From 169cbb2755beae99668f92393218f515d4853cd4 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 25 Oct 2017 22:08:27 -0700 Subject: [PATCH 32/77] Fix score reset for VR; isAlive global var deduping --- FallingPlayer.js | 17 ++- FallingPlayerStart.js | 248 +++++++++++++++++++++--------------------- FallingStartMenu.js | 3 +- ScoreController.js | 12 +- WormDeath.js | 4 +- lifeCountdown.js | 24 ++-- 6 files changed, 163 insertions(+), 145 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index ed661e6..3418e9f 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -44,8 +44,7 @@ var tiltAroundX : float; var script : ScoreController; script = GetComponent("ScoreController"); -static var isAlive : int = 0; -isAlive = lifeCountdown.isAlive; +static var isAlive : int = 1; static var lifeStartTime : float = 0; static var levelStartTime : float = 0; @@ -220,8 +219,12 @@ function DeathRespawn () { } FadeAudio (fadeTime, FadeDir.Out); - - script.ResetScore(0); + + // VR mode does its own score reset later, due to a longer fade interval/ + // interstitial 'back to menu' screen. + if (!FallingLaunch.isVRMode) { + script.ResetScore(); + } yield WaitForSeconds(1); @@ -265,6 +268,10 @@ function DeathRespawn () { // TODO: Fade out material here instead of toggling the whole object outright? deathUIVR.SetActive(false); + + // resetting score to max here for VR, to avoid the score + // ticking away over the preceding ~4 WaitForSeconds. + script.ResetScore(); lerpControlIn(3.0); @@ -310,7 +317,7 @@ function LatestCheckpointRespawn () { } function ShowDeathHelp() { - if (introComponent && !FallingLaunch.isVRMode) { + if (introComponent) { introComponent.DeathHelp(); } } diff --git a/FallingPlayerStart.js b/FallingPlayerStart.js index 14a14f6..cbd1697 100644 --- a/FallingPlayerStart.js +++ b/FallingPlayerStart.js @@ -1,156 +1,156 @@ -#pragma strict - - public var force:float = 1.0; - var dir : Vector3 = Vector3.zero; - public var touchingSomething:boolean = false; - -private var isLoading = false; -var levelToLoad : String = "scene-helix"; -var levelToLoad2 : String = "scene-bluesky"; -var levelToLoad3 : String = "falling-column-space"; -var levelToLoad4 : String = "scene-bluesky"; - -// Move object using accelerometer -var speed = 5.0; -var target : Transform; -var smooth = 2.0; -var tiltAngle = 30.0; - -var script : ScoreController; -script = GetComponent("ScoreController"); - -static var isAlive : boolean; - -function DeathRespawn () { - var respawnPosition = Respawn.currentRespawn.transform.position; - Camera.main.SendMessage("fadeOut"); - isAlive = true; - gameObject.SendMessage ("ResetScore", 0); - yield WaitForSeconds(1); -// gameObject.SendMessage ("DecrementScore"); -// gameObject.SendMessage ("ZeroScore", 1); - -// Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too - GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); - // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider. - transform.position = respawnPosition; // + Vector3.up; - Camera.main.SendMessage("fadeIn"); - } +// #pragma strict + +// public var force:float = 1.0; +// var dir : Vector3 = Vector3.zero; +// public var touchingSomething:boolean = false; + +// private var isLoading = false; +// var levelToLoad : String = "scene-helix"; +// var levelToLoad2 : String = "scene-bluesky"; +// var levelToLoad3 : String = "falling-column-space"; +// var levelToLoad4 : String = "scene-bluesky"; + +// // Move object using accelerometer +// var speed = 5.0; +// var target : Transform; +// var smooth = 2.0; +// var tiltAngle = 30.0; + +// var script : ScoreController; +// script = GetComponent("ScoreController"); + +// static var isAlive : boolean; + +// function DeathRespawn () { +// var respawnPosition = Respawn.currentRespawn.transform.position; +// Camera.main.SendMessage("fadeOut"); +// isAlive = true; +// gameObject.SendMessage ("ResetScore", 0); +// yield WaitForSeconds(1); +// // gameObject.SendMessage ("DecrementScore"); +// // gameObject.SendMessage ("ZeroScore", 1); + +// // Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too +// GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); +// // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider. +// transform.position = respawnPosition; // + Vector3.up; +// Camera.main.SendMessage("fadeIn"); +// } -function Awake () { - // Make the game run as fast as possible in the web player -// Application.targetFrameRate = 60; - Time.timeScale = 1.0; -} +// function Awake () { +// // Make the game run as fast as possible in the web player +// // Application.targetFrameRate = 60; +// Time.timeScale = 1.0; +// } -function Update () { - var dir : Vector3 = Vector3.zero; - - var tiltAroundZ = -Input.acceleration.y * tiltAngle; - var tiltAroundX = -Input.acceleration.x * tiltAngle; - var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); - - // Dampen towards the target rotation - transform.rotation = Quaternion.Slerp(transform.rotation, target, - Time.deltaTime * smooth);; - // Debug.Log(isAlive); -// Debug.Log(script.currentScore); - } +// function Update () { +// var dir : Vector3 = Vector3.zero; + +// var tiltAroundZ = -Input.acceleration.y * tiltAngle; +// var tiltAroundX = -Input.acceleration.x * tiltAngle; +// var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); + +// // Dampen towards the target rotation +// transform.rotation = Quaternion.Slerp(transform.rotation, target, +// Time.deltaTime * smooth);; +// // Debug.Log(isAlive); +// // Debug.Log(script.currentScore); +// } -// private var speed : Vector3 = Vector3 (3, 0, 0); -// var startingPosition = (0, 129, 0); -var deadlyObjectName : String = "DeathByFire"; -var initialRespawn : Respawn; // set this to the initial respawn point for the level. -// var damping:float = 0.7; // is this necessary? +// // private var speed : Vector3 = Vector3 (3, 0, 0); +// // var startingPosition = (0, 129, 0); +// var deadlyObjectName : String = "DeathByFire"; +// var initialRespawn : Respawn; // set this to the initial respawn point for the level. +// // var damping:float = 0.7; // is this necessary? -// textfield to hold the score and score variable -private var textfield:GUIText; -private var score:int; +// // textfield to hold the score and score variable +// private var textfield:GUIText; +// private var score:int; -public var simulateAccelerometer:boolean = false; +// public var simulateAccelerometer:boolean = false; -function OnCollisionEnter (collision : Collision) { -// Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); - Screen.sleepTimeout = 0.0f; -// collider.attachedRigidbody.velocity.y *= damping; +// function OnCollisionEnter (collision : Collision) { +// // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); +// Screen.sleepTimeout = 0.0f; +// // collider.attachedRigidbody.velocity.y *= damping; -// collider.attachedRigidbody.AddForce(dir * force); +// // collider.attachedRigidbody.AddForce(dir * force); -// iPhoneUtils.Vibrate (); -// var relativeStartingPosition = transform.InverseTransformPoint(0, -500, 0); +// // iPhoneUtils.Vibrate (); +// // var relativeStartingPosition = transform.InverseTransformPoint(0, -500, 0); -// if (collision.gameObject.name == deadlyObjectName){ - if (collision.gameObject.CompareTag ("Death")) { - DeathRespawn (); - } +// // if (collision.gameObject.name == deadlyObjectName){ +// if (collision.gameObject.CompareTag ("Death")) { +// DeathRespawn (); +// } -// if (collision.gameObject.layer == 8){ -// collider.attachedRigidbody.transform.Translate(relativeStartingPosition); +// // if (collision.gameObject.layer == 8){ +// // collider.attachedRigidbody.transform.Translate(relativeStartingPosition); -// Destroy the projectile -// Destroy (gameObject); -//if (relativeStartingPosition.y > 100) -// Debug.Log("You've moved up more than 100 units"); +// // Destroy the projectile +// // Destroy (gameObject); +// //if (relativeStartingPosition.y > 100) +// // Debug.Log("You've moved up more than 100 units"); -} +// } -// function FixedUpdate () { -// rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);} +// // function FixedUpdate () { +// // rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);} -function OnTriggerEnter (other : Collider) { - if (other.gameObject.CompareTag ("Score")){ - // Debug.Log("You scored!"); - gameObject.SendMessage ("IncrementScore", 10); -// if (audio) -// { -// audio.Play(); -// } - } +// function OnTriggerEnter (other : Collider) { +// if (other.gameObject.CompareTag ("Score")){ +// // Debug.Log("You scored!"); +// gameObject.SendMessage ("IncrementScore", 10); +// // if (audio) +// // { +// // audio.Play(); +// // } +// } - if (other.gameObject.CompareTag ("CloudLevelSelect")){ - isLoading = true; - Camera.main.SendMessage("fadeOut"); - yield WaitForSeconds(1); +// if (other.gameObject.CompareTag ("CloudLevelSelect")){ +// isLoading = true; +// Camera.main.SendMessage("fadeOut"); +// yield WaitForSeconds(1); - Application.LoadLevel(levelToLoad); - } +// Application.LoadLevel(levelToLoad); +// } - if (other.gameObject.CompareTag ("SunsetLevelSelect")){ - isLoading = true; - Camera.main.SendMessage("fadeOut"); - yield WaitForSeconds(1); +// if (other.gameObject.CompareTag ("SunsetLevelSelect")){ +// isLoading = true; +// Camera.main.SendMessage("fadeOut"); +// yield WaitForSeconds(1); - Application.LoadLevel(levelToLoad2); - } +// Application.LoadLevel(levelToLoad2); +// } - if (other.gameObject.CompareTag ("SpaceLevelSelect")){ - isLoading = true; - Camera.main.SendMessage("fadeOut"); - yield WaitForSeconds(1); +// if (other.gameObject.CompareTag ("SpaceLevelSelect")){ +// isLoading = true; +// Camera.main.SendMessage("fadeOut"); +// yield WaitForSeconds(1); - Application.LoadLevel(levelToLoad3); - } +// Application.LoadLevel(levelToLoad3); +// } - if (other.gameObject.CompareTag ("SkyLevelSelect")){ - isLoading = true; - Camera.main.SendMessage("fadeOut"); - yield WaitForSeconds(1); +// if (other.gameObject.CompareTag ("SkyLevelSelect")){ +// isLoading = true; +// Camera.main.SendMessage("fadeOut"); +// yield WaitForSeconds(1); - Application.LoadLevel(levelToLoad4); - } +// Application.LoadLevel(levelToLoad4); +// } -} +// } -function OnGUI() { -if (isLoading) { -GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70), "Loading...", "mainMenuTitle"); } -} +// function OnGUI() { +// if (isLoading) { +// GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70), "Loading...", "mainMenuTitle"); } +// } -@script AddComponentMenu("Scripts/FallingPlayerStart") \ No newline at end of file +// @script AddComponentMenu("Scripts/FallingPlayerStart") \ No newline at end of file diff --git a/FallingStartMenu.js b/FallingStartMenu.js index 3567a09..6d0fb22 100644 --- a/FallingStartMenu.js +++ b/FallingStartMenu.js @@ -45,8 +45,7 @@ private var mainCamera: Camera; var script : ScoreController; script = GetComponent("ScoreController"); -static var isAlive : int = 0; -isAlive = lifeCountdown.isAlive; +var isAlive : int = 1; static var isPausable : boolean = true; diff --git a/ScoreController.js b/ScoreController.js index 49dd6bf..1cd73fe 100644 --- a/ScoreController.js +++ b/ScoreController.js @@ -1,14 +1,14 @@ #pragma strict // Keep track of the player's main score -static var currentScore : float = 20f; -static var maxScore = 25f; +static var currentScore : float = 20.0; +static var maxScore : float = 25.0; // Keep track of the currently visible score -static var visibleScore : float = 20f; +static var visibleScore : float = 20.0; function Start() { - ResetScore (25); + ResetScore (); } function LerpVisibleScore (start : float, end : float, timer : float) { @@ -43,4 +43,6 @@ function ScoreUpdate ( timer : float) { // Debug.Log("Your visibleScore is: " + visibleScore + " and your currentScore is: " + currentScore); } -function ResetScore ( i : float ) {currentScore = maxScore;} \ No newline at end of file +function ResetScore () { + currentScore = maxScore; +} \ No newline at end of file diff --git a/WormDeath.js b/WormDeath.js index 8803c28..d4f7462 100644 --- a/WormDeath.js +++ b/WormDeath.js @@ -8,9 +8,9 @@ function Update () { var hit : RaycastHit; if (Physics.Raycast (transform.position, Vector3.up, hit, 100)) { //Debug.Log(hit.distance); - if (hit.rigidbody != null && lifeCountdown.isAlive == 1) { + if (hit.rigidbody != null && FallingPlayer.isAlive == 1) { Debug.Log(hit.distance); - lifeCountdown.isAlive = 0; + FallingPlayer.isAlive = 0; GetComponent(FallingPlayer).DeathRespawn (); } } diff --git a/lifeCountdown.js b/lifeCountdown.js index e9b1e47..fb384a8 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -11,7 +11,6 @@ var peakLifeFlashValueVR : float = 0.33; static var inOutro : boolean = false; -static var isAlive : int = 0; var UIscriptName : GameObject; private var maxSlowdownThreshold : float; @@ -28,7 +27,6 @@ function Start () { } maxSlowdownThreshold = MoveController.maxSlowdown - 1; - isAlive = 1; Loop (); Loop2 (); ScoreLerpLoop (); @@ -70,6 +68,11 @@ function FadeFlashVR (timer : float, fadeType : FadeDir) { } function TickingAway (delay : float) { + // Early return if player's not alive, so we stop flashing red: + if (FallingPlayer.isAlive == 0) { + return; + } + if (script.currentScore > 0) { if (MoveController.Slowdown > maxSlowdownThreshold) { script.DecrementScore(delay); @@ -81,11 +84,11 @@ function TickingAway (delay : float) { yield WaitForSeconds(delay); } } else { - isAlive = 0; + FallingPlayer.isAlive = 0; FallingPlayer.isPausable = false; if (FallingLaunch.isVRMode) { - FadeFlashVR (1, FadeDir.Out); + FadeFlashVR(1, FadeDir.Out); } else { LifeFlashTextureScript.FadeFlash (1, FadeDir.Out); } @@ -99,8 +102,11 @@ function TickingAway (delay : float) { FallingLaunch.secondsAlive ); - yield GetComponent(FallingPlayer).DeathRespawn (); - GetComponent(FallingPlayer).ShowDeathHelp(); + yield GetComponent(FallingPlayer).DeathRespawn(); + + if (!FallingLaunch.isVRMode) { + GetComponent(FallingPlayer).ShowDeathHelp(); + } // New GameAnalytics "Design" event syntax: // GameAnalytics.NewDesignEvent (string eventName, float eventValue); @@ -112,7 +118,11 @@ function TickingAway (delay : float) { function LifeFlashCheck (delay : float, score : int) { - + // Early return if player's not alive, so we stop flashing red: + if (!FallingPlayer.isAlive) { + return; + } + if (script.currentScore < score && inOutro == false) { //Camera.main.SendMessage("lifeFlashOut"); if (FallingLaunch.isVRMode) { From a2f2fb094db5690b87e885784c8abe871d020315 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Thu, 26 Oct 2017 23:06:39 -0700 Subject: [PATCH 33/77] Improve VR fade-to-black with two spheres and distinct shaders --- FallingPlayer.js | 93 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 3418e9f..0944c3e 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -57,18 +57,23 @@ var isExitingLevel : boolean = false; var UIscriptName : GameObject; static var UIscriptComponent : fallingUITest; -// todo: handle spherical fade-out UI in script -// var blackUIVR : GameObject; +var deathFadeUIVR : GameObject; +private var deathFadeUIVRRenderer : Renderer; +private var deathFadeUIVRMatl : Material; -var deathUIVR : GameObject; +var opaqueDeathFadeUIVR : GameObject; +private var opaqueDeathFadeUIVRRenderer : Renderer; +private var opaqueDeathFadeUIVRMatl : Material; + +var deathPauseUIVR : GameObject; var scoreUIVR : GameObject; -var scoreUIVRRenderer : Renderer; -var scoreUIVRMatl : Material; -var peakScoreFlashValueVR : float = 1.0; +private var scoreUIVRRenderer : Renderer; +private var scoreUIVRMatl : Material; +private var peakScoreFlashValueVR : float = 1.0; var reticleVRUIObj : GameObject; -var reticleVRUIScript : VRLifeMeter; +private var reticleVRUIScript : VRLifeMeter; var clearDestroyedObjects : boolean = false; @@ -121,6 +126,28 @@ function Start() { scoreUIVRRenderer = scoreUIVR.GetComponent.(); scoreUIVRMatl = scoreUIVRRenderer.material; scoreUIVRMatl.color.a = 0; + + // Hack to have two separate death/fade-to-black sphere objects, + // but neither shader does everything. The inverted transparent shader occludes + // all physical objects, but the UIToolkit one is needed for covering light halos. + // Both materials have manual RenderQueue settings of 5000 (the max). + if (deathFadeUIVR && opaqueDeathFadeUIVR) { + deathFadeUIVRRenderer = deathFadeUIVR.GetComponent.(); + deathFadeUIVRMatl = deathFadeUIVRRenderer.material; + + opaqueDeathFadeUIVRRenderer = opaqueDeathFadeUIVR.GetComponent.(); + opaqueDeathFadeUIVRMatl = opaqueDeathFadeUIVRRenderer.material; + + if (deathFadeUIVRMatl.HasProperty("_Color")) { + deathFadeUIVRMatl.color.a = 0; + } + if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) { + var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor"); + currentColor.a = 0; + opaqueDeathFadeUIVRMatl.SetColor("_TintColor", currentColor); + } + } + if (reticleVRUIObj) { reticleVRUIScript = reticleVRUIObj.GetComponent.(); } else { @@ -211,7 +238,11 @@ function DeathRespawn () { lifeStartTime = Time.time; var respawnPosition = Respawn.currentRespawn.transform.position; - UIscriptComponent.fadeOut(); + if (FallingLaunch.isVRMode) { + DeathFadeVR(1.0, FadeDir.Out); + } else { + UIscriptComponent.fadeOut(); + } // Camera.main.SendMessage("fadeOut"); if (levelChangeBackdrop == true) { @@ -250,24 +281,26 @@ function DeathRespawn () { MoveController.controlMultiplier = 1; - if (FallingLaunch.isVRMode && deathUIVR) { + if (FallingLaunch.isVRMode && deathPauseUIVR && deathFadeUIVR) { rb.isKinematic = true; isAlive = 0; - deathUIVR.SetActive(true); + deathPauseUIVR.SetActive(true); reticleVRUIScript.FadeReticleOut(0.5); - yield UIscriptComponent.fadeIn(false); + DeathFadeVR(1.0, FadeDir.In); + // yield UIscriptComponent.fadeIn(false); yield WaitForSeconds(4); - yield UIscriptComponent.fadeOut(); - // UIscriptComponent.UnPauseGame(true); + yield DeathFadeVR(1.0, FadeDir.Out); + // yield UIscriptComponent.fadeOut(); + // // UIscriptComponent.UnPauseGame(true); rb.isKinematic = false; // TODO: Fade out material here instead of toggling the whole object outright? - deathUIVR.SetActive(false); + deathPauseUIVR.SetActive(false); // resetting score to max here for VR, to avoid the score // ticking away over the preceding ~4 WaitForSeconds. @@ -275,8 +308,9 @@ function DeathRespawn () { lerpControlIn(3.0); - yield UIscriptComponent.fadeIn(false); - yield WaitForSeconds(1); + yield DeathFadeVR(1.0, FadeDir.In); + // yield UIscriptComponent.fadeIn(false); + // yield WaitForSeconds(1); reticleVRUIScript.FadeReticleIn(1.5); @@ -347,7 +381,7 @@ function Update () { } // disable VR mode and return to menu on screen touch while dead: - if (FallingLaunch.isVRMode && isAlive == 0 && deathUIVR.activeInHierarchy) { + if (FallingLaunch.isVRMode && isAlive == 0 && deathPauseUIVR.activeInHierarchy) { for (var i = 0; i < Input.touchCount; ++i) { if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { FallingLaunch.isVRMode = false; @@ -482,6 +516,31 @@ function ScoreFlashVR (timer : float, fadeType : FadeDir) { } } +function DeathFadeVR (timer : float, fadeType : FadeDir) { + + var start = fadeType == FadeDir.In ? 1.0 : 0.0; + var end = fadeType == FadeDir.In ? 0.0 : 1.0; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + // ease-out lerp, to match non-VR fade timing: + var t : float = Mathf.Sin(i * Mathf.PI * 0.5f); + + if (deathFadeUIVRMatl.HasProperty("_Color")) { + deathFadeUIVRMatl.color.a = Mathf.Lerp(start, end, t); + } + if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) { + var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor"); + currentColor.a = Mathf.Lerp(start, end, t); + opaqueDeathFadeUIVRMatl.SetColor("_TintColor", currentColor); + } + + yield; + } +} + function OnCollisionEnter (collision : Collision) { // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); // Screen.sleepTimeout = 0.0f; From add0da21ec810224372cce0940dcc1b40d82cb1b Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Sat, 28 Oct 2017 01:55:29 -0400 Subject: [PATCH 34/77] VR explanatory screen from start menu --- Respawn.js | 22 +-- fallingStartMenuUI.js | 321 +++++++++++++++++++++++++----------------- 2 files changed, 205 insertions(+), 138 deletions(-) diff --git a/Respawn.js b/Respawn.js index 7a9f915..d76b8c2 100644 --- a/Respawn.js +++ b/Respawn.js @@ -46,13 +46,13 @@ var mainRespawnScript : boolean = false; private var audioSource: AudioSource; function Start() -{ +{ // Get some of the objects we need later. - // This is often done in a script's Start function. That way, we've got all our initialization code in one place, + // This is often done in a script's Start function. That way, we've got all our initialization code in one place, // And can simply count on the code being fine. RespawnState = 0; - + // set up the looping "RespawnActive" sound, but leave it switched off for now: if (SFXRespawnActiveLoop) { @@ -61,15 +61,15 @@ function Start() audioSource.loop = true; audioSource.playOnAwake = false; } - + // Assign the respawn point to be this one - Since the player is positioned on top of a respawn point, it will come in and overwrite it. // This is just to make sure that we always have a respawn point. - // mainRespawnScript boolean is to keep multiple instances of Respawn from all trying to write + // mainRespawnScript boolean is to keep multiple instances of Respawn from all trying to write // to PlayerPrefs within a single Update call. - if (mainRespawnScript) { + if (mainRespawnScript) { if (PlayerPrefs.HasKey("LatestLevel") && PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) - { + { myCheckpoint = PlayerPrefs.GetString("LatestCheckpoint"); currentRespawn = GameObject.Find(myCheckpoint).GetComponent(Respawn); var tempPlayer : GameObject = GameObject.Find("Player"); @@ -86,7 +86,7 @@ function Start() } else { currentRespawn = initialRespawn; - } + } } SaveCheckpoint(); @@ -99,11 +99,11 @@ function OnTriggerEnter(other : Collider) { // turn the old respawn point off //currentRespawn.SetInactive (); - + // play the "Activated" one-shot sound effect if one has been supplied: if (SFXRespawnActivate) AudioSource.PlayClipAtPoint(SFXRespawnActivate, transform.position, SFXVolume); - + // Set the current respawn point to be us and make it visible. currentRespawn = this; } @@ -116,7 +116,7 @@ function OnApplicationPause(pauseStatus: boolean) { } } -// NB: We currently only persistently save checkpoints on pause +// NB: We currently only persistently save checkpoints on pause // (including app-to-background auto-pausing) and level loading. // Writing to PlayerPrefs can be slow and introduce visual stutter, so we do NOT // save in prefs when you pass a checkpoint during gameplay, although we do update the global diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 2bca88e..fbfab89 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -73,6 +73,9 @@ var openSiteButtonText : UIButton; var vrModeButton : UIButton; var vrModeLabel : UITextInstance; +var vrModeLaunchButton : UIButton; +var vrExplanatoryText : UITextInstance; + private var savedTimeScale:float; var canShowStart : boolean; @@ -90,7 +93,7 @@ var fallingLaunchComponent : FallingLaunch; function Awake () { //Input.compensateSensors = true; - + if (Debug.isDebugBuild) { Debug.Log("My screen orientation is " + Screen.orientation); @@ -108,20 +111,20 @@ function Awake () { Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; - // We have to use autoRotation here, due to crashes on force-changing Screen.orientation - // in conjunction with permitted-via-settings autoRotation + // We have to use autoRotation here, due to crashes on force-changing Screen.orientation + // in conjunction with permitted-via-settings autoRotation // (if app launches mid-screen-rotation?). // Source: https://forum.unity.com/threads/unitydefaultviewcontroller-should-be-used-only-if-unity-is-set-to-autorotate.314542/#post-2833628 Screen.orientation = ScreenOrientation.AutoRotation; - + // on iPhones, we could probably assume input to be landscape-left most of the time, // unless the device is known to be in landscape-right // (the edge cases are iPads lying on a flat surface, which could have either screen orientation): - + // This function waits an [arbitrary] second for iOS's autorotation to settle, then locks it. // It's not yielded, so it doesn't delay execution of the `hasSetOrientation = true` below. LockDeviceOrientation(1.0f); - + if (Debug.isDebugBuild) { Debug.Log("My final screen orientation is " + Screen.orientation); } @@ -137,7 +140,7 @@ function Awake () { } function LockDeviceOrientation (waitTime: float) { - // iOS/Unity can give strange/wrong orientation values while screen is mid-rotation + // iOS/Unity can give strange/wrong orientation values while screen is mid-rotation //or close to flat, so we manually add a wait yield. yield WaitForSeconds(waitTime); @@ -162,7 +165,7 @@ function LockDeviceOrientation (waitTime: float) { break; } - return; + return; } @@ -170,7 +173,7 @@ function HandleDeviceOrientationMismatch() { if (FallingLaunch.initialInputDeviceOrientation != Input.deviceOrientation) { GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "DeviceOrientationCheck:CachedAndCurrentMismatch:" + Input.deviceOrientation + ":" + FallingLaunch.initialInputDeviceOrientation, + "DeviceOrientationCheck:CachedAndCurrentMismatch:" + Input.deviceOrientation + ":" + FallingLaunch.initialInputDeviceOrientation, 0.0 ); @@ -185,7 +188,7 @@ function HandleDeviceOrientationMismatch() { } LockLandscapeRightOrientation(); } - + } else { if (Debug.isDebugBuild) { Debug.Log( @@ -208,21 +211,22 @@ function LockLandscapeRightOrientation () { Screen.orientation = ScreenOrientation.LandscapeRight; FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalFlipped; - FallingLaunch.flipMultiplier = -FallingLaunch.flipMultiplier; + FallingLaunch.flipMultiplier = -FallingLaunch.flipMultiplier; } function Start () { - + // resets all prefs on launch to simplify debugging: + // PlayerPrefs.DeleteAll(); if (PlayerPrefs.HasKey("HighestLevel") == false) { FallingLaunch.levelAchieved = Application.loadedLevel + 1; PlayerPrefs.SetInt("HighestLevel", FallingLaunch.levelAchieved); } - + FallingLaunch.levelAchieved = PlayerPrefs.GetInt("HighestLevel"); // yield WaitForSeconds(0.5f); -// Testing to see if disabling this hard coded screen.orientation will allow auto detection of landscape +// Testing to see if disabling this hard coded screen.orientation will allow auto detection of landscape // right or left mode on startup. // Screen.orientation = ScreenOrientation.LandscapeLeft; @@ -242,7 +246,7 @@ function Start () { else if (FallingLaunch.levelAchieved == 4) { level2Unlocked = true; level3Unlocked = true; - } + } else if (FallingLaunch.levelAchieved == 3) { level2Unlocked = true; } @@ -252,7 +256,7 @@ function Start () { level3Unlocked = true; level4Unlocked = true; } - + bgSpriteStart = UIT.firstToolkit.addSprite( "menuBackground.png", 0, 0, 2 ); bgSpriteStart.positionCenter(); bgSpriteStart.scaleTo( 0.0001f, new Vector3( (Screen.width * 6), (Screen.height * 6), 1 ), Easing.Sinusoidal.easeOut); @@ -263,7 +267,7 @@ function Start () { bgSprite.scaleTo( 0.01f, new Vector3( (Screen.width * 6), (Screen.height * 6), 1 ), Easing.Sinusoidal.easeOut); bgSprite.alphaTo( 0.01f, 0.94f, Easing.Sinusoidal.easeOut); bgSprite.hidden = true; - + pauseButton = UIButton.create("pauseWhite.png","pauseGray.png", 0, 0); pauseButton.pixelsFromTopRight( 5, 5 ); pauseButton.highlightedTouchOffsets = new UIEdgeOffsets(30); @@ -280,7 +284,7 @@ function Start () { boldText = new UIText( "font-bold", "font-bold.png" ); thinText = new UIText( "font-thin", "font-thin.png" ); - + boldText.alignMode = UITextAlignMode.Center; boldText.verticalAlignMode = UITextVerticalAlignMode.Middle; boldText.wrapMode = UITextLineWrapMode.MinimumLength; @@ -298,25 +302,42 @@ function Start () { text2.positionCenter(); //text3 = thinText.addTextInstance( "Music by Evan Kubota\nTextures: nobiax\nSound effects: freesound.org", 0, 0 ); - text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", + text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", 0, 0, 0.8f, 1, Color.white, UITextAlignMode.Center, UITextVerticalAlignMode.Bottom ); text3.positionFromBottom(.3f); // TODO: Use real VR Mode icon and button sprite here. - // HACK: reusing existing button sprite as a transparent background + // HACK: reusing existing button sprite as a transparent background // for the "VR Mode" text label (which is not clickable): - vrModeButton = UIButton.create("newgame.png", "newgame.png", 0,0); + vrModeButton = UIButton.create("newgame.png", "newgame.png", 0,0); vrModeButton.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); vrModeButton.normalTouchOffsets = new UIEdgeOffsets( 40 ); vrModeButton.highlightedTouchOffsets = new UIEdgeOffsets( 40 ); - vrModeButton.onTouchUpInside += LaunchVRMode; + vrModeButton.onTouchUpInside += OpenVRModeMenu; vrModeButton.alphaTo(0.01f, 0.0f, Easing.Sinusoidal.easeOut); - // vrModeButton.hidden = true; - vrModeLabel = boldText.addTextInstance( "VR MODE", 0, 0 ); vrModeLabel.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + vrModeLaunchButton = UIButton.create("startDown.png","startDown.png", 0, 0); + vrModeLaunchButton.positionFromCenter(.1, 0); + // vrModeLaunchButton.positionFromTopRight(buttonScaleFactor,0.2f); + vrModeLaunchButton.onTouchUpInside += LaunchVRMode; + vrModeLaunchButton.onTouchDown += fadeInVRLaunchButton; + vrModeLaunchButton.onTouchUp += fadeOutVRLaunchButton; + + var vrExplanatoryString : String = + "VR MODE REQUIRES GOOGLE CARDBOARD.\n\nPRESS PLAY BELOW, THEN PUT ON HEADSET."; + + vrExplanatoryText = + thinText.addTextInstance( vrExplanatoryString, 0, 0); + vrExplanatoryText.positionFromCenter(-.2, 0); + + vrModeButton.hidden = true; + vrModeLabel.hidden = true; + vrModeLaunchButton.hidden = true; + vrExplanatoryText.hidden = true; + optionsButton = UIButton.create("options.png", "options.png", 0,0); //optionsButton.positionFromBottomRight( .05f, .05f ); @@ -332,8 +353,8 @@ function Start () { tiltText2.verticalAlignMode = UITextVerticalAlignMode.Bottom; tiltText2.positionFromRight( -.16f, .52f ); tiltText2.hidden = true; - //public UITextInstance addTextInstance( string text, float xPos, float yPos, - //float scale, int depth, Color color, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode ) + //public UITextInstance addTextInstance( string text, float xPos, float yPos, + //float scale, int depth, Color color, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode ) invertHorizAxisText = thinText.addTextInstance( "HORIZONTAL AXIS", 0, 0 ); invertHorizAxisText.verticalAlignMode = UITextVerticalAlignMode.Bottom; invertHorizAxisText.positionFromRight( .00f, .52f ); @@ -382,7 +403,7 @@ function Start () { if (PlayerPrefs.GetInt("invertHorizAxis", 0) == 1) {FallingLaunch.invertHorizAxisVal = -1;} else {FallingLaunch.invertHorizAxisVal = 1;} if (PlayerPrefs.GetInt("invertVertAxis", 0) == 1) {FallingLaunch.invertVertAxisVal = -1;} - else {FallingLaunch.invertVertAxisVal = 1;} + else {FallingLaunch.invertVertAxisVal = 1;} tiltText1 = thinText.addTextInstance( "CHOOSE A NEUTRAL TILT ANGLE", 0, 0 ); tiltText1.pixelsFromCenter( -40, 0 ); @@ -439,17 +460,17 @@ function Start () { openSiteButtonText = UIButton.create("tutorialBackground.png","tutorialBackground.png", 40, 40); openSiteButtonText.positionFromCenter(0,0); openSiteButtonText.hidden = true; - openSiteButtonText.onTouchUpInside += OpenFallingSite; + openSiteButtonText.onTouchUpInside += OpenFallingSite; openSiteButtonText.scaleTo( 0.1f, new Vector3( (Screen.width), 3, 1 ), Easing.Sinusoidal.easeOut); openSiteButtonText.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); - + text1.hidden = true; text2.hidden = true; text3.hidden = true; tiltWarning = UIButton.create("tiltwarning.png","tiltwarning.png", 0, 0); tiltWarning.positionFromTop(buttonScaleFactor); - + rightArrow = UIButton.create("startDown.png","startDown.png", 0, 0); rightArrow.positionFromTopRight(buttonScaleFactor,0.2f); rightArrow.onTouchUpInside += ResumeGame; @@ -462,7 +483,7 @@ function Start () { //Debug.Log ("your screen aspect ratio is " + screenAspectRatio); BackToPauseMenuButton.normalTouchOffsets = new UIEdgeOffsets( 30 ); BackToPauseMenuButton.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); - + loadLevelOne = UIButton.create("level1.png","level1.png", 0, 0); loadLevelOne.positionFromTopLeft(buttonScaleFactor,0.05f); loadLevelOne.onTouchUpInside += LoadLevel1ViaStart; @@ -484,8 +505,8 @@ function Start () { } var middleIconAdjustRatio : float = UIT.isHD ? calculatedMiddleIconRatio : 0.3f; - - // Debug.Log("buttonScaleFactor: " + buttonScaleFactor); + + // Debug.Log("buttonScaleFactor: " + buttonScaleFactor); // Debug.Log("ScreenW: " + ScreenW); // Debug.Log("calculatedMiddleIconRatio: " + calculatedMiddleIconRatio); // Debug.Log("middleIconAdjustRatio: " + middleIconAdjustRatio); @@ -500,7 +521,7 @@ function Start () { loadLevelTwo.onTouchDown += downLevel2; } else {loadLevelTwo.onTouchUpInside += DoNothing;} - + loadLevelThree = UIButton.create("level3.png","level3.png", 0, 0); // var level3Space : float = (ScreenW * 0.9f) / 3.0; @@ -510,10 +531,10 @@ function Start () { if (level3Unlocked) { loadLevelThree.onTouchUpInside += LoadLevel3ViaStart; loadLevelThree.onTouchUp += upLevel3; - loadLevelThree.onTouchDown += downLevel3; + loadLevelThree.onTouchDown += downLevel3; } - else {loadLevelThree.onTouchUpInside += DoNothing;} - + else {loadLevelThree.onTouchUpInside += DoNothing;} + loadLevelFour = UIButton.create("level4.png","level4.png", 0, 0); loadLevelFour.positionFromTopRight(buttonScaleFactor,0.05f); if (level4Unlocked) { @@ -521,17 +542,17 @@ function Start () { loadLevelFour.onTouchUp += upLevel4; loadLevelFour.onTouchDown += downLevel4; } - else {loadLevelFour.onTouchUpInside += DoNothing;} + else {loadLevelFour.onTouchUpInside += DoNothing;} loadLevelOne.hidden = true; loadLevelTwo.hidden = true; loadLevelThree.hidden = true; loadLevelFour.hidden = true; - + leftArrow = UIButton.create("chooselevelDown.png","chooselevelDown.png", 0, 0); leftArrow.positionFromTopLeft(buttonScaleFactor,0.2f); leftArrow.hidden = true; - + if (level2Unlocked == true) { leftArrow.onTouchUpInside += LevelSelect; leftArrow.onTouchDown += fadeInLeftArrow; @@ -546,20 +567,20 @@ function Start () { tiltWarning.hidden = true; rightArrow.hidden = true; - BackToPauseMenuButton.onTouchUpInside += BackToPauseMenu; + BackToPauseMenuButton.onTouchUpInside += BackToPauseMenu; BackToPauseMenuButton.hidden = true; - + loadingLabel = UIButton.create("loading.png","loading.png", 20, 20); loadingLabel.positionFromCenter(0f, 0f); loadingLabel.hidden = true; - + loadNewLevelButton = UIButton.create("newlevel.png","newlevel.png", 40, 40); loadNewLevelButton.positionFromBottomLeft(.05f, .05f); loadNewLevelButton.normalTouchOffsets = new UIEdgeOffsets( 30 ); loadNewLevelButton.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); loadNewLevelButton.onTouchUpInside += LevelSelect; loadNewLevelButton.hidden = true; - + aboutButtonStart = UIButton.create("aboutDots.png","aboutDots.png", 40, 40); aboutButtonStart.normalTouchOffsets = new UIEdgeOffsets( 30 ); aboutButtonStart.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); @@ -567,7 +588,7 @@ function Start () { //aboutButtonStart.pixelsFromTopRight ( 14, 14 ); aboutButtonStart.positionFromTopRight ( .05f, (.05f * screenAspectRatio) ); aboutButtonStart.onTouchUpInside += OpenAbout; -// aboutButtonStart.onTouchUp += fadeOutAbout; +// aboutButtonStart.onTouchUp += fadeOutAbout; // aboutButtonStart.onTouchDown += fadeInAbout; aboutButtonStart.hidden = true; @@ -575,7 +596,7 @@ function Start () { howToButton.normalTouchOffsets = new UIEdgeOffsets( 30 ); howToButton.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); howToButton.centerize(); - //howToButton.pixelsFromTopLeft ( 14, 14 ); + //howToButton.pixelsFromTopLeft ( 14, 14 ); howToButton.positionFromTopLeft ( .05f, (.05f * screenAspectRatio) ); howToButton.onTouchUpInside += OpenHowTo; howToButton.hidden = true; @@ -605,14 +626,21 @@ function ShowStart() { optionsButton.alphaFromTo(2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); } if (level2Unlocked) {leftArrow.hidden = false;} - + rightArrow.hidden = false; aboutButtonStart.hidden = false; howToButton.hidden = false; + vrModeButton.hidden = false; + vrModeLabel.hidden = false; + rightArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); leftArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); aboutButtonStart.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); howToButton.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + + // fake button remains transparent: + // vrModeButton.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + vrModeLabel.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); canShowStart = false; //yield FixWrongInitialScreenOrientation(); } @@ -641,13 +669,13 @@ function DisplayTiltChooser () { flatTiltChooser.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); } - tiltText2.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + tiltText2.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); } function CheckTiltAngle() { canShowStart = false; - + yield WaitForSeconds (.75); if ((Mathf.Abs(Input.acceleration.x) < .75) && (Mathf.Abs(Input.acceleration.y) < .75)) { ShowStart();} @@ -656,11 +684,11 @@ function CheckTiltAngle() { function ShowTiltWarning() { canShowStart = false; - + tiltWarning.hidden = false; tiltWarning.alphaFromTo( 0.25f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); yield WaitForSeconds (.75); - tiltWarning.alphaFromTo( 0.25f, 1.0f, 0.0f, Easing.Sinusoidal.easeOut); + tiltWarning.alphaFromTo( 0.25f, 1.0f, 0.0f, Easing.Sinusoidal.easeOut); yield WaitForSeconds (.5); canShowStart = true; } @@ -675,11 +703,11 @@ function Update () { ShowTiltWarning(); var duration = 1.0; - + bgCamera.backgroundColor = Color.Lerp (bgColor1, bgColor2, 1.0); - //var t : float = Mathf.Repeat (Time.time, duration) / duration; - + //var t : float = Mathf.Repeat (Time.time, duration) / duration; + //var t : float = Mathf.PingPong (Time.time, duration) / duration; //bgCamera.backgroundColor = Color.Lerp (bgColor1, bgColor2, t); @@ -694,13 +722,13 @@ function PauseGame() { if (level2Unlocked) {leftArrow.hidden = false;} loadNewLevelButton.hidden = false; bgSprite.hidden = false; - + savedTimeScale = Time.timeScale; // scriptName.GetComponent(FallingPlayer).FadeAudio (.09, FadeDir.Out); yield WaitForSeconds (.1); Time.timeScale = 0; AudioListener.pause = true; - FallingPlayer.isPausable = true; + FallingPlayer.isPausable = true; } } @@ -714,9 +742,9 @@ function UnPauseGame(resume : boolean) { rightArrow.hidden = true; leftArrow.hidden = true; loadNewLevelButton.hidden = true; - FallingPlayer.isPausable = resume; + FallingPlayer.isPausable = resume; } - + function IsGamePaused() { return Time.timeScale==0; } @@ -739,12 +767,12 @@ function LevelSelect() { loadLevelTwo.hidden = false; loadLevelThree.hidden = false; loadLevelFour.hidden = false; - + HideStartMenuElements(); ShowBackButton(); fadeInLoadNewLevels(); - + loadNewLevelButton.hidden = true; } @@ -756,9 +784,9 @@ function BackToPauseMenu() { aboutButtonStart.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); howToButton.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - + fadeInPauseMenu(); - + loadLevelOne.hidden = true; loadLevelTwo.hidden = true; loadLevelThree.hidden = true; @@ -773,6 +801,11 @@ function BackToPauseMenu() { text3.hidden = true; openSiteButtonText.hidden = true; + vrModeLaunchButton.hidden = true; + vrExplanatoryText.hidden = true; + vrModeButton.hidden = false; + vrModeLabel.hidden = false; + HideOptions(); // if (PlayerPrefs.HasKey("LatestLevel")) { @@ -800,17 +833,20 @@ function FadeAudio (timer : float) { function ResumeGame() { if (PlayerPrefs.HasKey("LatestLevel")) { StartLevelLoad(PlayerPrefs.GetString("LatestLevel")); - } - else { + } else if (FallingLaunch.isVRMode) { + StartLevelLoad(level1); + } else { + // Only show tilt options if if's the player's + // first session and they're not in VR mode: ShowTiltNeutralOptions(); } } function ToggleTiltNeutral () { if (TogglingTiltNeutral == false) { - + TogglingTiltNeutral = true; - + if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) { fallingLaunchComponent.ChangeTilt(2); flatTiltChooser.hidden = true; @@ -822,7 +858,7 @@ function ToggleTiltNeutral () { flatTiltChooser.hidden = false; angledTiltChooser.hidden = true; verticalTiltChooser.hidden = true; - } + } else { fallingLaunchComponent.ChangeTilt(1); flatTiltChooser.hidden = true; @@ -837,48 +873,48 @@ function ToggleTiltNeutral () { function FlatTiltNeutral () { if (TogglingTiltNeutral == false) { - + TogglingTiltNeutral = true; - + fallingLaunchComponent.ChangeTilt(0); flatTiltLabel.hidden = false; angledTiltLabel.hidden = true; verticalTiltLabel.hidden = true; TogglingTiltNeutral = false; - + fadeAndLoad(0); } } function AngledTiltNeutral () { if (TogglingTiltNeutral == false) { - + TogglingTiltNeutral = true; - + fallingLaunchComponent.ChangeTilt(1); angledTiltLabel.hidden = false; flatTiltLabel.hidden = true; verticalTiltLabel.hidden = true; TogglingTiltNeutral = false; - + fadeAndLoad(1); } } function VerticalTiltNeutral () { if (TogglingTiltNeutral == false) { - + TogglingTiltNeutral = true; - + fallingLaunchComponent.ChangeTilt(2); angledTiltLabel.hidden = true; flatTiltLabel.hidden = true; verticalTiltLabel.hidden = false; TogglingTiltNeutral = false; - + fadeAndLoad(2); } } @@ -901,29 +937,30 @@ function fadeAndLoad (flatNeutral : int) { } yield WaitForSeconds (1.0f); - + StartLevelLoad(level1); //below logic unnecessary for one-time fade and load check // if (PlayerPrefs.HasKey("LatestLevel")) { // StartLevelLoad(PlayerPrefs.GetString("LatestLevel")); // } - // else { + // else { // StartLevelLoad(level1); // } } function ShowTiltNeutralOptions () { + // yield FadeOutLevelButtons (fadeTime/2); + yield FadeOutAllStartMenuElements(fadeTime/2); + // yield WaitForSeconds(fadeTime/2) + HideStartMenuElements(); + flatTiltLabel.hidden = false; angledTiltLabel.hidden = false; // verticalTiltLabel.hidden = false; tiltText1.hidden = false; - rightArrow.hidden = true; - leftArrow.hidden = true; - aboutButtonStart.hidden = true; - howToButton.hidden = true; - optionsButton.hidden = true; + tiltText1.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); flatTiltLabel.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeOut); angledTiltLabel.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeOut); @@ -938,21 +975,39 @@ function StartLevelLoad(levelName: String) { if (aboutToLoad == false) { aboutToLoad = true; FadeAudio (fadeTime); - + yield FadeOutLevelButtons (fadeTime/2); yield WaitForSeconds(fadeTime); - + FallingLaunch.hasSetAccel = false; Application.LoadLevel(levelName); } } function FadeOutLevelButtons(timer : float) { + BackToPauseMenuButton.hidden = true; - loadLevelOne.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); - loadLevelTwo.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); - loadLevelThree.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); - loadLevelFour.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); + yield FadeOutAllStartMenuElements(timer); + // yield WaitForSeconds(timer); + + loadLevelOne.hidden = true; + loadLevelTwo.hidden = true; + loadLevelThree.hidden = true; + loadLevelFour.hidden = true; + + HideStartMenuElements(); + + loadingLabel.hidden = false; + loadingLabel.alphaFromTo(.5, 0.0f, 1.0f, Easing.Quartic.easeIn); + yield WaitForSeconds(.5); + +} + +function FadeOutAllStartMenuElements(timer: float) { + loadLevelOne.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); + loadLevelTwo.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); + loadLevelThree.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); + loadLevelFour.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); rightArrow.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); leftArrow.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); angledTiltChooser.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); @@ -961,22 +1016,13 @@ function FadeOutLevelButtons(timer : float) { aboutButtonStart.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); howToButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); optionsButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); - - yield WaitForSeconds(timer); - - loadLevelOne.hidden = true; - loadLevelTwo.hidden = true; - loadLevelThree.hidden = true; - loadLevelFour.hidden = true; - HideStartMenuElements(); - - loadingLabel.hidden = false; - loadingLabel.alphaFromTo(.5, 0.0f, 1.0f, Easing.Quartic.easeIn); - yield WaitForSeconds(.5); - + vrModeLaunchButton.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); + vrExplanatoryText.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); + yield; } + function OpenHowTo() { HideStartMenuElements(); @@ -984,14 +1030,14 @@ function OpenHowTo() { helpIcon1.hidden = false; helpIcon2.hidden = false; - helpIcon3.hidden = false; + helpIcon3.hidden = false; helpIcon1.alphaFromTo(.5f, 0.0f, 0.9f, Easing.Sinusoidal.easeOut); helpIcon2.alphaFromTo(.75f, 0.0f, 0.9f, Easing.Sinusoidal.easeInOut); helpIcon3.alphaFromTo(1.5f, 0.0f, 0.9f, Easing.Sinusoidal.easeInOut); } function OpenAbout() { - + HideStartMenuElements(); ShowBackButton(); @@ -1004,6 +1050,17 @@ function OpenAbout() { text3.alphaFromTo(1.5f, 0.0f, 0.6f, Easing.Sinusoidal.easeInOut); } +function OpenVRModeMenu() { + + HideStartMenuElements(); + ShowBackButton(); + + vrExplanatoryText.hidden = false; + vrModeLaunchButton.hidden = false; + vrExplanatoryText.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); + vrModeLaunchButton.alphaFromTo( 1.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeInOut); +} + function LaunchVRMode() { FallingLaunch.isVRMode = true; ResumeGame(); @@ -1029,8 +1086,8 @@ function HideOptions() { angledTiltChooser.hidden = true; flatTiltChooser.hidden = true; verticalTiltChooser.hidden = true; - - if (PlayerPrefs.HasKey("LatestLevel")) { + + if (PlayerPrefs.HasKey("LatestLevel")) { optionsButton.hidden = false; optionsButton.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeOut); } @@ -1043,10 +1100,10 @@ function fadeInOptions() { tiltText2.hidden = false; invertHorizAxisText.hidden = false; invertVertAxisText.hidden = false; - + invertHorizAxisText.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); invertVertAxisText.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - + if (FallingLaunch.invertVertAxisVal == -1) { invertVertAxisTextNo.hidden = true; invertVertAxisTextYes.hidden = false; @@ -1068,7 +1125,7 @@ function fadeInOptions() { invertHorizAxisTextYes.hidden = true; invertHorizAxisTextNo.alphaFromTo(1.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); } - + } function SaveAxesPrefs( invert : int) { @@ -1127,7 +1184,9 @@ function HideStartMenuElements() { aboutButtonStart.hidden = true; howToButton.hidden = true; optionsButton.hidden = true; - + + vrModeButton.hidden = true; + vrModeLabel.hidden = true; //angledTiltChooser.hidden = true; //flatTiltChooser.hidden = true; } @@ -1186,15 +1245,23 @@ function fadeOutLeftArrow() { leftArrow.alphaTo(.25f, 0.4f, Easing.Sinusoidal.easeOut); } +function fadeInVRLaunchButton() { + vrModeLaunchButton.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); +} + +function fadeOutVRLaunchButton() { + vrModeLaunchButton.alphaTo(.25f, 0.4f, Easing.Sinusoidal.easeOut); +} + function fadeInLoadNewLevels() { loadLevelOne.alphaFromTo(.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeOut); - if (level2Unlocked) {loadLevelTwo.alphaFromTo(.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeOut);} + if (level2Unlocked) {loadLevelTwo.alphaFromTo(.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeOut);} else {loadLevelTwo.alphaFromTo(.25f, 0.0f, 0.05f, Easing.Sinusoidal.easeOut);} if (level3Unlocked) {loadLevelThree.alphaFromTo(.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeOut);} else {loadLevelThree.alphaFromTo(.25f, 0.0f, 0.05f, Easing.Sinusoidal.easeOut);} - + if (level4Unlocked) {loadLevelFour.alphaFromTo(.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeOut);} else {loadLevelFour.alphaFromTo(.25f, 0.0f, 0.05f, Easing.Sinusoidal.easeOut);} } @@ -1208,49 +1275,49 @@ function fadeInPauseMenu() { function downLevel1() { if (aboutToLoad == false) { - loadLevelOne.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); + loadLevelOne.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); } } function downLevel2() { if (aboutToLoad == false) { - loadLevelTwo.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); + loadLevelTwo.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); } } function downLevel3() { if (aboutToLoad == false) { - loadLevelThree.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); + loadLevelThree.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); } } function downLevel4() { if (aboutToLoad == false) { - loadLevelFour.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); + loadLevelFour.alphaTo(.05f, 1.0f, Easing.Sinusoidal.easeOut); } } function upLevel1() { if (aboutToLoad == false) { - loadLevelOne.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); + loadLevelOne.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); } } function upLevel2() { if (aboutToLoad == false) { - loadLevelTwo.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); + loadLevelTwo.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); } } function upLevel3() { if (aboutToLoad == false) { - loadLevelThree.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); + loadLevelThree.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); } } function upLevel4() { if (aboutToLoad == false) { - loadLevelFour.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); + loadLevelFour.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); } } @@ -1266,7 +1333,7 @@ function upLevel4() { // FallingLaunch.flipMultiplier = 1; // Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; -// } +// } // //this is necessary to override Unity 4's auto-orientation code // Input.compensateSensors = false; @@ -1304,12 +1371,12 @@ function upLevel4() { // // if (Screen.orientation == ScreenOrientation.LandscapeRight) { // // Debug.Log("Device is FaceUp, and ScreenOrientation is LandscapeRight"); // // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; -// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; +// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; // // } // // else { // // Debug.Log("Device is FaceUp, and ScreenOrientation is NOT LandscapeRight"); // // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; -// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; +// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; // // } // // Screen.autorotateToLandscapeRight = false; @@ -1319,7 +1386,7 @@ function upLevel4() { // // } -// if (Vector3.Dot(Input.acceleration.normalized, Vector3(1,0,0)) > 0) +// if (Vector3.Dot(Input.acceleration.normalized, Vector3(1,0,0)) > 0) // //else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) // { // Screen.orientation = ScreenOrientation.LandscapeRight; @@ -1333,11 +1400,11 @@ function upLevel4() { // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; // } -// FallingLaunch.hasSetOrientation = true; +// FallingLaunch.hasSetOrientation = true; // } // function StopCompensatingSensors() { -// //this is necessary to override Unity 4's auto-orientation code +// //this is necessary to override Unity 4's auto-orientation code // Input.compensateSensors = false; // yield; -// } \ No newline at end of file +// } From b4be5b171ffea2b1aba55e606e4a8f6360320fe3 Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Tue, 31 Oct 2017 00:48:10 -0400 Subject: [PATCH 35/77] Conditionally disable UIToolkit in VR mode --- EndSequenceTrigger.js | 50 ++++---- FallingLaunch.js | 46 +++---- FallingPlayer.js | 152 ++++++++++++----------- GUITextureLaunch.js | 26 ++-- IntroEndTrigger.js | 4 +- IntroSequence.js | 5 +- IntroSequence1stPerson.js | 20 ++-- SpeedLines.js | 30 ++--- fallingUITest.js | 246 +++++++++++++++++++++----------------- lifeCountdown.js | 25 ++-- 10 files changed, 319 insertions(+), 285 deletions(-) diff --git a/EndSequenceTrigger.js b/EndSequenceTrigger.js index 1219303..0a6daaf 100644 --- a/EndSequenceTrigger.js +++ b/EndSequenceTrigger.js @@ -23,21 +23,21 @@ function Start () { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Player") && lifeCountdown.inOutro == false) { lifeCountdown.inOutro = true; - + MoveController.SpeedLinesMeshScript.LinesLerpOut(3); if (EndScriptComponent) { EndScriptComponent.PlayOutro(); } - - for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) + + for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) shard.GetComponent.().Play(); - + if (audioSource) {audioSource.Play();} - FallingPlayer.ScoreFlashTextureScript.FadeFlash (12.0, FadeDir.In); + FallingPlayer.ScoreFlashTextureScript.FadeFlash(12.0, FadeDir.In); //yield WaitForSeconds (1.0); - //FallingPlayer.ScoreFlashTextureScript.FadeFlash (0.5, FadeDir.Out); + //FallingPlayer.ScoreFlashTextureScript.FadeFlash(0.5, FadeDir.Out); } } @@ -55,28 +55,28 @@ function getDiamondCenter() { } function SwapDiamonds(timer : float){ - FallingPlayer.ScoreFlashTextureScript.FadeFlash (3.0, FadeDir.Out); + FallingPlayer.ScoreFlashTextureScript.FadeFlash(3.0, FadeDir.Out); FallingPlayer.UIscriptComponent.OutroDiamondFlash(2); //yield WaitForSeconds (.2); endDiamond.active = true; - + var start = shardColor.color; var end = Color.black; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; - + for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) shard.transform.Find("sky-rock-angled-segment").GetComponent.().material.color = Color.Lerp(start, end, i); - + yield; } - + yield WaitForSeconds (1); - - for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) + + for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) Destroy (shard); } @@ -87,13 +87,13 @@ function AddDiamondCore(timer : float){ var end = .9; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; diamondCore.GetComponent.().material.color.a = Mathf.Lerp(start, end, i); yield; } - + yield WaitForSeconds (timer); } @@ -104,13 +104,13 @@ function FadeDiamond(timer : float){ var end = Color.black; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; endDiamond.GetComponent.().material.color = Color.Lerp(start, end, i); yield; } - + yield WaitForSeconds (timer); } @@ -124,14 +124,14 @@ function AddDiamond3DCore(timer : float){ var end = diamond3DCore1.GetComponent.().material.color; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; diamond3DCore1.GetComponent.().material.color = Color.Lerp(start, end, i); diamond3DCore2.GetComponent.().material.color = Color.Lerp(start, end, i); yield; } - + yield WaitForSeconds (timer); -} \ No newline at end of file +} diff --git a/FallingLaunch.js b/FallingLaunch.js index 9a050fc..0c818a7 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -60,14 +60,14 @@ function Start () { if (!alreadyLaunched) { - + // TestFlightUnity.TestFlight.TakeOff( testFlightToken ); if (Debug.isDebugBuild) { Debug.Log("Your device orientation is " + Input.deviceOrientation + "!"); } - + initialInputDeviceOrientation = Input.deviceOrientation; - + // if (!hasSetOrientation) { // if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) { // flipMultiplier = flipMultiplier * -1; @@ -79,7 +79,7 @@ function Start () { // flipMultiplier = flipMultiplier * 1; // //Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); // neutralPosTilted = neutralPosTiltedRegular; - // } + // } // hasSetOrientation = true; // } @@ -90,16 +90,16 @@ function Start () { // Debug.Log("Device orientation after Input.compensateSensors = false is " + Input.deviceOrientation); // NB: still doesn't work, sensor 'correctness' depends on starting device orientation as read by Cardboard. - // HACK: Force landscape left orientation for Cardboard compatibility. + // HACK: Force landscape left orientation for Cardboard compatibility. // TODO: make conditional on isVRMode? // Screen.orientation = ScreenOrientation.LandscapeLeft; - + var iOSGen = iOS.Device.generation; - + // Debug.Log("this is an " + iOSGen + " device!"); // Reduce target framerate for very old iOS devices: - if (iOSGen == UnityEngine.iOS.DeviceGeneration.iPad1Gen || iOSGen == UnityEngine.iOS.DeviceGeneration.iPad2Gen || + if (iOSGen == UnityEngine.iOS.DeviceGeneration.iPad1Gen || iOSGen == UnityEngine.iOS.DeviceGeneration.iPad2Gen || iOSGen == UnityEngine.iOS.DeviceGeneration.iPhone4 || iOSGen == UnityEngine.iOS.DeviceGeneration.iPodTouch4Gen || iOSGen.ToString().Contains("iPhone3G")) { QualitySettings.DecreaseLevel(false); @@ -107,13 +107,13 @@ function Start () { } else { targetFPS = 60; - } + } var screenDPI : float = Screen.dpi; var screenWidthInInches: float = (Screen.width / screenDPI); var screenHeightInInches: float = (Screen.height / screenDPI); - var hasLargeScreen: boolean = screenDPI > 0 && (screenWidthInInches > 8 && screenHeightInInches > 5); + var hasLargeScreen: boolean = screenDPI > 0 && (screenWidthInInches > 8 && screenHeightInInches > 5); // Debug.Log("Screen DPI: " + screenDPI); // Debug.Log("Screen width in inches: " + screenWidthInInches); // Debug.Log("Screen height in inches: " + screenHeightInInches); @@ -125,30 +125,30 @@ function Start () { // Debug.Log("Based on reported screen size, not a tablet..."); isTablet = false; } - + if (!Input.gyro.enabled) { Debug.Log("Your device doesn't have a gyroscope..."); } - // if ((iOSGen && + // if ((iOSGen && // (iPads.iPad1Gen | iPads.iPad2Gen | iPads.iPad3Gen | iPads.iPad4Gen | iPads.iPadMini1Gen | iPads.iPadUnknown)) != 0) { - + flipMultiplier = isTablet ? 2 * flipMultiplier : 1.5 * flipMultiplier; DontDestroyOnLoad (this); alreadyLaunched = true; Application.targetFrameRate = targetFPS; - + Application.LoadLevel("Falling-scene-menu"); } else { Destroy(this.gameObject); } - + // myTimer = new GAUserTimer("Timer", "Session Length"); // myTimer.Start(); //Calibrate(); - //Calibrating in Start here was unwise, in case the user is swinging + //Calibrating in Start here was unwise, in case the user is swinging //the device around and the accelerometer readings haven't settled yet. } @@ -166,7 +166,7 @@ function OnLevelWasLoaded (level : int) { // var loadedLevel : GALevel = new GALevel(); // GoogleAnalytics.instance.Add(loadedLevel); // GoogleAnalytics.instance.Dispatch(); - + //Debug.Log("my loaded level is... " + Application.loadedLevelName); } @@ -183,7 +183,7 @@ function Calibrate () { if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) {restPosition = neutralPosTilted;} else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} else {restPosition = neutralPosFlat;} - + SetAxesInversion(); //acceleratorSnapshot = Input.acceleration; acceleratorSnapshot = Vector3(0.0,0.0,-1.0); @@ -194,7 +194,7 @@ function Calibrate () { function CalibrateInLevel () { tiltable = false; - + if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) {restPosition = neutralPosTilted;} else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} else {restPosition = neutralPosFlat;} @@ -210,7 +210,7 @@ function ChangeTilt (toFlat : int) { if (toFlat == 2) { PlayerPrefs.SetInt("TiltNeutral", 2); Debug.Log("tilt set to vertical."); - } + } else if (toFlat == 0) { PlayerPrefs.SetInt("TiltNeutral", 0); Debug.Log("tilt set to flat."); @@ -218,14 +218,14 @@ function ChangeTilt (toFlat : int) { else { PlayerPrefs.SetInt("TiltNeutral", 1); Debug.Log("tilt set to angled."); - } + } CalibrateInLevel(); } // function Update () { // ListCurrentAccelerometer(); // } -// +// // function ListCurrentAccelerometer() { // Debug.Log ("Your rotation is " + Input.acceleration); -// } \ No newline at end of file +// } diff --git a/FallingPlayer.js b/FallingPlayer.js index 0944c3e..7db2ce0 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -1,4 +1,4 @@ -#pragma strict +#pragma strict // 10/25/2017: `Color` uses a 0-1 float range, not 0-2, in Unity. // 2 = 255 for rgba in this color array @@ -21,6 +21,8 @@ var ScoreFlashTexture : GameObject; static var ScoreFlashTextureScript : GUITextureLaunch; ScoreFlashTextureScript = ScoreFlashTexture.GetComponent("GUITextureLaunch"); +var lifeCountdownScript : lifeCountdown; + public var force:float = 1.0; var dir : Vector3 = Vector3.zero; @@ -48,7 +50,7 @@ static var isAlive : int = 1; static var lifeStartTime : float = 0; static var levelStartTime : float = 0; - + static var isTiltable : boolean = true; static var isPausable : boolean = false; @@ -120,6 +122,7 @@ function Start() { myBackdrop = GameObject.Find("plane-close"); BackdropMist = GameObject.Find("Cylinder"); myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; + lifeCountdownScript = gameObject.GetComponent.(); if (FallingLaunch.isVRMode) { myVRViewer = GameObject.Find("GvrViewerMain"); @@ -127,10 +130,11 @@ function Start() { scoreUIVRMatl = scoreUIVRRenderer.material; scoreUIVRMatl.color.a = 0; - // Hack to have two separate death/fade-to-black sphere objects, + // Hack to have two separate death/fade-to-black sphere objects, // but neither shader does everything. The inverted transparent shader occludes // all physical objects, but the UIToolkit one is needed for covering light halos. - // Both materials have manual RenderQueue settings of 5000 (the max). + // The opaque and transparent materials have manual RenderQueue settings + // of 5000 (the official max) and 6000, respectively. if (deathFadeUIVR && opaqueDeathFadeUIVR) { deathFadeUIVRRenderer = deathFadeUIVR.GetComponent.(); deathFadeUIVRMatl = deathFadeUIVRRenderer.material; @@ -140,7 +144,7 @@ function Start() { if (deathFadeUIVRMatl.HasProperty("_Color")) { deathFadeUIVRMatl.color.a = 0; - } + } if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) { var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor"); currentColor.a = 0; @@ -160,7 +164,7 @@ function Start() { // startingFogColor = RenderSettings.fogColor * 2; startingFogEndDistance = RenderSettings.fogEndDistance; startingFogStartDistance = RenderSettings.fogStartDistance; - + startingCameraFarClipPlane = myMainCamera.farClipPlane; isAlive = 1; UIscriptComponent = UIscriptName.GetComponent(fallingUITest); @@ -174,7 +178,7 @@ function Start() { peakVol = audioScore.volume; // fadeInAudio (); FadeAudio (0.1, FadeDir.In); - isPausable = false; + isPausable = false; rb = GetComponent.(); rb.isKinematic = false; @@ -190,7 +194,7 @@ function Start() { } function LevelStartFade () { - if (PlayerPrefs.HasKey("LatestLevel") && + if (PlayerPrefs.HasKey("LatestLevel") && PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) { FallingLaunch.LoadedLatestLevel = true; } @@ -210,10 +214,10 @@ function introFade() { function introNow() { LatestCheckpointRespawn(); - yield WaitForSeconds (3); + yield WaitForSeconds (3); FallingLaunch.LoadedLatestLevel = false; whiteFader = Camera.main.GetComponent(FadeInOutAlt); - whiteFader.enabled = false; + if (whiteFader) {whiteFader.enabled = false;} } @@ -236,7 +240,7 @@ function DeathRespawn () { isPausable = false; rb.isKinematic = true; lifeStartTime = Time.time; - var respawnPosition = Respawn.currentRespawn.transform.position; + var respawnPosition = Respawn.currentRespawn.transform.position; if (FallingLaunch.isVRMode) { DeathFadeVR(1.0, FadeDir.Out); @@ -248,7 +252,7 @@ function DeathRespawn () { if (levelChangeBackdrop == true) { changeLevelBackdrop (); } - + FadeAudio (fadeTime, FadeDir.Out); // VR mode does its own score reset later, due to a longer fade interval/ @@ -267,7 +271,7 @@ function DeathRespawn () { isAlive = 1; RenderSettings.fogEndDistance = startingFogEndDistance; RenderSettings.fogStartDistance = startingFogStartDistance; - + // Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider. @@ -278,12 +282,12 @@ function DeathRespawn () { // thisOceanCamera.SendMessage("fadeIn"); rb.isKinematic = false; // isAlive = 1; - + MoveController.controlMultiplier = 1; - + if (FallingLaunch.isVRMode && deathPauseUIVR && deathFadeUIVR) { - rb.isKinematic = true; + rb.isKinematic = true; isAlive = 0; deathPauseUIVR.SetActive(true); @@ -291,17 +295,15 @@ function DeathRespawn () { DeathFadeVR(1.0, FadeDir.In); // yield UIscriptComponent.fadeIn(false); - + yield WaitForSeconds(4); - + yield DeathFadeVR(1.0, FadeDir.Out); - // yield UIscriptComponent.fadeOut(); - // // UIscriptComponent.UnPauseGame(true); rb.isKinematic = false; - + // TODO: Fade out material here instead of toggling the whole object outright? deathPauseUIVR.SetActive(false); - + // resetting score to max here for VR, to avoid the score // ticking away over the preceding ~4 WaitForSeconds. script.ResetScore(); @@ -320,7 +322,7 @@ function DeathRespawn () { lerpControlIn(3.0); yield UIscriptComponent.fadeIn(true); } -} +} function LatestCheckpointRespawn () { isPausable = false; @@ -342,13 +344,13 @@ function LatestCheckpointRespawn () { FadeAudio (fadeTime, FadeDir.In); rb.isKinematic = false; - + MoveController.controlMultiplier = 1; - + lerpControlIn(3); //yield UIscriptComponent.fadeIn(true); UIscriptComponent.UnhideGUI(); -} +} function ShowDeathHelp() { if (introComponent) { @@ -363,7 +365,7 @@ function changeLevelBackdrop () { changeBackdrop.endSphereRenderer.enabled = false; // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component - // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); + // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); RenderSettings.fogEndDistance = startingFogEndDistance; RenderSettings.fogStartDistance = startingFogStartDistance; @@ -373,7 +375,7 @@ function changeLevelBackdrop () { } iTween.ColorTo(BackdropMist,{"a": startingCloudsAlpha,"time": .5}); } - + function Update () { // playerTilt moves camera on device tilt. Enable if not in VR mode: if (!FallingLaunch.isVRMode) { @@ -393,7 +395,7 @@ function Update () { //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); //Debug.Log("your current acceleration is: " + FallingLaunch.accelerator); } - + function playerTilt() { if (isTiltable == true) { var dir : Vector3 = Vector3.zero; @@ -407,28 +409,28 @@ function playerTilt() { var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); // Dampen towards the target rotation myTransform.rotation = Quaternion.Lerp(myTransform.rotation, target, - Time.deltaTime * smooth); + Time.deltaTime * smooth); } -} +} function lerpControlIn(timer : float) { - + //Debug.Log("your flip multiplier is " + FallingLaunch.flipMultiplier); //Debug.Log("your control multiplier is " + MoveController.controlMultiplier); - + var start = 0.0; var end = MoveController.controlMultiplier; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; MoveController.controlMultiplier = Mathf.Lerp(start, end, i); - if (isAlive == 0) {MoveController.controlMultiplier = end; break;} + if (isAlive == 0) {MoveController.controlMultiplier = end; break;} yield; - - if (i >= 1.0 || isAlive == 0) {MoveController.controlMultiplier = end; break;} + + if (i >= 1.0 || isAlive == 0) {MoveController.controlMultiplier = end; break;} } yield WaitForSeconds (timer); } @@ -448,15 +450,15 @@ function lerpControlOut(timer : float) { var i = 0.0; var step = 1.0/timer1; - while (i <= 1.0) { + while (i <= 1.0) { i += step * Time.deltaTime; var controlT : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp MoveController.controlMultiplier = Mathf.Lerp(startControl, end, controlT); - + if (isAlive == 0) { - MoveController.controlMultiplier = startControl; + MoveController.controlMultiplier = startControl; simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); break; } @@ -465,26 +467,26 @@ function lerpControlOut(timer : float) { // the && is because the smootherstep math can overshoot 1.0 on its own: if (i >= 1.0 && isAlive == 0) { - MoveController.controlMultiplier = startControl; + MoveController.controlMultiplier = startControl; simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); break; - } + } } // In the final bit of time (timer2), lerp the speed cap down to zero: var i2 : float = 0.0; var step2 = 1.0/timer2; - while (i2 <= 1.0) { + while (i2 <= 1.0) { i2 += step2 * Time.deltaTime; - + // var maxVelocityT : float = i2*i2*i2 * (i2 * (6f*i2 - 15f) + 10f); // smootherstep lerp var maxVelocityT : float = Mathf.Sin(i2 * Mathf.PI * 0.5f); // ease-out lerp var newMaxVelocity : float = Mathf.Lerp(startMaxVelocity, endVelocity, maxVelocityT); - + simpleVelocityLimiterComponent.SetMaxVelocity(newMaxVelocity); - + if (isAlive == 0) { MoveController.controlMultiplier = startControl; simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); @@ -495,10 +497,10 @@ function lerpControlOut(timer : float) { // the && is because the smootherstep math can overshoot 1.0 on its own: if (i2 >= 1.0 && isAlive == 0) { - MoveController.controlMultiplier = startControl; + MoveController.controlMultiplier = startControl; simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity); break; - } + } } } @@ -527,7 +529,7 @@ function DeathFadeVR (timer : float, fadeType : FadeDir) { i += step * Time.deltaTime; // ease-out lerp, to match non-VR fade timing: var t : float = Mathf.Sin(i * Mathf.PI * 0.5f); - + if (deathFadeUIVRMatl.HasProperty("_Color")) { deathFadeUIVRMatl.color.a = Mathf.Lerp(start, end, t); } @@ -549,19 +551,25 @@ function OnCollisionEnter (collision : Collision) { if (isPausable == true || collision.gameObject.layer == 17 ) { isAlive = 0; isPausable = false; - lifeCountdown.LifeFlashTextureScript.FadeFlash (1, FadeDir.Out); - UIscriptComponent.HideGUI(); + + if (!FallingLaunch.isVRMode) { + lifeCountdown.LifeFlashTextureScript.FadeFlash(1, FadeDir.Out); + UIscriptComponent.HideGUI(); + } else { + lifeCountdownScript.FadeFlashVR(1.0, FadeDir.Out); + } + FallingLaunch.secondsAlive = (Time.time - lifeStartTime); - + if (audioDeath) {audioDeath.Play();} - + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( "Death:Collision:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive ); //Debug.Log("you died in the area " + FallingLaunch.thisLevelArea); //Debug.Log("You died in a fatal collision with " + collision.gameObject); - + yield DeathRespawn (); //isPausable = true; //UIscriptComponent.UnhideGUI(); @@ -572,23 +580,23 @@ function OnCollisionEnter (collision : Collision) { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Score")){ - // Debug.Log("You scored!"); + // Debug.Log("You scored!"); // Camera.main.SendMessage("flashOut"); if (FallingLaunch.isVRMode) { ScoreFlashVR(0.8, FadeDir.Out); } else { - ScoreFlashTextureScript.FadeFlash (0.8, FadeDir.Out); + ScoreFlashTextureScript.FadeFlash(0.8, FadeDir.Out); } script.IncrementScore(6); UIscriptComponent.flashProgressBar(1); - + if (audioScore) { //Debug.Log(Random.Range(0,2)); myVol = ((MoveController.Slowdown / MoveController.maxSlowdown) * peakVol); clipToPlay = Random.Range(0.3f, 0.9f); pitchRand = Random.Range(0.98f,1.03f); - + if (playAltScoreAudio) { audioToPlay = audioScoreAlt; playAltScoreAudio = false; @@ -597,7 +605,7 @@ function OnTriggerEnter (other : Collider) { audioToPlay = audioScore; playAltScoreAudio = true; } - + audioToPlay.pitch = pitchRand; //if (clipToPlay == 1) {audioToPlay = audioScoreAlt;} @@ -609,44 +617,44 @@ function OnTriggerEnter (other : Collider) { audioToPlay.volume = clipToPlay; audioToPlay.panStereo = (clipToPlay/2); } - + //audioToPlay.volume = Mathf.Clamp(myVol, (peakVol * .5), peakVol); audioToPlay.Play(); } - + //yield WaitForSeconds(.2); // try using PlayClipAtPoint here so score sound fades away in 3D space as you fall? - // Camera.main.SendMessage("flashUp"); + // Camera.main.SendMessage("flashUp"); } - + if (other.gameObject.CompareTag ("LevelEnd") && isExitingLevel == false) { isExitingLevel = true; isPausable = false; var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - levelStartTime); - + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, FallingLaunch.secondsInLevel ); - + // reset the level area identifier for analytics purposes: FallingLaunch.thisLevelArea = "0-start"; // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); - + // to keep you from dying after you strike the levelend trigger script.IncrementScore(25); - + audioLevelEnd.Play(); - // the lerpControlOut timer argument must be equal to, or just less than, + // the lerpControlOut timer argument must be equal to, or just less than, // the sum of levelComplete's first argument, // in order to create a convincing slowdown lerp and UI/camera fadeout: lerpControlOut(4.0); UIscriptComponent.LevelComplete(3.0, 1.5); - } + } } - -@script AddComponentMenu("Scripts/FallingPlayer") \ No newline at end of file + +@script AddComponentMenu("Scripts/FallingPlayer") diff --git a/GUITextureLaunch.js b/GUITextureLaunch.js index aa60b83..666f730 100644 --- a/GUITextureLaunch.js +++ b/GUITextureLaunch.js @@ -10,7 +10,7 @@ function Start () { GetComponent.().color.a = 0.0; } -function FadeFlash (timer : float, fadeType : FadeDir) { +function FadeFlash(timer : float, fadeType : FadeDir) { var start = fadeType == FadeDir.In? 0.0 : peakValue; var end = fadeType == FadeDir.In? peakValue : 0.0; @@ -30,20 +30,20 @@ function LinesFlash (timer : float, fadeType : FadeDir) { var end = fadeType == FadeDir.In? peakValue : 0.0; var i = 0.0; var step = 1.0/timer; - + // if (controllerITween2.speedingUp == 2) { // if ((controllerITween2.speedingUp == 2) && (controllerITween2.Slowdown < 1)) { - while (i <= 1.0) { + while (i <= 1.0) { i += step * Time.deltaTime; GetComponent.().color.a = Mathf.Lerp(start, end, i); yield; - + if (MoveController.Slowdown < 1) {break;} } yield WaitForSeconds (timer); - MoveController.speedingUp = 1; + MoveController.speedingUp = 1; // } - + } function LinesFlashOut (timer : float, fadeType : FadeDir) { @@ -52,8 +52,8 @@ function LinesFlashOut (timer : float, fadeType : FadeDir) { var end = fadeType == FadeDir.In? GetComponent.().color.a : 0.0; var i = 0.0; var step = 1.0/timer; - - if (MoveController.speedingUp == 0) { + + if (MoveController.speedingUp == 0) { while (i <= 1.0) { i += step * Time.deltaTime; GetComponent.().color.a = Mathf.Lerp(end, start, i); @@ -62,7 +62,7 @@ function LinesFlashOut (timer : float, fadeType : FadeDir) { if (MoveController.Slowdown > 1) {break;} } yield WaitForSeconds (timer/3); - MoveController.speedingUp = 1; + MoveController.speedingUp = 1; } } @@ -76,13 +76,13 @@ function FadeOut (timer : float) { var end = 0.0; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; GetComponent.().color.a = Mathf.Lerp(start, end, i); yield; } - + yield WaitForSeconds (timer); - + } diff --git a/IntroEndTrigger.js b/IntroEndTrigger.js index ecb5533..3db6b2c 100644 --- a/IntroEndTrigger.js +++ b/IntroEndTrigger.js @@ -15,8 +15,8 @@ function Start () { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Player") && activeIntro == false){ activeIntro = true; - FallingPlayer.ScoreFlashTextureScript.FadeFlash (3, FadeDir.Out); + FallingPlayer.ScoreFlashTextureScript.FadeFlash(3, FadeDir.Out); IntroScriptComponent.EndIntro(true); if (audioSource) {audioSource.Play();} } -} \ No newline at end of file +} diff --git a/IntroSequence.js b/IntroSequence.js index bbfa97b..2746785 100644 --- a/IntroSequence.js +++ b/IntroSequence.js @@ -5,8 +5,9 @@ var introCamera : GameObject; var mainCamera : GameObject; function Start () { - FallingPlayer.UIscriptComponent.HideGUI(); - + if (!FallingLaunch.isVRMode) { + FallingPlayer.UIscriptComponent.HideGUI(); + } } function EndIntro () { diff --git a/IntroSequence1stPerson.js b/IntroSequence1stPerson.js index f15e96d..794641c 100644 --- a/IntroSequence1stPerson.js +++ b/IntroSequence1stPerson.js @@ -15,8 +15,10 @@ function Start () { if (!FallingLaunch.NewGamePlus) { PlayerController.enabled = false; ScoreController.enabled = false; - FallingPlayer.UIscriptComponent.HideGUI(); - + if (!FallingLaunch.isVRMode) { + FallingPlayer.UIscriptComponent.HideGUI(); + } + for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { destructible = shard.GetComponent(ProjectileDestroy); var shardRenderer : Renderer = shard.GetComponent.(); @@ -34,18 +36,18 @@ function Start () { FallingPlayer.UIscriptComponent.UnhideGUI(); } - + } function EndIntro (playAudio : boolean) { PlayerController.enabled = true; ScoreController.enabled = true; LifeController.enabled = true; - + if (!FallingLaunch.NewGamePlus) { FallingPlayer.UIscriptComponent.UnhideGUI(); } - + for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { destructible = shard.GetComponent(ProjectileDestroy); shard.GetComponent.().isKinematic = false; @@ -56,13 +58,13 @@ function EndIntro (playAudio : boolean) { shard.GetComponent.().enabled = true; destructible.enabled = true; } - + var start = shardColor; var end = Color.black; var i = 0.0; var step = 1.0/5; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) shard.GetComponent.().material.color = Color.Lerp(start, end, i); @@ -72,4 +74,4 @@ function EndIntro (playAudio : boolean) { function DeathHelp() { DeathGUITrigger.ShowHelpAfterDeath(); -} \ No newline at end of file +} diff --git a/SpeedLines.js b/SpeedLines.js index 6b9ceb2..0d9f286 100644 --- a/SpeedLines.js +++ b/SpeedLines.js @@ -34,29 +34,29 @@ function LinesFlash (timer : float, fadeType : FadeDir) { var start = (fadeType == FadeDir.In) ? speedLinesMaterial.color.a : peakValue; var end = (fadeType == FadeDir.In) ? peakValue : 0.0; var audioStart = speedLinesAudio2.volume; - var audioEnd = 1.0; + var audioEnd = 1.0; var i = 0.0; var step = 1.0/timer; - + speedLinesRenderer.enabled = true; if (i == 0.0) { if (!speedLinesAudio1.isPlaying) {speedLinesAudio1.Play();} if (!speedLinesAudio2.isPlaying) {speedLinesAudio2.Play();} } - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; speedLinesMaterial.color.a = Mathf.Lerp(start, end, i); - speedLinesAudio2.volume = Mathf.SmoothStep(audioStart, audioEnd, i); + speedLinesAudio2.volume = Mathf.SmoothStep(audioStart, audioEnd, i); yield; - + if (MoveController.Slowdown < 1) {break;} } yield WaitForSeconds (timer); - MoveController.speedingUp = 1; + MoveController.speedingUp = 1; // } - + } function LinesFlashOut (timer : float, fadeType : FadeDir) { @@ -64,11 +64,11 @@ function LinesFlashOut (timer : float, fadeType : FadeDir) { var start = (fadeType == FadeDir.In) ? 0.0 : peakValue; var end = (fadeType == FadeDir.In) ? speedLinesMaterial.color.a : 0.0; var audioStart = speedLinesAudio2.volume; - var audioEnd = 0.0; + var audioEnd = 0.0; var i = 0.0; var step = 1.0/timer; - - if (MoveController.speedingUp == 0) { + + if (MoveController.speedingUp == 0) { while (i <= 1.0) { i += step * Time.deltaTime; speedLinesMaterial.color.a = Mathf.Lerp(end, start, i); @@ -76,7 +76,7 @@ function LinesFlashOut (timer : float, fadeType : FadeDir) { yield; if (MoveController.Slowdown > 1) {speedLinesRenderer.enabled = true; break;} - if (i >= 1.0) {speedLinesRenderer.enabled = false;} + if (i >= 1.0) {speedLinesRenderer.enabled = false;} } yield WaitForSeconds (timer/3); MoveController.speedingUp = 1; @@ -90,14 +90,14 @@ function LinesLerpOut (timer : float) { var start = speedLinesMaterial.color.a; var end = 0.0; var audioStart = speedLinesAudio2.volume; - var audioEnd = 0.0; + var audioEnd = 0.0; var i = 0.0; var step = 1.0/timer; while (i <= 1.0) { i += step * Time.deltaTime; speedLinesMaterial.color.a = Mathf.Lerp(start, end, i); - speedLinesAudio2.volume = Mathf.Lerp(audioStart, audioEnd, i); + speedLinesAudio2.volume = Mathf.Lerp(audioStart, audioEnd, i); yield; } } @@ -110,4 +110,4 @@ function LinesOff () { speedLinesAudio2.volume = 0; } else {return;} -} \ No newline at end of file +} diff --git a/fallingUITest.js b/fallingUITest.js index d92412e..85ccce5 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -8,7 +8,7 @@ var fallingLaunchComponent : FallingLaunch; var value : float = 0.5f; var bgSprite : UISprite; //static var tutorialSprite : UISprite; -static var tutorialSpriteExtraTimer : float = 0; +static var tutorialSpriteExtraTimer : float = 0; var fadeSprite : UISprite; var pauseButton : UIButton; var circleReticle: UIButton; @@ -88,19 +88,28 @@ function Awake () { function Start () { // yield WaitForSeconds(0.5f); -// Testing to see if disabling this hard coded screen.orientation will allow auto detection of landscape +// Testing to see if disabling this hard coded screen.orientation will allow auto detection of landscape // right or left mode on startup. // Screen.orientation = ScreenOrientation.LandscapeLeft; // if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) { // Screen.orientation = ScreenOrientation.LandscapeRight;} // else {Screen.orientation = ScreenOrientation.LandscapeLeft;} - + + // VR mode is incompatible with orthographic cameras, and thus doesn't use UI Toolkit. + if (!FallingLaunch.isVRMode) { + SetupLevelUI(); + } else { + return; + } +} + +function SetupLevelUI() { fallingPlayerComponent = player.GetComponent("FallingPlayer"); //moveControllerComponent = player.GetComponent("MoveController"); fallingLaunch = GameObject.Find("LaunchGameObject"); fallingLaunchComponent = fallingLaunch.GetComponent("FallingLaunch"); - + bgSprite = UIT.firstToolkit.addSprite( "menuBackground.png", 0, 0, 2 ); bgSprite.positionCenter(); bgSprite.scaleTo( 0.01f, new Vector3( (Screen.width * 6), (Screen.height * 6), 1 ), Easing.Linear.easeIn); @@ -116,7 +125,7 @@ function Start () { else if (FallingLaunch.levelAchieved == 4) { level2Unlocked = true; level3Unlocked = true; - } + } else if (FallingLaunch.levelAchieved == 3) { level2Unlocked = true; } @@ -136,7 +145,7 @@ function Start () { boldText = new UIText( "font-bold", "font-bold.png" ); thinText = new UIText( "font-thin", "font-thin.png" ); - + boldText.alignMode = UITextAlignMode.Center; boldText.verticalAlignMode = UITextVerticalAlignMode.Middle; boldText.wrapMode = UITextLineWrapMode.MinimumLength; @@ -145,12 +154,12 @@ function Start () { thinText.verticalAlignMode = UITextVerticalAlignMode.Middle; thinText.wrapMode = UITextLineWrapMode.None; - + // var tutorialHeight = 1.25 * spriteEdgeSize; // tutorialSprite = UIT.firstToolkit.addSprite( "tutorialBackground.png", 0, 0, 4 ); // tutorialSprite.hidden = true; // tutorialSprite.scaleTo( 0.1f, new Vector3( (Screen.width), 3, 1 ), Easing.Sinusoidal.easeOut); - + fadeSprite = UIT.firstToolkit.addSprite( "menuBackgroundBlack.png", 0, 0, -1 ); fadeSprite.positionCenter(); fadeSprite.scaleTo( 0.01f, new Vector3( (Screen.width * 6), (Screen.height * 6), 1 ), Easing.Linear.easeIn); @@ -176,13 +185,13 @@ function Start () { rightArrow.hidden = true; leftArrow.hidden = true; - + BackToPauseMenuButton = UIButton.create("back.png","back.png", 40, 40); BackToPauseMenuButton.positionFromBottomLeft ( .05f, (.05f * screenAspectRatio) ); //BackToPauseMenuButton.pixelsFromBottomLeft ( 14, 14 ); BackToPauseMenuButton.normalTouchOffsets = new UIEdgeOffsets( 30 ); - BackToPauseMenuButton.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); - BackToPauseMenuButton.onTouchUpInside += BackToPauseMenu; + BackToPauseMenuButton.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); + BackToPauseMenuButton.onTouchUpInside += BackToPauseMenu; BackToPauseMenuButton.hidden = true; BackToHomeMenuButton = UIButton.create("homeArrows.png","homeArrows.png", 40, 40); @@ -197,13 +206,13 @@ function Start () { nextLevelLabel = UIT.firstToolkit.addSprite( "level2.png", 0, 0, 0 ); } else if (level2 == SceneManagement.SceneManager.GetActiveScene().name) { - nextLevelLabel = UIT.firstToolkit.addSprite( "level3.png", 0, 0, 0 ); + nextLevelLabel = UIT.firstToolkit.addSprite( "level3.png", 0, 0, 0 ); } else if (level3 == SceneManagement.SceneManager.GetActiveScene().name) { - nextLevelLabel = UIT.firstToolkit.addSprite( "level4.png", 0, 0, 0 ); + nextLevelLabel = UIT.firstToolkit.addSprite( "level4.png", 0, 0, 0 ); } else if (level4 == SceneManagement.SceneManager.GetActiveScene().name) { - nextLevelLabel = UIT.firstToolkit.addSprite( "level1.png", 0, 0, 0 ); + nextLevelLabel = UIT.firstToolkit.addSprite( "level1.png", 0, 0, 0 ); } //nextLevelLabel.positionFromCenter(.0f); @@ -225,24 +234,24 @@ function Start () { } var middleIconAdjustRatio : float = UIT.isHD ? calculatedMiddleIconRatio : 0.3f; - + if (level1 == SceneManagement.SceneManager.GetActiveScene().name) { loadLevelOne = UIButton.create("level1.png","level1.png", 0, 0); loadLevelOne.alphaTo( 0.01f, 0.75f, Easing.Sinusoidal.easeOut); } - else { + else { loadLevelOne = UIButton.create("level1.png","level1.png", 0, 0); loadLevelOne.alphaTo( 0.01f, 0.4f, Easing.Sinusoidal.easeOut); } loadLevelOne.positionFromTopLeft(buttonScaleFactor,0.05f); loadLevelOne.onTouchUpInside += LoadLevel1ViaMenu; - + if (level2 == SceneManagement.SceneManager.GetActiveScene().name) { loadLevelTwo = UIButton.create("level2.png","level2.png", 0, 0); loadLevelTwo.alphaTo( 0.01f, 0.75f, Easing.Sinusoidal.easeOut); loadLevelTwo.onTouchUpInside += LoadLevel2ViaMenu; } - else { + else { loadLevelTwo = UIButton.create("level2.png","level2.png", 0, 0); if (level2Unlocked == false) { loadLevelTwo.alphaTo( 0.01f, 0.05f, Easing.Sinusoidal.easeOut); @@ -259,7 +268,7 @@ function Start () { loadLevelThree.alphaTo( 0.01f, 0.75f, Easing.Sinusoidal.easeOut); loadLevelThree.onTouchUpInside += LoadLevel3ViaMenu; } - else { + else { loadLevelThree = UIButton.create("level3.png","level3.png", 0, 0); if (level3Unlocked == false) { loadLevelThree.alphaTo( 0.01f, 0.05f, Easing.Sinusoidal.easeOut); @@ -270,13 +279,13 @@ function Start () { } } loadLevelThree.positionFromTopRight(buttonScaleFactor, middleIconAdjustRatio); - + if (level4 == SceneManagement.SceneManager.GetActiveScene().name) { loadLevelFour = UIButton.create("level4.png","level4.png", 0, 0); loadLevelFour.alphaTo( 0.01f, 0.75f, Easing.Sinusoidal.easeOut); loadLevelFour.onTouchUpInside += LoadLevel4ViaMenu; } - else { + else { loadLevelFour = UIButton.create("level4.png","level4.png", 0, 0); if (level4Unlocked == false) { loadLevelFour.alphaTo( 0.01f, 0.05f, Easing.Sinusoidal.easeOut); @@ -292,11 +301,11 @@ function Start () { loadLevelTwo.hidden = true; loadLevelThree.hidden = true; loadLevelFour.hidden = true; - + loadingLabel = UIButton.create("loading.png","loading.png", 20, 20); loadingLabel.positionCenter(); loadingLabel.hidden = true; - + loadNewLevelButton = UIButton.create("chooselevel.png","chooselevelDown.png", 40, 40); loadNewLevelButton.positionFromTopLeft(buttonScaleFactor,0.2f); loadNewLevelButton.normalTouchOffsets = new UIEdgeOffsets( 30 ); @@ -322,8 +331,8 @@ function Start () { tiltText2.verticalAlignMode = UITextVerticalAlignMode.Bottom; tiltText2.positionFromRight( -.16f, .52f ); tiltText2.hidden = true; - //public UITextInstance addTextInstance( string text, float xPos, float yPos, - //float scale, int depth, Color color, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode ) + //public UITextInstance addTextInstance( string text, float xPos, float yPos, + //float scale, int depth, Color color, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode ) invertHorizAxisText = thinText.addTextInstance( "HORIZONTAL AXIS", 0, 0 ); invertHorizAxisText.verticalAlignMode = UITextVerticalAlignMode.Bottom; invertHorizAxisText.positionFromRight( .00f, .52f ); @@ -374,7 +383,7 @@ function Start () { angledTiltLabel = UIButton.create("neutralAngle45.png","neutralAngle45.png", 0, 0 ); angledTiltLabel.normalTouchOffsets = new UIEdgeOffsets( 30 ); angledTiltLabel.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); - angledTiltLabel.positionFromLeft( -.16f, .52f ); + angledTiltLabel.positionFromLeft( -.16f, .52f ); angledTiltLabel.onTouchUpInside += ToggleTiltNeutral; angledTiltLabel.hidden = true; @@ -395,7 +404,7 @@ function Start () { circleReticle = UIButton.create("circle-reticle.png","circle-reticle.png", 0, 0); circleReticle.positionCenter(); - + lifeBarOutline = UIProgressBar.create( "lifeBarOutline.png", 0, 0 ); lifeBarOutline.pixelsFromTopLeft ( 8, 8 ); lifeBarOutline.value = 1f; @@ -409,11 +418,11 @@ function Start () { // animateThreatBar (lifeBarThreat); lifeBarThreat.hidden = true; lifeBarThreat.alphaFromTo( 0.01f, 0f, 0f, Easing.Sinusoidal.easeOut); - + lifeBar = UIProgressBar.create( "lifeBarWhite.png", 0, 0 ); lifeBar.pixelsFromTopLeft ( 10, 10 ); lifeBar.resizeTextureOnChange = true; - lifeBar.value = 0.67f; + lifeBar.value = 0.67f; animateProgressBar (lifeBar); // Loop (); @@ -451,7 +460,7 @@ function Start () { -1.0f ); } - + if (FallingLaunch.invertVertAxisVal == -1) { GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( "AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, @@ -462,10 +471,10 @@ function Start () { "AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, 1.0f ); - } - } +} + function animateProgressBar(lifeBar : UIProgressBar) { while (true) { @@ -486,44 +495,51 @@ function animateProgressBar(lifeBar : UIProgressBar) { // } function flashProgressBar(delay : float) { - lifeBar.alphaTo( 0.01f, 1.0f, Easing.Sinusoidal.easeOut); - yield WaitForSeconds(.25); - lifeBar.alphaTo( delay, 0.5f, Easing.Sinusoidal.easeInOut); + if (!FallingLaunch.isVRMode) { + lifeBar.alphaTo( 0.01f, 1.0f, Easing.Sinusoidal.easeOut); + yield WaitForSeconds(.25); + lifeBar.alphaTo( delay, 0.5f, Easing.Sinusoidal.easeInOut); + } } function showThreatBar(delay : float) { - lifeBarThreat.hidden = false; - lifeBarThreat.alphaTo( delay, 0.25f, Easing.Sinusoidal.easeInOut); + if (!FallingLaunch.isVRMode) { + lifeBarThreat.hidden = false; + lifeBarThreat.alphaTo( delay, 0.25f, Easing.Sinusoidal.easeInOut); + } } function hideThreatBar(delay : float) { - lifeBarThreat.alphaTo( delay, 0.0f, Easing.Sinusoidal.easeInOut); + if (!FallingLaunch.isVRMode) { + lifeBarThreat.alphaTo( delay, 0.0f, Easing.Sinusoidal.easeInOut); + } } function flashThreatBar(delay : float) { - lifeBarThreat.hidden = false; - lifeBarThreat.alphaFromTo( delay, 1.0f, 0.0f, Easing.Sinusoidal.easeInOut); - yield WaitForSeconds(delay); -// lifeBarThreat.hidden = true; + if (!FallingLaunch.isVRMode) { + lifeBarThreat.hidden = false; + lifeBarThreat.alphaFromTo( delay, 1.0f, 0.0f, Easing.Sinusoidal.easeInOut); + yield WaitForSeconds(delay); + } } function PauseGame() { if (FallingPlayer.isPausable) { FallingPlayer.isPausable = false; - + FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); - + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( "GUI:PauseGame:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel ); //Debug.Log("you paused at " + transform.parent.position); - + circleReticle.hidden = true; lifeBar.hidden = true; lifeBarOutline.hidden = true; lifeBarThreat.hidden = true; - + origPauseButtonArea = MoveController.pauseButtonArea; MoveController.pauseButtonArea = Rect(0, 0, Screen.width, Screen.height); @@ -532,7 +548,7 @@ function PauseGame() { yield WaitForSeconds (.1); Time.timeScale = 0; AudioListener.pause = true; - + rightArrow.hidden = false; //leftArrow.hidden = false; if (level2Unlocked) {loadNewLevelButton.hidden = false;} @@ -542,7 +558,7 @@ function PauseGame() { //DisplayTiltOnPause(); - //clear any unused stuff in pause menu. + //clear any unused stuff in pause menu. //audio and video should be stopped, so any hiccuping won't be as obvious. Resources.UnloadUnusedAssets(); @@ -562,7 +578,7 @@ function UnPauseGame(resume : boolean) { lifeBar.hidden = false; lifeBarOutline.hidden = false; lifeBarThreat.hidden = false; - + bgSprite.hidden = true; rightArrow.hidden = true; leftArrow.hidden = true; @@ -574,40 +590,41 @@ function UnPauseGame(resume : boolean) { flatTiltLabel.hidden = true; verticalTiltLabel.hidden = true; - FallingPlayer.isPausable = resume; + FallingPlayer.isPausable = resume; holdingPauseButton = false; MoveController.pauseButtonArea = origPauseButtonArea; } - + function IsGamePaused() { return Time.timeScale==0; } function PauseGameCheck() { + if (!FallingLaunch.isVRMode) { + holdingPauseButton = true; - holdingPauseButton = true; - - if (FallingPlayer.isPausable == true) { - if (Time.timeScale == 0) { - // if (AudioListener.pause == true) { - UnPauseGame(true); - } - else { - PauseGame(); + if (FallingPlayer.isPausable == true) { + if (Time.timeScale == 0) { + // if (AudioListener.pause == true) { + UnPauseGame(true); + } + else { + PauseGame(); + } } } } function RestartLevel() { - FallingPlayer.isPausable = false; + FallingPlayer.isPausable = false; // Camera.main.SendMessage("fadeOut"); //fadeOut(); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( "GUI:RestartLevel:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel - ); - + ); + Respawn.currentRespawn = initialRespawn; HideGUI(); fallingPlayerComponent.DeathRespawn (); @@ -624,20 +641,20 @@ function LevelComplete(timer1 : float, timer2 : float) { yield WaitForSeconds(timer1); - // fade in congrats menu / buttons here + // fade in congrats menu / buttons here savedTimeScale = Time.timeScale; //loadingLabel.hidden = false; - //loadingLabel.alphaFromTo( 0.75f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + //loadingLabel.alphaFromTo( 0.75f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); nextLevelLabel.hidden = false; - nextLevelLabel.alphaFromTo( timer2, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); + nextLevelLabel.alphaFromTo( timer2, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); fallingPlayerComponent.FadeAudio (.9 * timer2, FadeDir.Out); yield WaitForSeconds (timer2); - + // Time.timeScale = 0; player.GetComponent.().isKinematic = true; AudioListener.pause = true; - + // Only increment `HighestLevel` pref if it's higher than the current `levelAchieved` value // (fixes bug where beaten levels reset on beating level one of New Game Plus): if ((Application.loadedLevel + 1) > FallingLaunch.levelAchieved) { @@ -665,7 +682,7 @@ function BeginOutroUI() { // yield WaitForSeconds (.5); // savedTimeScale = Time.timeScale; // // loadingLabel.hidden = false; -// // loadingLabel.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); +// // loadingLabel.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); // yield WaitForSeconds (1); // AudioListener.pause = true; // FallingPlayer.isTiltable = true; @@ -677,7 +694,7 @@ function GameCompleteUI() { bgSprite.hidden = false; bgSprite.alphaFromTo( 2f, 0.0f, 0.8f, Easing.Sinusoidal.easeIn); // fallingPlayerComponent.FadeAudio (1.5, FadeDir.Out); - + // add anything else that requires main uitoolkit instance } @@ -695,7 +712,7 @@ function LoadNewLevelViaMenu() { loadLevelFour.hidden = true; BackToPauseMenuButton.hidden = true; loadingLabel.hidden = false; - + FallingLaunch.levelEndSlowdown = 0; Application.LoadLevel(levelToLoad); @@ -708,14 +725,14 @@ function LevelSelect() { loadLevelTwo.hidden = false; loadLevelThree.hidden = false; loadLevelFour.hidden = false; - + BackToHomeMenuButton.hidden = false; - + angledTiltLabel.hidden = true; flatTiltLabel.hidden = true; verticalTiltLabel.hidden = true; - loadNewLevelButton.hidden = true; + loadNewLevelButton.hidden = true; ShowBackButton(); } @@ -725,7 +742,7 @@ function HidePauseMenuElements() { pauseButton.hidden = true; optionsButton.hidden = true; loadNewLevelButton.hidden = true; - + } function ShowBackButton() { @@ -736,13 +753,13 @@ function BackToPauseMenu() { //leftArrow.hidden = false; rightArrow.hidden = false; pauseButton.hidden = false; - + loadLevelOne.hidden = true; loadLevelTwo.hidden = true; loadLevelThree.hidden = true; loadLevelFour.hidden = true; HideOptions(); - + ShowOptionsButton(); //BackToHomeMenuButton.hidden = true; @@ -765,16 +782,16 @@ function HideOptions() { tiltText2.hidden = true; invertHorizAxisText.hidden = true; invertVertAxisText.hidden = true; - + invertVertAxisTextYes.hidden = true; invertVertAxisTextNo.hidden = true; invertHorizAxisTextYes.hidden = true; invertHorizAxisTextNo.hidden = true; - + angledTiltLabel.hidden = true; flatTiltLabel.hidden = true; verticalTiltLabel.hidden = true; - + } function ShowOptionsButton () { @@ -790,7 +807,7 @@ function fadeInOptions() { tiltText2.hidden = false; invertHorizAxisText.hidden = false; invertVertAxisText.hidden = false; - + if (FallingLaunch.invertVertAxisVal == -1) { invertVertAxisTextNo.hidden = true; invertVertAxisTextYes.hidden = false; @@ -808,7 +825,7 @@ function fadeInOptions() { invertHorizAxisTextNo.hidden = false; invertHorizAxisTextYes.hidden = true; } - + } function DisplayTiltChooser () { @@ -892,7 +909,7 @@ function LoadLevel1ViaMenu() { BackToPauseMenuButton.hidden = true; BackToHomeMenuButton.hidden = true; loadingLabel.hidden = false; - + FallingLaunch.hasSetAccel = false; Application.LoadLevel(level1); Time.timeScale = savedTimeScale; @@ -905,8 +922,8 @@ function LoadLevel2ViaMenu() { loadLevelFour.hidden = true; BackToPauseMenuButton.hidden = true; BackToHomeMenuButton.hidden = true; - loadingLabel.hidden = false; - + loadingLabel.hidden = false; + FallingLaunch.hasSetAccel = false; Application.LoadLevel(level2); Time.timeScale = savedTimeScale; @@ -920,7 +937,7 @@ function LoadLevel3ViaMenu() { BackToPauseMenuButton.hidden = true; BackToHomeMenuButton.hidden = true; loadingLabel.hidden = false; - + FallingLaunch.hasSetAccel = false; Application.LoadLevel(level3); Time.timeScale = savedTimeScale; @@ -934,7 +951,7 @@ function LoadLevel4ViaMenu() { BackToPauseMenuButton.hidden = true; BackToHomeMenuButton.hidden = true; loadingLabel.hidden = false; - + FallingLaunch.hasSetAccel = false; Application.LoadLevel(level4); Time.timeScale = savedTimeScale; @@ -948,7 +965,7 @@ function LoadHomeViaMenu() { BackToPauseMenuButton.hidden = true; BackToHomeMenuButton.hidden = true; loadingLabel.hidden = false; - + HidePauseMenuElements(); HideOptions(); @@ -983,7 +1000,7 @@ function FadeOutGUI() { circleReticle.alphaTo( 0.5f, 0.0f, Easing.Quartic.easeIn); lifeBarThreat.hidden = true; yield WaitForSeconds (1.0); - + pauseButton.hidden = true; circleReticle.hidden = true; lifeBar.hidden = true; @@ -992,20 +1009,21 @@ function FadeOutGUI() { function UnhideGUI() { - pauseButton.hidden = false; - circleReticle.hidden = false; - lifeBar.hidden = false; - lifeBarOutline.hidden = false; - lifeBarThreat.hidden = true; - -// lifeBarThreat.alphaFrom( 1.0f, 0.0f, Easing.Quartic.easeIn); - pauseButton.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); - lifeBar.alphaFromTo( 1.0f, 0.0f, 0.5f, Easing.Quartic.easeIn); - lifeBarOutline.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); - circleReticle.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); - yield WaitForSeconds (1.0); + if (!FallingLaunch.isVRMode) { + pauseButton.hidden = false; + circleReticle.hidden = false; + lifeBar.hidden = false; + lifeBarOutline.hidden = false; + lifeBarThreat.hidden = true; + + // lifeBarThreat.alphaFrom( 1.0f, 0.0f, Easing.Quartic.easeIn); + pauseButton.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); + lifeBar.alphaFromTo( 1.0f, 0.0f, 0.5f, Easing.Quartic.easeIn); + lifeBarOutline.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); + circleReticle.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Quartic.easeIn); + yield WaitForSeconds (1.0); + } FallingPlayer.isPausable = true; -// lifeBarThreat.hidden = false; } function fadeIn( shouldUnhideGUI : boolean ) { @@ -1026,22 +1044,26 @@ function fadeOut() { function OnApplicationPause(pauseStatus: boolean) { - if (pauseStatus && Time.timeScale != 0 && FallingPlayer.isPausable == true) {setSavedTimeScale(); PauseGameNow();} + if (pauseStatus && FallingPlayer.isPausable && !FallingLaunch.isVRMode && + Time.timeScale != 0) { + setSavedTimeScale(); + PauseGameNow(); + } } function setSavedTimeScale() { savedTimeScale = Time.timeScale; } - -function PauseGameNow() { + +function PauseGameNow() { circleReticle.hidden = true; lifeBar.hidden = true; lifeBarOutline.hidden = true; lifeBarThreat.hidden = true; - + origPauseButtonArea = MoveController.pauseButtonArea; MoveController.pauseButtonArea = Rect(0, 0, Screen.width, Screen.height); - + // savedTimeScale = Time.timeScale; Time.timeScale = 0; AudioListener.volume = 0; @@ -1076,9 +1098,9 @@ function setHoldingPauseButtonFalse() { function ToggleTiltNeutral () { if (TogglingTiltNeutral == false) { - + TogglingTiltNeutral = true; - + if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) { fallingLaunchComponent.ChangeTilt(2); flatTiltLabel.hidden = true; @@ -1090,7 +1112,7 @@ function ToggleTiltNeutral () { flatTiltLabel.hidden = false; angledTiltLabel.hidden = true; verticalTiltLabel.hidden = true; - } + } else { fallingLaunchComponent.ChangeTilt(1); flatTiltLabel.hidden = true; @@ -1128,8 +1150,8 @@ function DisplayTiltOnPause () { } else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) { verticalTiltLabel.hidden = false; - } + } else { flatTiltLabel.hidden = false; } -} \ No newline at end of file +} diff --git a/lifeCountdown.js b/lifeCountdown.js index fb384a8..b3b8372 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -31,7 +31,7 @@ function Start () { Loop2 (); ScoreLerpLoop (); } - + function Loop () { while (true && inOutro == false) { yield TickingAway(.25); @@ -62,7 +62,8 @@ function FadeFlashVR (timer : float, fadeType : FadeDir) { while (i <= 1.0) { i += step * Time.deltaTime; - lifeFlashUIMatl.color.a = Mathf.Lerp(start, end, i); + var t : float = i*i * (3f - 2f*i); // smoothstep lerp + lifeFlashUIMatl.color.a = Mathf.Lerp(start, end, t); yield; } } @@ -78,7 +79,7 @@ function TickingAway (delay : float) { script.DecrementScore(delay); yield WaitForSeconds((delay/4)); } - + else if (MoveController.Slowdown < MoveController.maxSlowdown) { script.DecrementScore(delay); yield WaitForSeconds(delay); @@ -90,28 +91,28 @@ function TickingAway (delay : float) { if (FallingLaunch.isVRMode) { FadeFlashVR(1, FadeDir.Out); } else { - LifeFlashTextureScript.FadeFlash (1, FadeDir.Out); + LifeFlashTextureScript.FadeFlash(1, FadeDir.Out); } - + FallingLaunch.secondsAlive = (Time.time - FallingPlayer.lifeStartTime); //Debug.Log("You died!"); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "Death:Drained:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + "Death:Drained:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive ); yield GetComponent(FallingPlayer).DeathRespawn(); - + if (!FallingLaunch.isVRMode) { GetComponent(FallingPlayer).ShowDeathHelp(); } - // New GameAnalytics "Design" event syntax: + // New GameAnalytics "Design" event syntax: // GameAnalytics.NewDesignEvent (string eventName, float eventValue); - // Original GameAnalytics syntax: GA.API.Design.NewEvent(String eventName, float eventValue, Vector3 trackPosition); + // Original GameAnalytics syntax: GA.API.Design.NewEvent(String eventName, float eventValue, Vector3 trackPosition); } } @@ -122,20 +123,20 @@ function LifeFlashCheck (delay : float, score : int) { if (!FallingPlayer.isAlive) { return; } - + if (script.currentScore < score && inOutro == false) { //Camera.main.SendMessage("lifeFlashOut"); if (FallingLaunch.isVRMode) { FadeFlashVR(delay, FadeDir.In); } else { - LifeFlashTextureScript.FadeFlash (delay, FadeDir.In); + LifeFlashTextureScript.FadeFlash(delay, FadeDir.In); } yield WaitForSeconds(delay); // Camera.main.SendMessage("lifeFlashUp"); if (FallingLaunch.isVRMode) { FadeFlashVR(delay, FadeDir.Out); } else { - LifeFlashTextureScript.FadeFlash (delay, FadeDir.Out); + LifeFlashTextureScript.FadeFlash(delay, FadeDir.Out); } yield WaitForSeconds((delay*3)); // stagger the flash timing (compare w/ `delay` above) } From 6cf6ae215108f5b14d529204442ab8dd47dd8471 Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Tue, 31 Oct 2017 23:51:09 -0700 Subject: [PATCH 36/77] Improve VR mode respawn audio fading; general DeathRespawn refactor --- FallingPlayer.js | 67 +++++++++++++------------- MoveController.js | 117 ++++++++++++++++++++++++---------------------- 2 files changed, 97 insertions(+), 87 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 7db2ce0..6a38c66 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -54,6 +54,7 @@ static var levelStartTime : float = 0; static var isTiltable : boolean = true; static var isPausable : boolean = false; +private var isExitableFromVR : boolean = true; var isExitingLevel : boolean = false; var UIscriptName : GameObject; @@ -177,7 +178,7 @@ function Start() { myVol = audioScore.volume; peakVol = audioScore.volume; // fadeInAudio (); - FadeAudio (0.1, FadeDir.In); + FadeAudio(0.1, FadeDir.In); isPausable = false; rb = GetComponent.(); @@ -221,7 +222,7 @@ function introNow() { } -function FadeAudio (timer : float, fadeType : FadeDir) { +function FadeAudio(timer : float, fadeType : FadeDir) { var start = fadeType == FadeDir.In? 0.0 : 1.0; var end = fadeType == FadeDir.In? 1.0 : 0.0; @@ -230,6 +231,7 @@ function FadeAudio (timer : float, fadeType : FadeDir) { while (i <= 1.0) { i += step * Time.deltaTime; + // var t : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp AudioListener.volume = Mathf.Lerp(start, end, i); yield; } @@ -243,28 +245,26 @@ function DeathRespawn () { var respawnPosition = Respawn.currentRespawn.transform.position; if (FallingLaunch.isVRMode) { - DeathFadeVR(1.0, FadeDir.Out); + reticleVRUIScript.FadeReticleOut(0.5); + FadeAudio(1.5, FadeDir.Out); + yield DeathFadeVR(1.0, FadeDir.Out); } else { - UIscriptComponent.fadeOut(); + FadeAudio(fadeTime, FadeDir.Out); + yield UIscriptComponent.fadeOut(); } -// Camera.main.SendMessage("fadeOut"); - - if (levelChangeBackdrop == true) { - changeLevelBackdrop (); - } - - FadeAudio (fadeTime, FadeDir.Out); - // VR mode does its own score reset later, due to a longer fade interval/ - // interstitial 'back to menu' screen. - if (!FallingLaunch.isVRMode) { - script.ResetScore(); - } + if (levelChangeBackdrop == true) { + changeLevelBackdrop (); + } - yield WaitForSeconds(1); + // VR mode does its own score reset later, due to a longer fade interval/ + // interstitial 'back to menu' screen. + if (!FallingLaunch.isVRMode) { + script.ResetScore(); + } -// if you want to clear destroyed projectiles... - if (clearDestroyedObjects == true) { + // If you want to clear destroyed projectiles (set per-level)... + if (clearDestroyedObjects) { Resources.UnloadUnusedAssets(); } @@ -276,12 +276,8 @@ function DeathRespawn () { GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider. myTransform.position = respawnPosition; // + Vector3.up; -// Camera.main.SendMessage("fadeIn"); - FadeAudio (fadeTime, FadeDir.In); -// thisOceanCamera.SendMessage("fadeIn"); rb.isKinematic = false; -// isAlive = 1; MoveController.controlMultiplier = 1; @@ -291,14 +287,18 @@ function DeathRespawn () { isAlive = 0; deathPauseUIVR.SetActive(true); - reticleVRUIScript.FadeReticleOut(0.5); DeathFadeVR(1.0, FadeDir.In); // yield UIscriptComponent.fadeIn(false); + // Managing isExitableFromVR gives finer control over the exit UI, + // preventing the player from tapping mid-respawn fadeout. + isExitableFromVR = true; yield WaitForSeconds(4); + isExitableFromVR = false; + + yield DeathFadeVR(0.5, FadeDir.Out); - yield DeathFadeVR(1.0, FadeDir.Out); rb.isKinematic = false; // TODO: Fade out material here instead of toggling the whole object outright? @@ -308,17 +308,19 @@ function DeathRespawn () { // ticking away over the preceding ~4 WaitForSeconds. script.ResetScore(); - lerpControlIn(3.0); + // In VR mode, we ignore fadeTime in favor of a longer fade-in + // matched to the longer waiting interval below: + FadeAudio(2.0, FadeDir.In); - yield DeathFadeVR(1.0, FadeDir.In); - // yield UIscriptComponent.fadeIn(false); - // yield WaitForSeconds(1); + DeathFadeVR(1.0, FadeDir.In); + lerpControlIn(3.0); reticleVRUIScript.FadeReticleIn(1.5); isPausable = true; isAlive = 1; } else { + FadeAudio(fadeTime, FadeDir.In); lerpControlIn(3.0); yield UIscriptComponent.fadeIn(true); } @@ -342,7 +344,7 @@ function LatestCheckpointRespawn () { GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); myTransform.position = respawnPosition; // + Vector3.up; - FadeAudio (fadeTime, FadeDir.In); + FadeAudio(fadeTime, FadeDir.In); rb.isKinematic = false; MoveController.controlMultiplier = 1; @@ -383,9 +385,10 @@ function Update () { } // disable VR mode and return to menu on screen touch while dead: - if (FallingLaunch.isVRMode && isAlive == 0 && deathPauseUIVR.activeInHierarchy) { + if (FallingLaunch.isVRMode && isAlive == 0 && deathPauseUIVR.activeInHierarchy && isExitableFromVR) { for (var i = 0; i < Input.touchCount; ++i) { if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { + isPausable = false; FallingLaunch.isVRMode = false; Application.LoadLevel("Falling-scene-menu"); } @@ -581,7 +584,7 @@ function OnCollisionEnter (collision : Collision) { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Score")){ // Debug.Log("You scored!"); - // Camera.main.SendMessage("flashOut"); + if (FallingLaunch.isVRMode) { ScoreFlashVR(0.8, FadeDir.Out); } else { diff --git a/MoveController.js b/MoveController.js index 11b1740..7c12e81 100644 --- a/MoveController.js +++ b/MoveController.js @@ -42,7 +42,7 @@ var audioSource : AudioSource; var changingPitch : boolean = false; -// this is on for all levels but lvl1/tutorial, which has music baked +// this is on for all levels but lvl1/tutorial, which has music baked // into the background wind sound, and thus shouldn't get pitch-shifted: var shouldChangePitch : boolean = true; @@ -59,13 +59,13 @@ function Awake() { function Start() { - // HACK: Force landscape left orientation in VR for Cardboard compatibility. + // HACK: Force landscape left orientation in VR for Cardboard compatibility. // Or is this best off just being removed? // NB: If your phone is tilted a little beyond flat (away from you) on level load, - // then all other game objects will be behind you when you look up: 180deg wrong - // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse - // quaternion in some cases based on Head gaze direction/ gameObj position, - // or in the menu UI, ensure the phone orientation is not flat before + // then all other game objects will be behind you when you look up: 180deg wrong + // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse + // quaternion in some cases based on Head gaze direction/ gameObj position, + // or in the menu UI, ensure the phone orientation is not flat before // letting the user load the scene... if (FallingLaunch.isVRMode) { // TODO FIXME FOR VR MODE: see above @@ -75,7 +75,7 @@ function Start() { // Screen.sleepTimeout = 0.0f; // deprecated, now should use NeverSleep Screen.sleepTimeout = SleepTimeout.NeverSleep; - startTime = Time.time; + startTime = Time.time; Slowdown = FallingLaunch.levelEndSlowdown; if (mainCameraObj) { @@ -85,9 +85,9 @@ function Start() { mainCameraObj = GameObject.FindWithTag("MainCamera"); mainCamera = Camera.main; } - + audioSource = mainCamera.GetComponent.(); - + //Calibrate(); // resetting controlMultiplier in case it was zeroed from the previous level @@ -118,7 +118,7 @@ function FixedUpdate () { dir = Vector3.zero; } - // Address any speedups due to screen presses in FixedUpdate, not here! + // Address any speedups due to screen presses in FixedUpdate, not here! // FallingSpeed(); } @@ -142,13 +142,13 @@ function MovePlayerVR () { var speedRatio : float = Slowdown / maxSlowdown; - // Cap the lateral speed (it should be translation, not a force, + // Cap the lateral speed (it should be translation, not a force, // so you don't keep moving after you lift the trigger). - // Distinguish between two categories of movement: + // Distinguish between two categories of movement: // while in boost mode and just afterwards (speedRatio > .25; value range is 1.25-2.4), - // vs. regular (speedRatio < .25) movement. + // vs. regular (speedRatio < .25) movement. // The latter is more constrained (possible value range 1-1.5). - lateralSpeedBoost = speedRatio > .25 ? + lateralSpeedBoost = speedRatio > .25 ? Mathf.Max(1.25, speedRatio * speed) : 1.0 + (speedRatio * maxLateralSpeed); // Debug.Log('lateralSpeedBoost: ' + lateralSpeedBoost); @@ -168,7 +168,7 @@ function MovePlayer(horizAxisInversionVal: int, vertAxisInversionVal: int) { // Debug.Log("MoveController FallingLaunch.calibrationRotation: " + FallingLaunch.calibrationRotation); // Debug.Log("Input.acceleration: " + Input.acceleration); // Debug.Log( "MoveController FallingLaunch.flipMultiplier: " + FallingLaunch.flipMultiplier ); - + // Debug.Log("MoveController FallingLaunch.accelerator: " + FallingLaunch.accelerator); dir.x = 4 * FallingPlayer.isAlive * controlMultiplier * FallingLaunch.flipMultiplier * -((FallingLaunch.accelerator.y) * Mathf.Abs(FallingLaunch.accelerator.y)); @@ -208,12 +208,12 @@ function Update () { function FallingSpeed () { fingerCount = 0; - + if (FallingPlayer.isAlive == 1 && FallingPlayer.isPausable == true) { //for (touch in Input.touches) { // if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) { for (var i = 0; i < Input.touchCount; ++i) { - if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { + if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { fingerCount++; if (pauseButtonArea.Contains(Input.GetTouch(i).position)) { @@ -226,11 +226,11 @@ function FallingSpeed () { // } // else { // Debug.Log("Not in pause area."); - // } + // } } } - - + + if (fingerCount > 0) { if (Slowdown < 1) { Slowdown = maxSlowdown; @@ -244,7 +244,7 @@ function FallingSpeed () { } else if (fingerCount < 1) { // rounding Slowdown, since as lerp approaches zero, floating-point errors creep in if (Mathf.Round(Slowdown) > 0) { - speedingUp = 0; speedsUp(); lerpSlowdown(.5); + speedingUp = 0; speedsUp(); lerpSlowdown(.5); } else { audioSource.volume = maxDuckedVolume; } @@ -255,20 +255,22 @@ function FallingSpeed () { Slowdown = 0; speedingUp = 1; SpeedLinesMeshScript.LinesOff(); - if (shouldChangePitch == true && changingPitch == false) {lerpPitchDown(.5, 1, 1);} + if (shouldChangePitch && !changingPitch) {lerpPitchDown(.5, 1, 1);} dir = Vector3.zero; - FallingPlayer.UIscriptComponent.hideThreatBar(0.1); + if (!FallingLaunch.isVRMode && FallingPlayer.isPausable) { + FallingPlayer.UIscriptComponent.hideThreatBar(0.1); + } } // Debug.Log("Slowdown = " + Slowdown + ", speedingUp = " + speedingUp ); // Debug.Log("You have " + fingerCount + " fingers touching the screen." ); - // In non-VR mode, relativeForce assumes the Player GameObject transform is tilted - // (by the device accelerometer) in space; it relies on device tilt + // In non-VR mode, relativeForce assumes the Player GameObject transform is tilted + // (by the device accelerometer) in space; it relies on device tilt // to provide some worldspace lateral speedup to the local (relative) down vector. // In VR, the head's gaze direction supplies our y vector, which is attenuated - // based on the gaze x/z (clampedModifierVR). + // based on the gaze x/z (clampedModifierVR). // That vector is multiplied by Slowdown to get a final downwards force. // Any x/z movement during a speed boost is handled in MovePlayerVR, since applying @@ -278,16 +280,16 @@ function FallingSpeed () { // Debug.Log('extraForceRaw: ' + extraForceRaw); // Debug.Log('myHead.Gaze.direction: ' + myHead.Gaze.direction); - clampedModifierVR = + clampedModifierVR = Mathf.Max(Mathf.Abs(myHead.Gaze.direction.x), Mathf.Abs(myHead.Gaze.direction.z)); extraForce = Vector3.ClampMagnitude(extraForceRaw, (1.0 - clampedModifierVR)); // Debug.Log('clampedModifierVR: ' + clampedModifierVR); - // If you wanted to directly set the downward vector, + // If you wanted to directly set the downward vector, // you could use set extraForce.y to be myHead.Gaze.direction.y below... // but the attenuated version is easier on the neck to control! - // Mutate into a downwards vector that insists on negative y values + // Mutate into a downwards vector that insists on negative y values // (so you can't fly upwards). extraForce = Vector3(0, Mathf.Min(extraForce.y, 0.0) * Slowdown, 0); } @@ -303,18 +305,23 @@ function speedsUp () { if (speedingUp == 2) { speedingUp = 1; SpeedLinesMeshScript.LinesFlash (0.25, FadeDir.In); - FallingPlayer.UIscriptComponent.showThreatBar(1); - if (audioSource && shouldChangePitch == true) { - // a bit of randomness to vary the end wind-noise pitch; + if (!FallingLaunch.isVRMode) { + FallingPlayer.UIscriptComponent.showThreatBar(1); + } + if (audioSource && shouldChangePitch) { + // a bit of randomness to vary the end wind-noise pitch; // generally, we want a value near 2: lerpPitchUp(.5, Random.Range(1.85, 2.25), .3); } - } - else { + } else { SpeedLinesMeshScript.LinesFlashOut (0.5, FadeDir.In); - FallingPlayer.UIscriptComponent.hideThreatBar(.5); - if (audioSource && shouldChangePitch == true && changingPitch == false) {lerpPitchDown(1, 1, 1);} - } + if (!FallingLaunch.isVRMode) { + FallingPlayer.UIscriptComponent.hideThreatBar(.5); + } + if (audioSource && shouldChangePitch && !changingPitch) { + lerpPitchDown(1, 1, 1); + } + } } function getMaxDuckedVolume() { @@ -330,62 +337,62 @@ function lerpSlowdown (timer : float) { var end = 0.0; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; Slowdown = Mathf.Lerp(start, end, i); yield; - + if (Slowdown > maxSlowdownThreshold) {break;} } yield WaitForSeconds (timer); - + } function lerpPitchUp (timer : float, endPitch : float, endVolume : float) { - + var startVol = audioSource.volume; var endVol = endVolume; - + var start = audioSource.pitch; var end = endPitch; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; audioSource.pitch = Mathf.Lerp(start, end, i); audioSource.volume = Mathf.SmoothStep(startVol, endVol * maxDuckedVolume, i); yield; - + if (Slowdown < 1) {break;} } yield WaitForSeconds (timer); } function lerpPitchDown (timer : float, endPitch : float, endVolume : float) { - + changingPitch = true; var startVol = audioSource.volume; var endVol = endVolume; - + var start = audioSource.pitch; var end = endPitch; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; audioSource.pitch = Mathf.Lerp(start, end, i); audioSource.volume = Mathf.SmoothStep(startVol, endVol * maxDuckedVolume, i); yield; - if (Slowdown > maxSlowdownThreshold) {changingPitch = false; break;} + if (Slowdown > maxSlowdownThreshold) {changingPitch = false; break;} } - - yield WaitForSeconds (timer); + + yield WaitForSeconds (timer); changingPitch = false; } @@ -395,9 +402,9 @@ function lerpControl(timer : float) { var end = controlMultiplier; var i = 0.0; var step = 1.0/timer; - - while (i <= 1.0) { + + while (i <= 1.0) { i += step * Time.deltaTime; controlMultiplier = Mathf.Lerp(start, end, i); yield; From a84ac36e36d9b129bc0fed474eb9456484f62102 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 1 Nov 2017 21:15:02 -0700 Subject: [PATCH 37/77] Use visibleScore for health-drain death condition --- FallingPlayer.js | 6 +++--- lifeCountdown.js | 39 +++++++++++++++------------------------ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 6a38c66..d9b643d 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -314,11 +314,11 @@ function DeathRespawn () { DeathFadeVR(1.0, FadeDir.In); lerpControlIn(3.0); - - reticleVRUIScript.FadeReticleIn(1.5); - isPausable = true; isAlive = 1; + yield WaitForSeconds(1); + reticleVRUIScript.FadeReticleIn(1.5); + } else { FadeAudio(fadeTime, FadeDir.In); lerpControlIn(3.0); diff --git a/lifeCountdown.js b/lifeCountdown.js index b3b8372..d26e496 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -74,13 +74,16 @@ function TickingAway (delay : float) { return; } - if (script.currentScore > 0) { + // The visibleScore check is to ensure that the onscreen health UI + // is actually empty before the player dies; if we used currentScore directly, + // the UI health bar's lerp would lag behind the actual value, so the player would + // appear to die too soon in some cases. + if (ScoreController.currentScore > 0 || ScoreController.visibleScore > 0) { + if (MoveController.Slowdown > maxSlowdownThreshold) { script.DecrementScore(delay); - yield WaitForSeconds((delay/4)); - } - - else if (MoveController.Slowdown < MoveController.maxSlowdown) { + yield WaitForSeconds((delay/4)); // 4x health penalty during player speedup + } else if (MoveController.Slowdown < MoveController.maxSlowdown) { script.DecrementScore(delay); yield WaitForSeconds(delay); } @@ -124,30 +127,18 @@ function LifeFlashCheck (delay : float, score : int) { return; } - if (script.currentScore < score && inOutro == false) { - //Camera.main.SendMessage("lifeFlashOut"); + if (ScoreController.currentScore < score && inOutro == false) { + if (FallingLaunch.isVRMode) { FadeFlashVR(delay, FadeDir.In); - } else { - LifeFlashTextureScript.FadeFlash(delay, FadeDir.In); - } - yield WaitForSeconds(delay); -// Camera.main.SendMessage("lifeFlashUp"); - if (FallingLaunch.isVRMode) { + yield WaitForSeconds(delay); FadeFlashVR(delay, FadeDir.Out); } else { + LifeFlashTextureScript.FadeFlash(delay, FadeDir.In); + yield WaitForSeconds(delay); LifeFlashTextureScript.FadeFlash(delay, FadeDir.Out); } - yield WaitForSeconds((delay*3)); // stagger the flash timing (compare w/ `delay` above) - } -} -// not being used currently, due to more versatile LifeFlashCheck in a separate coroutine. -function LifeFlash (delay : float, score : int) { - - if (script.currentScore < score) { - Camera.main.SendMessage("lifeFlashOut"); - yield WaitForSeconds(delay); - Camera.main.SendMessage("lifeFlashUp"); + yield WaitForSeconds((delay*3)); // stagger the flash timing (compare w/ `delay` above) } -} +} \ No newline at end of file From 72fc312d1e9deac3e16076d6a55c9f3e374a858f Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 3 Nov 2017 00:46:31 -0700 Subject: [PATCH 38/77] Basic setup for VR levelComplete fade-to-white --- FallingPlayer.js | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index d9b643d..6bb3893 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -70,6 +70,10 @@ private var opaqueDeathFadeUIVRMatl : Material; var deathPauseUIVR : GameObject; +var whiteFadeUIVR : GameObject; +private var whiteFadeUIVRRenderer : Renderer; +private var whiteFadeUIVRMatl : Material; + var scoreUIVR : GameObject; private var scoreUIVRRenderer : Renderer; private var scoreUIVRMatl : Material; @@ -131,6 +135,9 @@ function Start() { scoreUIVRMatl = scoreUIVRRenderer.material; scoreUIVRMatl.color.a = 0; + whiteFadeUIVRRenderer = whiteFadeUIVR.GetComponent.(); + whiteFadeUIVRMatl = whiteFadeUIVRRenderer.material; + whiteFadeUIVRMatl.color.a = 0; // Hack to have two separate death/fade-to-black sphere objects, // but neither shader does everything. The inverted transparent shader occludes // all physical objects, but the UIToolkit one is needed for covering light halos. @@ -390,6 +397,8 @@ function Update () { if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { isPausable = false; FallingLaunch.isVRMode = false; + + UIscriptComponent.SaveCheckpointVR(); Application.LoadLevel("Falling-scene-menu"); } } @@ -546,6 +555,20 @@ function DeathFadeVR (timer : float, fadeType : FadeDir) { } } +function WhiteFadeVR (timer : float, fadeType : FadeDir) { + + var start = fadeType == FadeDir.In ? 1.0 : 0.0; + var end = fadeType == FadeDir.In ? 0.0 : 1.0; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + whiteFadeUIVRMatl.color.a = Mathf.Lerp(start, end, i); + yield; + } +} + function OnCollisionEnter (collision : Collision) { // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); // Screen.sleepTimeout = 0.0f; @@ -637,13 +660,13 @@ function OnTriggerEnter (other : Collider) { var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - levelStartTime); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, - FallingLaunch.secondsInLevel - ); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, + FallingLaunch.secondsInLevel + ); - // reset the level area identifier for analytics purposes: - FallingLaunch.thisLevelArea = "0-start"; + // reset the level area identifier for analytics purposes: + FallingLaunch.thisLevelArea = "0-start"; // TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName ); @@ -656,6 +679,12 @@ function OnTriggerEnter (other : Collider) { // the sum of levelComplete's first argument, // in order to create a convincing slowdown lerp and UI/camera fadeout: lerpControlOut(4.0); + + if (FallingLaunch.isVRMode) { + WhiteFadeVR(3.0, FadeDir.Out); + } + // Handles 2D (non-VR) UI logic in its own conditional, + // plus saves progress, loads the next level, etc. UIscriptComponent.LevelComplete(3.0, 1.5); } } From 7bc9901d2ea0bc699602dcfa5c4114e60bddb545 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 3 Nov 2017 00:47:47 -0700 Subject: [PATCH 39/77] Exit VR mode on Cardboard back button press; more levelComplete setup --- fallingUITest.js | 50 +++++++++++++++++++++++++----------------------- setVRMode.js | 13 +++++++++++++ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/fallingUITest.js b/fallingUITest.js index 85ccce5..32fdf13 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -632,11 +632,16 @@ function RestartLevel() { } function LevelComplete(timer1 : float, timer2 : float) { - HideGUI(); + if (!FallingLaunch.isVRMode) { + HideGUI(); + } FallingPlayer.isPausable = false; MoveController.Slowdown = 0; - bgSprite.hidden = false; - bgSprite.alphaFromTo( timer1, 0.0f, 0.97f, Easing.Sinusoidal.easeIn); + + if (!FallingLaunch.isVRMode && bgSprite) { + bgSprite.hidden = false; + bgSprite.alphaFromTo( timer1, 0.0f, 0.97f, Easing.Sinusoidal.easeIn); + } FallingLaunch.levelEndSlowdown = MoveController.Slowdown; yield WaitForSeconds(timer1); @@ -645,8 +650,11 @@ function LevelComplete(timer1 : float, timer2 : float) { savedTimeScale = Time.timeScale; //loadingLabel.hidden = false; //loadingLabel.alphaFromTo( 0.75f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - nextLevelLabel.hidden = false; - nextLevelLabel.alphaFromTo( timer2, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); + if (!FallingLaunch.isVRMode && nextLevelLabel) { + nextLevelLabel.hidden = false; + nextLevelLabel.alphaFromTo( timer2, 0.0f, 0.75f, Easing.Sinusoidal.easeIn); + } + fallingPlayerComponent.FadeAudio (.9 * timer2, FadeDir.Out); yield WaitForSeconds (timer2); @@ -975,11 +983,14 @@ function LoadHomeViaMenu() { flatTiltLabel.hidden = true; verticalTiltLabel.hidden = true; - FallingLaunch.hasSetAccel = false; - Application.LoadLevel(homeLevel); + LoadHomeNow(); Time.timeScale = savedTimeScale; } +function LoadHomeNow() { + FallingLaunch.hasSetAccel = false; + Application.LoadLevel(homeLevel); +} function OpenSite() { Application.OpenURL ("http://tysonkubota.net/"); @@ -1125,23 +1136,14 @@ function ToggleTiltNeutral () { } } -// function DisplayTilt () { -// if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) { -// flatTiltLabel.hidden = true; -// angledTiltLabel.hidden = false; -// verticalTiltLabel.hidden = true; -// } -// else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) { -// flatTiltLabel.hidden = true; -// angledTiltLabel.hidden = true; -// verticalTiltLabel.hidden = false; -// } -// else { -// flatTiltLabel.hidden = false; -// angledTiltLabel.hidden = true; -// verticalTiltLabel.hidden = true; -// } -// } +function SaveCheckpointVR () { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "ExitVRMode:" + SceneManagement.SceneManager.GetActiveScene().name, + FallingLaunch.secondsInLevel + ); + + initialRespawn.SaveCheckpoint(); +} function DisplayTiltOnPause () { diff --git a/setVRMode.js b/setVRMode.js index b2ae344..1ea9ca1 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -49,4 +49,17 @@ function Start () { if (!FallingLaunch.isVRMode) { GvrViewerMainObject.SetActive(false); // disable the GvrViewerMain gameObject to stop blank viewer from rendering } +} + +function Update () { + if (FallingLaunch.isVRMode && VRViewerComponent) { + // See note in Start() about unfortunate-but-required type coercion: + if ( (VRViewerComponent as GvrViewer).BackButtonPressed ) { + // When Cardboard SDK close icon / back button tapped, return home: + FallingPlayer.isPausable = false; + FallingLaunch.isVRMode = false; + FallingPlayer.UIscriptComponent.SaveCheckpointVR(); + FallingPlayer.UIscriptComponent.LoadHomeNow(); + } + } } \ No newline at end of file From f6ed2938358105078fa5bf63cad370386f250ad2 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 3 Nov 2017 21:25:30 -0700 Subject: [PATCH 40/77] Large orientation refactor, with recalculation on level load --- FallingLaunch.js | 162 +++++++++++++++++++++-------- FallingPlayer.js | 115 +++++++++++---------- MoveController.js | 13 --- fallingStartMenuUI.js | 230 +++++++----------------------------------- 4 files changed, 219 insertions(+), 301 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 0c818a7..dc2ca48 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -11,6 +11,7 @@ static var isTablet : boolean = false; static var tiltable : boolean = false; static var initialInputDeviceOrientation : DeviceOrientation; +static var cachedScreenOrientation : ScreenOrientation; static var hasSetAccel : boolean = false; static var restPosition : Vector3; @@ -67,33 +68,13 @@ function Start () { } initialInputDeviceOrientation = Input.deviceOrientation; - - // if (!hasSetOrientation) { - // if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) { - // flipMultiplier = flipMultiplier * -1; - // //Debug.Log("I'm in LandscapeRight!"); - // Screen.orientation = ScreenOrientation.LandscapeRight; - // neutralPosTilted = neutralPosTiltedFlipped; - // } - // else { Screen.orientation = ScreenOrientation.LandscapeLeft; - // flipMultiplier = flipMultiplier * 1; - // //Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); - // neutralPosTilted = neutralPosTiltedRegular; - // } - - // hasSetOrientation = true; - // } + cachedScreenOrientation = Screen.orientation; // this is necessary to override Unity 4's auto-orientation code Input.compensateSensors = false; // Debug.Log("Device orientation after Input.compensateSensors = false is " + Input.deviceOrientation); - // NB: still doesn't work, sensor 'correctness' depends on starting device orientation as read by Cardboard. - // HACK: Force landscape left orientation for Cardboard compatibility. - // TODO: make conditional on isVRMode? - // Screen.orientation = ScreenOrientation.LandscapeLeft; - var iOSGen = iOS.Device.generation; // Debug.Log("this is an " + iOSGen + " device!"); @@ -192,20 +173,6 @@ function Calibrate () { tiltable = true; } -function CalibrateInLevel () { - tiltable = false; - - if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) {restPosition = neutralPosTilted;} - else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) {restPosition = neutralPosVertical;} - else {restPosition = neutralPosFlat;} - - SetAxesInversion(); - calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition); - - tiltable = true; -} - - function ChangeTilt (toFlat : int) { if (toFlat == 2) { PlayerPrefs.SetInt("TiltNeutral", 2); @@ -219,13 +186,122 @@ function ChangeTilt (toFlat : int) { PlayerPrefs.SetInt("TiltNeutral", 1); Debug.Log("tilt set to angled."); } - CalibrateInLevel(); + Calibrate(); +} + +function LockDeviceOrientation (waitTime: float) { + cachedScreenOrientation = Screen.orientation; + + // Let the device auto-rotate if necessary: + Screen.autorotateToLandscapeLeft = true; + Screen.autorotateToLandscapeRight = true; + Screen.orientation = ScreenOrientation.AutoRotation; + + // iOS/Unity can give strange/wrong orientation values while screen is mid-rotation + // or close to flat, so we manually add a wait yield. + yield WaitForSeconds(waitTime); + + switch (Input.deviceOrientation) { + case DeviceOrientation.LandscapeLeft: + LockLandscapeLeftOrientation(); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeLeft", 0.0); + break; + case DeviceOrientation.LandscapeRight: + LockLandscapeRightOrientation(); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeRight", 0.0); + break; + default: + HandleDeviceOrientationMismatch(); + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationCheck:NonLandscape:" + Input.deviceOrientation, 0.0); + break; + } + + Screen.autorotateToLandscapeLeft = false; + Screen.autorotateToLandscapeRight = false; + + Calibrate(); + + if (Debug.isDebugBuild) { + Debug.Log("Final screen orientation is: " + Screen.orientation); + } + + return; } -// function Update () { -// ListCurrentAccelerometer(); -// } -// -// function ListCurrentAccelerometer() { -// Debug.Log ("Your rotation is " + Input.acceleration); -// } + +function HandleDeviceOrientationMismatch() { + if (initialInputDeviceOrientation != Input.deviceOrientation) { + + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "DeviceOrientationCheck:CachedAndCurrentMismatch:" + Input.deviceOrientation + ":" + initialInputDeviceOrientation, + 0.0 + ); + + if (initialInputDeviceOrientation == DeviceOrientation.LandscapeLeft) { + if (Debug.isDebugBuild) { + Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape left..."); + } + initialInputDeviceOrientation = Input.deviceOrientation; + LockLandscapeLeftOrientation(); + } else if (initialInputDeviceOrientation == DeviceOrientation.LandscapeRight) { + if (Debug.isDebugBuild) { + Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape right..."); + } + initialInputDeviceOrientation = Input.deviceOrientation; + LockLandscapeRightOrientation(); + } else { + DefaultToLandscapeLeftOrientation(); + } + + } else { + if (Debug.isDebugBuild) { + Debug.Log("InitialInputDeviceOrientation and Input.deviceOrientation do match, as " + Input.deviceOrientation); + } + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:CachedAndCurrentMatch:" + Input.deviceOrientation, 0.0); + + // But we must choose left or right, ultimately... + DefaultToLandscapeLeftOrientation(); + } + + return; +} + +function DefaultToLandscapeLeftOrientation() { + if (Screen.orientation == ScreenOrientation.LandscapeRight || cachedScreenOrientation == ScreenOrientation.LandscapeRight || + Input.deviceOrientation == DeviceOrientation.LandscapeRight) { + if (Debug.isDebugBuild) { + Debug.Log("Picking LandscapeRight, to match Screen.orientation or Input.deviceOrientation"); + } + LockLandscapeRightOrientation(); + } else { + if (Debug.isDebugBuild) { + Debug.Log("Defaulting to LandscapeLeft, since Screen.orientation / Input.deviceOrientation were not LandscapeRight"); + } + LockLandscapeLeftOrientation(); + } +} + +function LockLandscapeLeftOrientation () { + if (Debug.isDebugBuild) {Debug.Log("Locking LandscapeLeft orientation");} + + Screen.orientation = ScreenOrientation.LandscapeLeft; + cachedScreenOrientation = Screen.orientation; + + neutralPosTilted = neutralPosTiltedRegular; + neutralPosVertical = neutralPosVerticalRegular; + flipMultiplier = 1.0; +} + +function LockLandscapeRightOrientation () { + if (Debug.isDebugBuild) {Debug.Log("Locking LandscapeRight orientation");} + + Screen.orientation = ScreenOrientation.LandscapeRight; + cachedScreenOrientation = Screen.orientation; + + neutralPosTilted = neutralPosTiltedFlipped; + neutralPosVertical = neutralPosVerticalFlipped; + flipMultiplier = -1.0; +} \ No newline at end of file diff --git a/FallingPlayer.js b/FallingPlayer.js index 6bb3893..dd03e09 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -1,5 +1,8 @@ #pragma strict +private var fallingLaunch : GameObject; +private var fallingLaunchComponent : FallingLaunch; + // 10/25/2017: `Color` uses a 0-1 float range, not 0-2, in Unity. // 2 = 255 for rgba in this color array // static var startingFogColor : Color = Color(1.17, 1.17, 1.17, 2); @@ -123,52 +126,60 @@ function Awake() { } function Start() { - myMainCamera = Camera.main; - myBackdrop = GameObject.Find("plane-close"); - BackdropMist = GameObject.Find("Cylinder"); - myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; - lifeCountdownScript = gameObject.GetComponent.(); + fallingLaunch = GameObject.Find("LaunchGameObject"); + fallingLaunchComponent = fallingLaunch.GetComponent.(); - if (FallingLaunch.isVRMode) { - myVRViewer = GameObject.Find("GvrViewerMain"); - scoreUIVRRenderer = scoreUIVR.GetComponent.(); - scoreUIVRMatl = scoreUIVRRenderer.material; - scoreUIVRMatl.color.a = 0; - - whiteFadeUIVRRenderer = whiteFadeUIVR.GetComponent.(); - whiteFadeUIVRMatl = whiteFadeUIVRRenderer.material; - whiteFadeUIVRMatl.color.a = 0; - // Hack to have two separate death/fade-to-black sphere objects, - // but neither shader does everything. The inverted transparent shader occludes - // all physical objects, but the UIToolkit one is needed for covering light halos. - // The opaque and transparent materials have manual RenderQueue settings - // of 5000 (the official max) and 6000, respectively. - if (deathFadeUIVR && opaqueDeathFadeUIVR) { - deathFadeUIVRRenderer = deathFadeUIVR.GetComponent.(); - deathFadeUIVRMatl = deathFadeUIVRRenderer.material; - - opaqueDeathFadeUIVRRenderer = opaqueDeathFadeUIVR.GetComponent.(); - opaqueDeathFadeUIVRMatl = opaqueDeathFadeUIVRRenderer.material; + if (!FallingLaunch.isVRMode) { + // In case the calculation in the start menu was wrong/outmoded: + fallingLaunchComponent.LockDeviceOrientation(1.0); + } - if (deathFadeUIVRMatl.HasProperty("_Color")) { - deathFadeUIVRMatl.color.a = 0; - } - if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) { - var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor"); - currentColor.a = 0; - opaqueDeathFadeUIVRMatl.SetColor("_TintColor", currentColor); - } - } + myMainCamera = Camera.main; + myBackdrop = GameObject.Find("plane-close"); + BackdropMist = GameObject.Find("Cylinder"); + myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; + lifeCountdownScript = gameObject.GetComponent.(); - if (reticleVRUIObj) { - reticleVRUIScript = reticleVRUIObj.GetComponent.(); - } else { - Debug.LogError("You forgot to assign an object for the VR reticle... trying to look up manually"); - reticleVRUIScript = GameObject.Find("vr-radial-life-meter").GetComponent.(); + if (FallingLaunch.isVRMode) { + myVRViewer = GameObject.Find("GvrViewerMain"); + scoreUIVRRenderer = scoreUIVR.GetComponent.(); + scoreUIVRMatl = scoreUIVRRenderer.material; + scoreUIVRMatl.color.a = 0; + + whiteFadeUIVRRenderer = whiteFadeUIVR.GetComponent.(); + whiteFadeUIVRMatl = whiteFadeUIVRRenderer.material; + whiteFadeUIVRMatl.color.a = 0; + // Hack to have two separate death/fade-to-black sphere objects, + // but neither shader does everything. The inverted transparent shader occludes + // all physical objects, but the UIToolkit one is needed for covering light halos. + // The opaque and transparent materials have manual RenderQueue settings + // of 5000 (the official max) and 6000, respectively. + if (deathFadeUIVR && opaqueDeathFadeUIVR) { + deathFadeUIVRRenderer = deathFadeUIVR.GetComponent.(); + deathFadeUIVRMatl = deathFadeUIVRRenderer.material; + + opaqueDeathFadeUIVRRenderer = opaqueDeathFadeUIVR.GetComponent.(); + opaqueDeathFadeUIVRMatl = opaqueDeathFadeUIVRRenderer.material; + + if (deathFadeUIVRMatl.HasProperty("_Color")) { + deathFadeUIVRMatl.color.a = 0; + } + if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) { + var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor"); + currentColor.a = 0; + opaqueDeathFadeUIVRMatl.SetColor("_TintColor", currentColor); } - reticleVRUIScript.FadeReticleIn(1.5); } + if (reticleVRUIObj) { + reticleVRUIScript = reticleVRUIObj.GetComponent.(); + } else { + Debug.LogError("You forgot to assign an object for the VR reticle... trying to look up manually"); + reticleVRUIScript = GameObject.Find("vr-radial-life-meter").GetComponent.(); + } + reticleVRUIScript.FadeReticleIn(1.5); + } + // startingFogColor = RenderSettings.fogColor * 2; startingFogEndDistance = RenderSettings.fogEndDistance; startingFogStartDistance = RenderSettings.fogStartDistance; @@ -197,8 +208,8 @@ function Start() { LevelStartFade(); - // since it was probably lerped down to zero at previous levelEnd, initialize it here. - MoveController.controlMultiplier = 1; + // since it was probably lerped down to zero at previous levelEnd, initialize it here. + MoveController.controlMultiplier = 1; } function LevelStartFade () { @@ -231,17 +242,17 @@ function introNow() { function FadeAudio(timer : float, fadeType : FadeDir) { - var start = fadeType == FadeDir.In? 0.0 : 1.0; - var end = fadeType == FadeDir.In? 1.0 : 0.0; - var i = 0.0; - var step = 1.0/timer; + var start = fadeType == FadeDir.In? 0.0 : 1.0; + var end = fadeType == FadeDir.In? 1.0 : 0.0; + var i = 0.0; + var step = 1.0/timer; - while (i <= 1.0) { - i += step * Time.deltaTime; - // var t : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp - AudioListener.volume = Mathf.Lerp(start, end, i); - yield; - } + while (i <= 1.0) { + i += step * Time.deltaTime; + // var t : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp + AudioListener.volume = Mathf.Lerp(start, end, i); + yield; + } } diff --git a/MoveController.js b/MoveController.js index 7c12e81..651bb5d 100644 --- a/MoveController.js +++ b/MoveController.js @@ -59,19 +59,6 @@ function Awake() { function Start() { - // HACK: Force landscape left orientation in VR for Cardboard compatibility. - // Or is this best off just being removed? - // NB: If your phone is tilted a little beyond flat (away from you) on level load, - // then all other game objects will be behind you when you look up: 180deg wrong - // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse - // quaternion in some cases based on Head gaze direction/ gameObj position, - // or in the menu UI, ensure the phone orientation is not flat before - // letting the user load the scene... - if (FallingLaunch.isVRMode) { - // TODO FIXME FOR VR MODE: see above - Screen.orientation = ScreenOrientation.LandscapeLeft; - } - // Screen.sleepTimeout = 0.0f; // deprecated, now should use NeverSleep Screen.sleepTimeout = SleepTimeout.NeverSleep; diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index fbfab89..9be5f57 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -88,11 +88,13 @@ var bgCamera : Camera; var bgColor1 : Color; var bgColor2 : Color = Color.red; -var fallingLaunch : GameObject; -var fallingLaunchComponent : FallingLaunch; +private var fallingLaunch : GameObject; +private var fallingLaunchComponent : FallingLaunch; function Awake () { //Input.compensateSensors = true; + fallingLaunch = GameObject.Find("LaunchGameObject"); + fallingLaunchComponent = fallingLaunch.GetComponent.(); if (Debug.isDebugBuild) { Debug.Log("My screen orientation is " + Screen.orientation); @@ -101,120 +103,38 @@ function Awake () { Debug.Log("Cached FallingLaunch Input.deviceOrientation is " + FallingLaunch.initialInputDeviceOrientation); } - //Screen.orientation = ScreenOrientation.AutoRotation; - // if (FallingLaunch.hasSetOrientation == false) { - // AutoOrientToLandscape(); - // } - - if (!FallingLaunch.hasSetOrientation) { - // Just to be safe, exclude portrait modes from potential autorotation: - Screen.autorotateToPortrait = false; - Screen.autorotateToPortraitUpsideDown = false; - - // We have to use autoRotation here, due to crashes on force-changing Screen.orientation - // in conjunction with permitted-via-settings autoRotation - // (if app launches mid-screen-rotation?). - // Source: https://forum.unity.com/threads/unitydefaultviewcontroller-should-be-used-only-if-unity-is-set-to-autorotate.314542/#post-2833628 - Screen.orientation = ScreenOrientation.AutoRotation; - - // on iPhones, we could probably assume input to be landscape-left most of the time, - // unless the device is known to be in landscape-right - // (the edge cases are iPads lying on a flat surface, which could have either screen orientation): - - // This function waits an [arbitrary] second for iOS's autorotation to settle, then locks it. - // It's not yielded, so it doesn't delay execution of the `hasSetOrientation = true` below. - LockDeviceOrientation(1.0f); - - if (Debug.isDebugBuild) { - Debug.Log("My final screen orientation is " + Screen.orientation); - } - - FallingLaunch.hasSetOrientation = true; - } - - fallingLaunch = GameObject.Find("LaunchGameObject"); - fallingLaunchComponent = fallingLaunch.GetComponent("FallingLaunch"); ScreenH = Screen.height; ScreenW = Screen.width; screenAspectRatio = (ScreenH / ScreenW); } -function LockDeviceOrientation (waitTime: float) { - // iOS/Unity can give strange/wrong orientation values while screen is mid-rotation - //or close to flat, so we manually add a wait yield. - yield WaitForSeconds(waitTime); - - Screen.autorotateToLandscapeLeft = false; - Screen.autorotateToLandscapeRight = false; - - switch (Input.deviceOrientation) { - case DeviceOrientation.LandscapeLeft: - LockLandscapeLeftOrientation(); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeLeft", 0.0); - break; - case DeviceOrientation.LandscapeRight: - LockLandscapeRightOrientation(); - - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeRight", 0.0); - break; - default: - HandleDeviceOrientationMismatch(); - - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationCheck:NonLandscape:" + Input.deviceOrientation, 0.0); - break; +function Start () { + // Just to be safe, exclude portrait modes from potential autorotation: + Screen.autorotateToPortrait = false; + Screen.autorotateToPortraitUpsideDown = false; + + // We have to use autoRotation here, due to crashes on force-changing Screen.orientation + // in conjunction with permitted-via-settings autoRotation + // (if app launches mid-screen-rotation?). + // Source: https://forum.unity.com/threads/unitydefaultviewcontroller-should-be-used-only-if-unity-is-set-to-autorotate.314542/#post-2833628 + Screen.orientation = ScreenOrientation.AutoRotation; + + // on iPhones, we could probably assume input to be landscape-left most of the time, + // unless the device is known to be in landscape-right + // (the edge cases are iPads lying on a flat surface, which could have either screen orientation): + + // This function waits an [arbitrary] second for iOS's autorotation to settle, then locks it. + // It's not yielded, so it doesn't delay execution of the `hasSetOrientation = true` below. + if (!FallingLaunch.isVRMode) { + fallingLaunchComponent.LockDeviceOrientation(1.0); } - return; -} - - -function HandleDeviceOrientationMismatch() { - if (FallingLaunch.initialInputDeviceOrientation != Input.deviceOrientation) { - - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "DeviceOrientationCheck:CachedAndCurrentMismatch:" + Input.deviceOrientation + ":" + FallingLaunch.initialInputDeviceOrientation, - 0.0 - ); - - if (FallingLaunch.initialInputDeviceOrientation == DeviceOrientation.LandscapeLeft) { - if (Debug.isDebugBuild) { - Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape left..."); - } - LockLandscapeLeftOrientation(); - } else if (FallingLaunch.initialInputDeviceOrientation == DeviceOrientation.LandscapeRight) { - if (Debug.isDebugBuild) { - Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape right..."); - } - LockLandscapeRightOrientation(); - } - - } else { - if (Debug.isDebugBuild) { - Debug.Log( - "No need to manually set Screen.orientation, since initialInputDeviceOrientation and Input.deviceOrientation do match, as " + Input.deviceOrientation - ); - } - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:CachedAndCurrentMatch:" + Input.deviceOrientation, 0.0); + if (Debug.isDebugBuild) { + Debug.Log("My final screen orientation is " + Screen.orientation); } - return; -} -function LockLandscapeLeftOrientation () { - Screen.orientation = ScreenOrientation.LandscapeLeft; - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; - FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalRegular; -} - -function LockLandscapeRightOrientation () { - Screen.orientation = ScreenOrientation.LandscapeRight; - FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; - FallingLaunch.neutralPosVertical = FallingLaunch.neutralPosVerticalFlipped; - FallingLaunch.flipMultiplier = -FallingLaunch.flipMultiplier; -} - -function Start () { // resets all prefs on launch to simplify debugging: // PlayerPrefs.DeleteAll(); if (PlayerPrefs.HasKey("HighestLevel") == false) { @@ -1063,6 +983,18 @@ function OpenVRModeMenu() { function LaunchVRMode() { FallingLaunch.isVRMode = true; + + // NB: If your phone is tilted a little beyond flat (away from you) on level load, + // then all other game objects will be behind you when you look up: 180deg wrong + // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse + // quaternion in some cases based on Head gaze direction/ gameObj position, + // or in the menu UI, ensure the phone orientation is not flat before + // letting the user load the scene. + + // HACK: But as a temporary workaround, force landscape left orientation + // in VR for Cardboard compatibility (Google's SDK also enforces this mode + // with 'tilt your phone' UI when device is in landscape right): + fallingLaunchComponent.LockLandscapeLeftOrientation(); ResumeGame(); } @@ -1320,91 +1252,3 @@ function upLevel4() { loadLevelFour.alphaTo(.25f, 0.8f, Easing.Sinusoidal.easeOut); } } - -// function SetOrientationNow() { -// if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { -// Screen.orientation = ScreenOrientation.LandscapeRight; -// FallingLaunch.flipMultiplier = -1; -// Debug.Log("I'm in LandscapeRight!"); -// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; -// } -// else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft){ -// Screen.orientation = ScreenOrientation.LandscapeLeft; -// FallingLaunch.flipMultiplier = 1; -// Debug.Log("I'm in LandscapeLeft, or Portrait, or FaceDown/Up!"); -// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; -// } - -// //this is necessary to override Unity 4's auto-orientation code -// Input.compensateSensors = false; -// yield; -// return; -// } - - -// function FixWrongInitialScreenOrientation () { -// if ( (Screen.height > Screen.width && Input.deviceOrientation.ToString().ToLower().StartsWith("landscape")) -// || (Screen.width > Screen.height && Input.deviceOrientation.ToString().ToLower().StartsWith("portrait")) -// ) { -// Debug.LogWarning("Fixing wrong screen orientation ("+ Screen.orientation +") to right device orientation: "+ Input.deviceOrientation); -// switch (Input.deviceOrientation) { -// case DeviceOrientation.LandscapeLeft: -// Screen.orientation = ScreenOrientation.LandscapeLeft; -// break; -// case DeviceOrientation.LandscapeRight: -// Screen.orientation = ScreenOrientation.LandscapeRight; -// break; -// case DeviceOrientation.PortraitUpsideDown: -// Screen.orientation = ScreenOrientation.PortraitUpsideDown; -// break; -// case DeviceOrientation.Portrait: -// Screen.orientation = ScreenOrientation.Portrait; -// break; -// } -// } -// yield; -// } - -// function AutoOrientToLandscape () { - -// // if (Input.deviceOrientation == DeviceOrientation.FaceUp) { -// // if (Screen.orientation == ScreenOrientation.LandscapeRight) { -// // Debug.Log("Device is FaceUp, and ScreenOrientation is LandscapeRight"); -// // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; -// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; -// // } -// // else { -// // Debug.Log("Device is FaceUp, and ScreenOrientation is NOT LandscapeRight"); -// // FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; -// // FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; -// // } - -// // Screen.autorotateToLandscapeRight = false; -// // Screen.autorotateToLandscapeLeft = false; -// // Screen.autorotateToPortrait = false; -// // Screen.autorotateToPortraitUpsideDown = false; - -// // } - -// if (Vector3.Dot(Input.acceleration.normalized, Vector3(1,0,0)) > 0) -// //else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) -// { -// Screen.orientation = ScreenOrientation.LandscapeRight; -// FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * -1; -// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedFlipped; -// } -// else if(Vector3.Dot(Input.acceleration.normalized, Vector3(-1,0,0)) > 0) -// //else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) -// { -// Screen.orientation = ScreenOrientation.LandscapeLeft; -// FallingLaunch.flipMultiplier = FallingLaunch.flipMultiplier * 1; -// FallingLaunch.neutralPosTilted = FallingLaunch.neutralPosTiltedRegular; -// } -// FallingLaunch.hasSetOrientation = true; -// } - -// function StopCompensatingSensors() { -// //this is necessary to override Unity 4's auto-orientation code -// Input.compensateSensors = false; -// yield; -// } From 28466dea006bbdcdc21c6f6971c8b2c3d69dbd9e Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Mon, 6 Nov 2017 20:01:40 -0800 Subject: [PATCH 41/77] Interstitial UI upon first loading level in VR mode --- FallingLaunch.js | 1 + FallingPlayer.js | 77 +++++++++++++++++++++++++++++++------------ FallingStartMenu.js | 1 - MoveController.js | 36 ++++++++++++-------- fallingStartMenuUI.js | 4 ++- 5 files changed, 83 insertions(+), 36 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index dc2ca48..518c0d9 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -36,6 +36,7 @@ static var debugMode : boolean = false; // true; var testFlightToken : String; static var isVRMode : boolean = false; +static var shouldShowVRIntroUI : boolean = false; //GameAnalytics variables static var secondsAlive : float = 0; diff --git a/FallingPlayer.js b/FallingPlayer.js index dd03e09..9463e59 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -71,6 +71,7 @@ var opaqueDeathFadeUIVR : GameObject; private var opaqueDeathFadeUIVRRenderer : Renderer; private var opaqueDeathFadeUIVRMatl : Material; +var levelStartUIVR : GameObject; var deathPauseUIVR : GameObject; var whiteFadeUIVR : GameObject; @@ -141,6 +142,7 @@ function Start() { lifeCountdownScript = gameObject.GetComponent.(); if (FallingLaunch.isVRMode) { + myVRViewer = GameObject.Find("GvrViewerMain"); scoreUIVRRenderer = scoreUIVR.GetComponent.(); scoreUIVRMatl = scoreUIVRRenderer.material; @@ -149,6 +151,7 @@ function Start() { whiteFadeUIVRRenderer = whiteFadeUIVR.GetComponent.(); whiteFadeUIVRMatl = whiteFadeUIVRRenderer.material; whiteFadeUIVRMatl.color.a = 0; + // Hack to have two separate death/fade-to-black sphere objects, // but neither shader does everything. The inverted transparent shader occludes // all physical objects, but the UIToolkit one is needed for covering light halos. @@ -195,21 +198,25 @@ function Start() { AudioListener.pause = false; myVol = audioScore.volume; peakVol = audioScore.volume; -// fadeInAudio (); FadeAudio(0.1, FadeDir.In); isPausable = false; rb = GetComponent.(); - rb.isKinematic = false; + + if (FallingLaunch.isVRMode && levelStartUIVR) { + levelStartUIVR.SetActive(true); + isAlive = 0; + rb.isKinematic = true; + } else { + isAlive = 1; + rb.isKinematic = false; + } if (!introComponent) { UIscriptComponent.UnhideGUI(); } LevelStartFade(); - - // since it was probably lerped down to zero at previous levelEnd, initialize it here. - MoveController.controlMultiplier = 1; } function LevelStartFade () { @@ -231,7 +238,7 @@ function introFade() { whiteFader.enabled = false; } -function introNow() { +function introNow() { LatestCheckpointRespawn(); yield WaitForSeconds (3); FallingLaunch.LoadedLatestLevel = false; @@ -297,7 +304,7 @@ function DeathRespawn () { rb.isKinematic = false; - MoveController.controlMultiplier = 1; + MoveController.controlMultiplier = 1.0; if (FallingLaunch.isVRMode && deathPauseUIVR && deathFadeUIVR) { @@ -331,9 +338,13 @@ function DeathRespawn () { FadeAudio(2.0, FadeDir.In); DeathFadeVR(1.0, FadeDir.In); - lerpControlIn(3.0); isPausable = true; + + // setting isAlive is order-dependent with lerpControlIn below + // (isAlive = 0 will break its loop): isAlive = 1; + lerpControlIn(3.0); + yield WaitForSeconds(1); reticleVRUIScript.FadeReticleIn(1.5); @@ -347,7 +358,7 @@ function DeathRespawn () { function LatestCheckpointRespawn () { isPausable = false; rb.isKinematic = true; - var respawnPosition = Respawn.currentRespawn.transform.position; + var respawnPosition = Respawn.currentRespawn.transform.position; //UIscriptComponent.fadeOut(); if (levelChangeBackdrop == true) { @@ -355,21 +366,26 @@ function LatestCheckpointRespawn () { } // yield WaitForSeconds(1); - isAlive = 1; + // if in VR intro, don't set isAlive yet, since that will start the lifeCountdown timer ticking: + if (FallingLaunch.isVRMode && FallingLaunch.shouldShowVRIntroUI) { + isAlive = 0; + } else { + isAlive = 1; + } + RenderSettings.fogEndDistance = startingFogEndDistance; - RenderSettings.fogStartDistance = startingFogStartDistance; + RenderSettings.fogStartDistance = startingFogStartDistance; GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); myTransform.position = respawnPosition; // + Vector3.up; FadeAudio(fadeTime, FadeDir.In); - rb.isKinematic = false; - - MoveController.controlMultiplier = 1; - - lerpControlIn(3); - //yield UIscriptComponent.fadeIn(true); - UIscriptComponent.UnhideGUI(); + + if (!FallingLaunch.isVRMode) { + rb.isKinematic = false; + lerpControlIn(3.0); + UIscriptComponent.UnhideGUI(); + } } function ShowDeathHelp() { @@ -415,6 +431,14 @@ function Update () { } } + if (FallingLaunch.isVRMode && levelStartUIVR.activeInHierarchy && FallingLaunch.shouldShowVRIntroUI) { + for (var i2 = 0; i2 < Input.touchCount; ++i2) { + if (Input.GetTouch(i2).phase == TouchPhase.Ended && Input.GetTouch(i2).phase != TouchPhase.Canceled) { + ContinueFromLevelStartVR(); + } + } + } + //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); //Debug.Log("your current acceleration is: " + FallingLaunch.accelerator); } @@ -438,11 +462,11 @@ function playerTilt() { function lerpControlIn(timer : float) { - //Debug.Log("your flip multiplier is " + FallingLaunch.flipMultiplier); - //Debug.Log("your control multiplier is " + MoveController.controlMultiplier); + // Debug.Log("your flip multiplier is " + FallingLaunch.flipMultiplier); + // Debug.Log("your control multiplier is " + MoveController.controlMultiplier); var start = 0.0; - var end = MoveController.controlMultiplier; + var end = 1.0; // MoveController.controlMultiplier; var i = 0.0; var step = 1.0/timer; @@ -700,4 +724,15 @@ function OnTriggerEnter (other : Collider) { } } +function ContinueFromLevelStartVR () { + FallingLaunch.shouldShowVRIntroUI = false; + + // TODO: Fade out material here instead of toggling the whole object outright? + levelStartUIVR.SetActive(false); + rb.isKinematic = false; + isAlive = 1; + isPausable = true; + lerpControlIn(1.5); +} + @script AddComponentMenu("Scripts/FallingPlayer") diff --git a/FallingStartMenu.js b/FallingStartMenu.js index 6d0fb22..e303342 100644 --- a/FallingStartMenu.js +++ b/FallingStartMenu.js @@ -70,7 +70,6 @@ function Start() { isAlive = 1; UIscriptComponent = UIscriptName.GetComponent(fallingStartMenuUI); AudioListener.pause = false; -// fadeInAudio (); FadeAudio (0.1, FadeDir.In); isPausable = true; diff --git a/MoveController.js b/MoveController.js index 651bb5d..66fd764 100644 --- a/MoveController.js +++ b/MoveController.js @@ -77,12 +77,21 @@ function Start() { //Calibrate(); + lerpSlowdown(.5); + // resetting controlMultiplier in case it was zeroed from the previous level // (since as a global/static var, it's cached across level loads); - controlMultiplier = 1.0; + // Also, since it was probably lerped down to zero at previous levelEnd, initialize it here, except in the case where . + if (FallingLaunch.shouldShowVRIntroUI && FallingLaunch.isVRMode) { + MoveController.controlMultiplier = 0.0; + } else { + MoveController.controlMultiplier = 1.0; + } + + if (!FallingLaunch.isVRMode) { + lerpControlIn(3.0); + } - lerpSlowdown(.5); - lerpControl(3); //pauseButtonArea = Rect(0, 0, Screen.width / 2, Screen.height / 2); pauseButtonArea = Rect(Screen.width * .9, Screen.height * .8, Screen.width * .1, Screen.height * .2); @@ -139,13 +148,14 @@ function MovePlayerVR () { Mathf.Max(1.25, speedRatio * speed) : 1.0 + (speedRatio * maxLateralSpeed); // Debug.Log('lateralSpeedBoost: ' + lateralSpeedBoost); - + // Debug.Log('controlMultiplier: ' + controlMultiplier); + // Dir is clamped to +/-2 units/frame (and avoiding direct use of the speed multiplier) // to obtain more 'realistic' 1:1 movement, with just a little amplification, // and with lateralSpeedBoost as the extra if you're touching the screen. // myTransform.Translate (dir * (1.0 + lateralSpeedBoost), Space.World); // myTransform.Translate (dir * lateralSpeedBoost, Space.World); - myTransform.Translate (dir * lateralSpeedBoost, Space.World); + myTransform.Translate (dir * lateralSpeedBoost * controlMultiplier, Space.World); } function MovePlayer(horizAxisInversionVal: int, vertAxisInversionVal: int) { @@ -193,7 +203,9 @@ function Update () { // decent collision detection. function FallingSpeed () { - + // Debug.Log("FallingPlayer.isAlive: " + FallingPlayer.isAlive); + // Debug.Log('controlMultiplier: ' + controlMultiplier); + // Debug.Log("FallingPlayer.isPausable: " + FallingPlayer.isPausable); fingerCount = 0; if (FallingPlayer.isAlive == 1 && FallingPlayer.isPausable == true) { @@ -383,19 +395,17 @@ function lerpPitchDown (timer : float, endPitch : float, endVolume : float) { changingPitch = false; } -function lerpControl(timer : float) { +function lerpControlIn(timer : float) { - var start = 0.0; - var end = controlMultiplier; - var i = 0.0; + var i : float = 0.0; var step = 1.0/timer; - while (i <= 1.0) { i += step * Time.deltaTime; - controlMultiplier = Mathf.Lerp(start, end, i); + controlMultiplier = Mathf.Lerp(0.0, 1.0, i); yield; - //Debug.Log("My flipmultiplier is " + FallingLaunch.flipMultiplier + " and my end is " + end); + // Debug.Log("My controlMultiplier is " + controlMultiplier); + // Debug.Log("My flipmultiplier is " + FallingLaunch.flipMultiplier + " and my end is " + end); } yield WaitForSeconds (timer); } diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 9be5f57..13b69bf 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -144,7 +144,9 @@ function Start () { FallingLaunch.levelAchieved = PlayerPrefs.GetInt("HighestLevel"); -// yield WaitForSeconds(0.5f); + // every return to the Start menu means re-entering VR mode + // should show the in-level intro UI: + FallingLaunch.shouldShowVRIntroUI = true; // Testing to see if disabling this hard coded screen.orientation will allow auto detection of landscape // right or left mode on startup. From 3bd4761cfe845b028300ed7a67c315f564695368 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Tue, 7 Nov 2017 23:28:49 -0800 Subject: [PATCH 42/77] Tutorial UI in VR mode --- FallingLaunch.js | 2 +- FallingPlayer.js | 13 ++++++++--- IntroSequence1stPerson.js | 18 +++++++++------ IntroUITrigger.js | 19 +++++++++++----- fallingIntroUI.js | 48 ++++++++++++++++++++++++++++++++++++++- lifeCountdown.js | 14 ++++++++---- 6 files changed, 92 insertions(+), 22 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 518c0d9..23ff5f6 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -60,7 +60,7 @@ function Awake () { function Start () { - + // PlayerPrefs.DeleteAll(); if (!alreadyLaunched) { // TestFlightUnity.TestFlight.TakeOff( testFlightToken ); diff --git a/FallingPlayer.js b/FallingPlayer.js index 9463e59..6ec39a4 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -84,12 +84,12 @@ private var scoreUIVRMatl : Material; private var peakScoreFlashValueVR : float = 1.0; var reticleVRUIObj : GameObject; -private var reticleVRUIScript : VRLifeMeter; +static var reticleVRUIScript : VRLifeMeter; var clearDestroyedObjects : boolean = false; var whiteFader : FadeInOutAlt; -var introComponent : IntroSequence1stPerson; +private var introComponent : IntroSequence1stPerson; introComponent = GetComponent("IntroSequence1stPerson"); var simpleVelocityLimiterComponent : SimpleVelocityLimiter; @@ -180,7 +180,6 @@ function Start() { Debug.LogError("You forgot to assign an object for the VR reticle... trying to look up manually"); reticleVRUIScript = GameObject.Find("vr-radial-life-meter").GetComponent.(); } - reticleVRUIScript.FadeReticleIn(1.5); } // startingFogColor = RenderSettings.fogColor * 2; @@ -212,8 +211,16 @@ function Start() { rb.isKinematic = false; } + // introComponent's existence is a proxy for level 1, + // where we don't want the reticle to be visible yet + // (resuming from a level 1 post-intro checkpoint + // is handled in Respawn.js (mainRespawnScript): if (!introComponent) { UIscriptComponent.UnhideGUI(); + + if (FallingLaunch.isVRMode) { + reticleVRUIScript.FadeReticleIn(1.5); + } } LevelStartFade(); diff --git a/IntroSequence1stPerson.js b/IntroSequence1stPerson.js index 794641c..9682777 100644 --- a/IntroSequence1stPerson.js +++ b/IntroSequence1stPerson.js @@ -15,6 +15,7 @@ function Start () { if (!FallingLaunch.NewGamePlus) { PlayerController.enabled = false; ScoreController.enabled = false; + if (!FallingLaunch.isVRMode) { FallingPlayer.UIscriptComponent.HideGUI(); } @@ -27,16 +28,15 @@ function Start () { destructible.enabled = false; shardColor = shardRenderer.material.color; } - } - else if (FallingLaunch.NewGamePlus) { + } else if (FallingLaunch.NewGamePlus) { PlayerController.enabled = true; ScoreController.enabled = true; LifeController.enabled = true; - //FallingPlayer.UIscriptComponent.HideGUI(); - FallingPlayer.UIscriptComponent.UnhideGUI(); - } - + if (!FallingLaunch.isVRMode) { + FallingPlayer.UIscriptComponent.UnhideGUI(); + } + } } function EndIntro (playAudio : boolean) { @@ -48,6 +48,10 @@ function EndIntro (playAudio : boolean) { FallingPlayer.UIscriptComponent.UnhideGUI(); } + if (FallingLaunch.isVRMode) { + FallingPlayer.reticleVRUIScript.FadeReticleIn(1.5); + } + for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { destructible = shard.GetComponent(ProjectileDestroy); shard.GetComponent.().isKinematic = false; @@ -69,7 +73,7 @@ function EndIntro (playAudio : boolean) { for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) shard.GetComponent.().material.color = Color.Lerp(start, end, i); yield; - } + } } function DeathHelp() { diff --git a/IntroUITrigger.js b/IntroUITrigger.js index dbb7fe7..5751f5a 100644 --- a/IntroUITrigger.js +++ b/IntroUITrigger.js @@ -7,13 +7,14 @@ var fallingUI : GameObject; static var fallingUIComponent : fallingUITest; enum Triggers { -trigger1, -trigger2, -trigger3 + trigger1, + trigger2, + trigger3 }; var helpIcon: UISprite; var thisIcon : String; +var iconNameVR : String; var thisTimer : float = 8; var thisTrigger : Triggers; var tutorialSprite : UISprite; @@ -61,7 +62,7 @@ function Start () { helpIcon.pixelsFromBottom(textHeight); helpIcon.hidden = true; - + audioSource = GetComponent.(); } @@ -69,8 +70,12 @@ function Start () { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Player") && activeIntro == false && FallingLaunch.NewGamePlus == false) { activeIntro = true; - fallingIntroUIComponent.ShowIcon(helpIcon, thisTimer, tutorialSprite); - tutorialSpritePosition(thisTimer); + if (FallingLaunch.isVRMode) { + fallingIntroUIComponent.ShowIconVR(iconNameVR, thisTimer); + } else { + fallingIntroUIComponent.ShowIcon(helpIcon, thisTimer, tutorialSprite); + tutorialSpritePosition(thisTimer); + } if (audioSource) {audioSource.Play();} } } @@ -93,6 +98,8 @@ function tutorialSpritePosition(timer : float) { } function ShowHelpAfterDeath() { + if (!FallingLaunch.isVRMode) { fallingIntroUIComponent.ShowIcon(helpIcon, 2, tutorialSprite); tutorialSpritePosition(2); + } } \ No newline at end of file diff --git a/fallingIntroUI.js b/fallingIntroUI.js index eae4e05..e22a29b 100644 --- a/fallingIntroUI.js +++ b/fallingIntroUI.js @@ -2,9 +2,13 @@ var scriptName : GameObject; static var currentIcon : UISprite; +private var tutorialObjVR : GameObject; +private var iconVRMatl : Material; +private var iconVRRenderer : Renderer; function Start () { - } + tutorialObjVR = gameObject.Find("tutorial-vr-ui-group"); +} function ShowIcon(icon : UISprite, timer : float, bgIcon : UISprite) { // tutorialSpritePosition(timer); @@ -25,4 +29,46 @@ function ShowIcon(icon : UISprite, timer : float, bgIcon : UISprite) { icon.alphaTo( 2.0f, 0.0f, Easing.Sinusoidal.easeOut); yield WaitForSeconds (2); icon.hidden = true; +} + +function ShowIconVR(iconName : String, timer : float) { + // TODO: Improve perf by grabbing and caching these in Start? + // find corresponding gameObject in children: + // Debug.Log("Showing " + iconName); + var thisIcon : GameObject = tutorialObjVR.transform.Find(iconName).gameObject; + + if (thisIcon) { + thisIcon.SetActive(true); + iconVRRenderer = thisIcon.GetComponent.(); + iconVRMatl = iconVRRenderer.material; + // iconVRMatl.color.a = 1; + FadeIconVR(timer/4, FadeDir.In); + + yield WaitForSeconds (timer/2); + if (FallingPlayer.isAlive == 0) { + iconVRMatl.color.a = 0; thisIcon.SetActive(false); return; + } + yield WaitForSeconds (timer/4); + + FadeIconVR(timer/4, FadeDir.Out); + + yield WaitForSeconds (timer/4); + // iconVRMatl.color.a = 0; + thisIcon.SetActive(false); + } +} + +function FadeIconVR (timer : float, fadeType : FadeDir) { + + var start = fadeType == FadeDir.In ? 0.0 : 0.8; + var end = fadeType == FadeDir.In ? 0.8 : 0.0; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + iconVRMatl.color.a = Mathf.Lerp(start, end, i); + yield; + if (FallingPlayer.isAlive == 0) {iconVRMatl.color.a = 0.0; break;} + } } \ No newline at end of file diff --git a/lifeCountdown.js b/lifeCountdown.js index d26e496..ecb6d84 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -1,13 +1,15 @@ -var script : ScoreController; +private var script : ScoreController; var LifeFlashTexture : GameObject; static var LifeFlashTextureScript : GUITextureLaunch; LifeFlashTextureScript = LifeFlashTexture.GetComponent("GUITextureLaunch"); var lifeFlashUIVR : GameObject; -var lifeFlashUIRenderer : Renderer; -var lifeFlashUIMatl : Material; -var peakLifeFlashValueVR : float = 0.33; +private var lifeFlashUIRenderer : Renderer; +private var lifeFlashUIMatl : Material; +private var peakLifeFlashValueVR : float = 0.7; + +var fallingIntroUIComponent : fallingIntroUI; static var inOutro : boolean = false; @@ -110,6 +112,10 @@ function TickingAway (delay : float) { if (!FallingLaunch.isVRMode) { GetComponent(FallingPlayer).ShowDeathHelp(); + } else if (fallingIntroUIComponent) { + // fallingIntroUIComponent only exists on intro level: + // 'tutorial-vr-intro-2' is the name of the 'gather orbs to survive' icon + fallingIntroUIComponent.ShowIconVR('tutorial-vr-intro-2', 8); } // New GameAnalytics "Design" event syntax: From 428f0330f84c2831ecf2a1e6659b904845bc1a3d Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 8 Nov 2017 00:12:14 -0800 Subject: [PATCH 43/77] Fix VR level-completion next-level loading --- FallingPlayer.js | 3 ++- VRLifeMeter.js | 3 ++- fallingUITest.js | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 6ec39a4..092d1cc 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -202,7 +202,7 @@ function Start() { rb = GetComponent.(); - if (FallingLaunch.isVRMode && levelStartUIVR) { + if (FallingLaunch.isVRMode && levelStartUIVR && FallingLaunch.shouldShowVRIntroUI) { levelStartUIVR.SetActive(true); isAlive = 0; rb.isKinematic = true; @@ -702,6 +702,7 @@ function OnTriggerEnter (other : Collider) { var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - levelStartTime); + // TODO: Send separate event indicating whether you were in VR mode? GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, FallingLaunch.secondsInLevel diff --git a/VRLifeMeter.js b/VRLifeMeter.js index bcc180c..ca5f269 100644 --- a/VRLifeMeter.js +++ b/VRLifeMeter.js @@ -44,11 +44,12 @@ function FadeReticleOut (timer : float) { } function Update () { - // Deactivate this and early return if we're not in VR mode. + // Deactivate the VR reticle and early return if we're not in VR mode. if (!FallingLaunch.isVRMode) { gameObject.SetActive(false); return; } + if (FallingPlayer.isAlive == 1 && isVisible) { lifePercentage = parseFloat(ScoreController.visibleScore)/parseFloat(ScoreController.maxScore); thisImage.fillAmount = lifePercentage; diff --git a/fallingUITest.js b/fallingUITest.js index 32fdf13..12279e9 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -96,6 +96,11 @@ function Start () { // Screen.orientation = ScreenOrientation.LandscapeRight;} // else {Screen.orientation = ScreenOrientation.LandscapeLeft;} + fallingPlayerComponent = player.GetComponent("FallingPlayer"); + //moveControllerComponent = player.GetComponent("MoveController"); + fallingLaunch = GameObject.Find("LaunchGameObject"); + fallingLaunchComponent = fallingLaunch.GetComponent("FallingLaunch"); + // VR mode is incompatible with orthographic cameras, and thus doesn't use UI Toolkit. if (!FallingLaunch.isVRMode) { SetupLevelUI(); @@ -105,11 +110,6 @@ function Start () { } function SetupLevelUI() { - fallingPlayerComponent = player.GetComponent("FallingPlayer"); - //moveControllerComponent = player.GetComponent("MoveController"); - fallingLaunch = GameObject.Find("LaunchGameObject"); - fallingLaunchComponent = fallingLaunch.GetComponent("FallingLaunch"); - bgSprite = UIT.firstToolkit.addSprite( "menuBackground.png", 0, 0, 2 ); bgSprite.positionCenter(); bgSprite.scaleTo( 0.01f, new Vector3( (Screen.width * 6), (Screen.height * 6), 1 ), Easing.Linear.easeIn); From 5badfaa20e92b5ef8a0a4667004849d5949c8697 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 11 Nov 2017 21:21:49 -0800 Subject: [PATCH 44/77] Main camera clip plane manipulation and backdrop camera support in VR --- FallingPlayer.js | 37 ++++---- FallingStartMenu.js | 2 - changeBackdrop.js | 226 +++++++++++++++++++++++++++++++++++--------- setVRMode.js | 2 +- 4 files changed, 205 insertions(+), 62 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 092d1cc..a1d4074 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -8,7 +8,6 @@ private var fallingLaunchComponent : FallingLaunch; // static var startingFogColor : Color = Color(1.17, 1.17, 1.17, 2); static var startingFogEndDistance : int = 1500; static var startingFogStartDistance : int = 150; -static var startingCameraFarClipPlane : int = 1700; static var startingCloudsAlpha : float = .25f; // Unity 4 used .39f (99 in RGBA) //original for corroded sky tubes level @@ -182,17 +181,15 @@ function Start() { } } -// startingFogColor = RenderSettings.fogColor * 2; startingFogEndDistance = RenderSettings.fogEndDistance; - startingFogStartDistance = RenderSettings.fogStartDistance; - - startingCameraFarClipPlane = myMainCamera.farClipPlane; - isAlive = 1; - UIscriptComponent = UIscriptName.GetComponent(fallingUITest); - lifeStartTime = Time.time; - levelStartTime = Time.time; - isExitingLevel = false; - FallingLaunch.thisLevel = Application.loadedLevelName; + startingFogStartDistance = RenderSettings.fogStartDistance; + + isAlive = 1; + UIscriptComponent = UIscriptName.GetComponent(fallingUITest); + lifeStartTime = Time.time; + levelStartTime = Time.time; + isExitingLevel = false; + FallingLaunch.thisLevel = Application.loadedLevelName; FallingLaunch.thisLevelArea = "0-start"; AudioListener.pause = false; myVol = audioScore.volume; @@ -402,17 +399,25 @@ function ShowDeathHelp() { } function changeLevelBackdrop () { - changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; - changeBackdrop.oceanRenderer.enabled = false; - changeBackdrop.cloudRenderer.enabled = false; - changeBackdrop.endSphereRenderer.enabled = false; + if (!FallingLaunch.isVRMode) { + if (changeBackdrop.oceanCameraVR) { + changeBackdrop.oceanCameraVR.GetComponent(Camera).enabled = false; + } + if (changeBackdrop.oceanCamera) { + changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; + changeBackdrop.oceanRenderer.enabled = false; + } + } // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); RenderSettings.fogEndDistance = startingFogEndDistance; RenderSettings.fogStartDistance = startingFogStartDistance; - if (myMainCamera) {myMainCamera.farClipPlane = startingCameraFarClipPlane;} + if (myMainCamera) { + // reset regular or VR cameras' clip planes (handles both cases internally): + changeBackdrop.ResetCameraClipPlane(); + } if (myBackdropRenderer) { myBackdropRenderer.materials = [origMat]; } diff --git a/FallingStartMenu.js b/FallingStartMenu.js index e303342..8f2b58c 100644 --- a/FallingStartMenu.js +++ b/FallingStartMenu.js @@ -124,8 +124,6 @@ function DeathRespawn () { function changeLevelBackdrop () { changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; changeBackdrop.oceanRenderer.enabled = false; - changeBackdrop.cloudRenderer.enabled = false; - changeBackdrop.endSphereRenderer.enabled = false; // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component // Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0); diff --git a/changeBackdrop.js b/changeBackdrop.js index 94d9042..267ae07 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -17,10 +17,18 @@ static var startingCloudAlpha : float; // Unity 4 used .39f (99 in RGBA) var newCloudAlpha : float = .3f; static var cloudOriginalMaterial : Material; -static var oceanCamera : GameObject; -static var oceanRenderer : Renderer; -static var cloudRenderer : Renderer; -static var endSphereRenderer : Renderer; +var oceanCamera : GameObject; +var oceanCameraVR : GameObject; +var oceanCameraVRHead : GvrHead; + +var backdropCamera : GameObject; +private var backdropCameraVRHead : GvrHead; + +var oceanRenderer : Renderer; +var cloudRenderer : Renderer; + +var eyeCamerasVR : Array; +var StereoControllerComponent : Component; //var foo : Material; //set this in the editor //var bar : Material; //set this in the editor @@ -28,6 +36,7 @@ var oceanLevel : boolean = false; var ShouldUseOceanCamera : boolean = false; var ShouldChangeBackdrop : boolean = false; var FogOnly : boolean = false; +var farClipPlaneValueOrig : int; var farClipPlaneValue : int = 2500; var fogEndValue : int = 3000; var farClipPlaneFadeTime : float = 3; @@ -39,24 +48,29 @@ var farClipPlaneFadeTime2 : float = 2; function Start () { if (oceanLevel == true) { if (!mainCamera) {mainCamera = transform.FindChild("Camera").gameObject;} - + oceanCamera = transform.FindChild("Camera-for-ocean").gameObject; - + + var oceanCameraVRTransform : Transform = mainCamera.transform.FindChild("Camera-for-ocean-VR"); + oceanCameraVR = oceanCameraVRTransform ? oceanCameraVRTransform.gameObject : null; + + var backdropCameraTransform : Transform = transform.FindChild("Camera-for-backdrop"); + backdropCamera = backdropCameraTransform ? backdropCameraTransform.gameObject : null; + oceanRenderer = gameObject.Find("sky-water-ocean/Mesh").GetComponent.(); oceanRenderer.enabled = false; cloudRenderer = gameObject.Find("simple-cloud-plane/Mesh").GetComponent.(); cloudRenderer.enabled = false; - - endSphereRenderer = gameObject.Find("score-orbs-end/score-orb/Mesh").GetComponent.(); - endSphereRenderer.enabled = false; } cam = mainCamera.GetComponent.(); + farClipPlaneValueOrig = cam.farClipPlane; + // Warn re. plane-close/Cylinder if they haven't been manually associated via the Inspector: if (ShouldChangeBackdrop || oceanLevel) { - if (!cloudCylinderObj) { + if (!cloudCylinderObj && Debug.isDebugBuild) { Debug.Log('Did you forget to link your cloudCylinderObj in the Inspector?'); } if (cloudCylinderObj) { @@ -72,7 +86,34 @@ function Start () { closePlaneRenderer = closePlaneTransform.GetComponent.(); } } +} + +function Update () { + // Existence check required for StereoControllerComponent in Update() + // since it takes 1+ seconds to set up everything via GVR plugin: + if (FallingLaunch.isVRMode) { + if (mainCamera && !StereoControllerComponent) { + StereoControllerComponent = mainCamera.GetComponent.(); + } + + if (oceanLevel && oceanCameraVR && !oceanCameraVRHead) { + oceanCameraVRHead = oceanCameraVR.GetComponent.().Head; + + // this GvrHead is already nested within the Player camera's + // StereoController, so to stay aligned with its parent, + // it shouldn't independently track rotation: + oceanCameraVRHead.trackRotation = false; + } + if (!backdropCameraVRHead) { + backdropCameraVRHead = backdropCamera.GetComponent.().Head; + + // this GvrHead is already nested within the Player object, + // and the backdrop is meant to be static relative to the player, + // so therefore shouldn't independently track rotation: + backdropCameraVRHead.trackRotation = false; + } + } } function OnTriggerEnter (other : Collider) { @@ -86,14 +127,18 @@ function OnTriggerEnter (other : Collider) { iTween.ColorTo(cloudCylinderObj,{"a": newCloudAlpha, "time": 1}); } -// FadeBetweenCameras (); -// Enable the above method to re-add the fade 2d image backdrop on trigger enter. - // Debug.Log("You hit a changeBackdrop trigger! " + other.gameObject); FadeCameraFarClipPlane (1); if (FogOnly == true) {SmoothFogFade (3);} - if (ShouldUseOceanCamera == true) {enableOceanCamera(); SmoothFogFade (1);} + if (ShouldUseOceanCamera) { + if (FallingLaunch.isVRMode) { + EnableOceanCamera(true); + } else { + EnableOceanCamera(false); + } + SmoothFogFade (1); + } } else if (other.gameObject.CompareTag ("changeBackdrop2")) { @@ -101,7 +146,14 @@ function OnTriggerEnter (other : Collider) { FadeCameraFarClipPlane (2); if (FogOnly == true) {SmoothFogFade (2);} - if (ShouldUseOceanCamera == true) {enableOceanCamera(); SmoothFogFade (2);} + if (ShouldUseOceanCamera) { + if (FallingLaunch.isVRMode) { + EnableOceanCamera(true); + } else { + EnableOceanCamera(false); + } + SmoothFogFade (2); + } } } @@ -118,29 +170,32 @@ function OnTriggerExit (other : Collider) { } } -function changeCameraFadeLayer() { - var cameraFadeObject : GameObject = GameObject.Find ("iTween Camera Fade"); - if (cameraFadeObject) {cameraFadeObject.layer = 4;} -} - +// TODO: Switch iTween clip plane transitions to a regular lerp function FadeCameraFarClipPlane (type : int) { - if (type == 2) { + if (Debug.isDebugBuild) { + Debug.Log("calling FadeCameraFarClipPlane"); + } - iTween.ValueTo ( gameObject, - { - "from" : cam.farClipPlane, - "to" : farClipPlaneValue2, - "onupdate" : "ChangeCameraFarClipPlane", - "time" : farClipPlaneFadeTime2, - "easetype" : "easeInExpo" - }); - } + if (type == 2) { + iTween.ValueTo ( gameObject, + { + "from" : cam.farClipPlane, + "to" : farClipPlaneValue2, + "onstart" : "EnableStereoUpdatesVR", + "onupdate" : "ChangeCameraFarClipPlane", + "oncomplete" : "YieldDisableStereoUpdatesVR", + "time" : farClipPlaneFadeTime2, + "easetype" : "easeInExpo" + }); + } else { iTween.ValueTo ( gameObject, { "from" : cam.farClipPlane, "to" : farClipPlaneValue, + "onstart" : "EnableStereoUpdatesVR", "onupdate" : "ChangeCameraFarClipPlane", + "oncomplete" : "YieldDisableStereoUpdatesVR", "time" : farClipPlaneFadeTime, "easetype" : "easeInExpo" }); @@ -156,7 +211,6 @@ function SmoothFogFade (type : int) { "onupdate" : "ChangeFogEndDistance", "time" : 3, "easetype" : "easeInExpo" - // "oncomplete" : "CameraFadeEnd" }); } else if (type == 2) { iTween.ValueTo ( gameObject, @@ -192,17 +246,38 @@ function SmoothFogFade (type : int) { } } +function ResetCameraClipPlane() { + if (Debug.isDebugBuild) { + Debug.Log("called ResetCameraClipPlane with current clip plane " + cam.farClipPlane); + Debug.Log("...and farClipPlaneValueOrig" + farClipPlaneValueOrig); + } + + // This function gets called on first level load (via LatestCheckpointRespawn), + // so we only want to proceed if the current camera clip value doesn't match + // the specified starting value. This should avoid having more than one iTween lerp + // occurring simultaneously and polluting each other. + // TODO: Switch iTween to regular lerps + if (FallingLaunch.isVRMode && farClipPlaneValueOrig != cam.farClipPlane) { + + if (Debug.isDebugBuild) { + Debug.Log("resetting main VR camera clip plane to " + farClipPlaneValueOrig); + } + + // Set the primary camera's draw distance (far clip plane), + // and enable the keepStereoUpdated boolean on the parent + // stereo controller, so the child eye cameras will update to match. + yield EnableStereoUpdatesVR(); + yield ResetFarClipPlane(); + yield DisableStereoUpdatesVR(); // Then disable `keepStereoUpdated` for performance -function FadeBetweenCameras () { - iTween.CameraFadeAdd(fadeTex); - changeCameraFadeLayer(); - iTween.CameraFadeTo(0.75,.25); - yield WaitForSeconds(.25); - iTween.CameraFadeTo(0.0,3); + } else if (cam && cam.farClipPlane != farClipPlaneValueOrig) { + cam.farClipPlane = farClipPlaneValueOrig; + } } -function CameraFadeEnd () { - iTween.CameraFadeTo(0.0,1); +// this gets yielded so we can be sure the new value is set before proceeding: +function ResetFarClipPlane() : IEnumerator { + cam.farClipPlane = farClipPlaneValueOrig; } function ChangeFogEndDistance (i : int) { @@ -217,9 +292,74 @@ function ChangeCameraFarClipPlane (i : int) { cam.farClipPlane = i; } -function enableOceanCamera () { - oceanCamera.GetComponent(Camera).enabled = true; +function EnableStereoUpdatesVR () { + Debug.Log("called EnableStereoUpdatesVR"); + // Existence check required for StereoControllerComponent since + // it takes 1+ seconds to instantiate via GVR plugin: + if (FallingLaunch.isVRMode && StereoControllerComponent) { + // Type coercion is required... details in setVRMode.Start(): + (StereoControllerComponent as StereoController).keepStereoUpdated = true; + Debug.Log("keepStereoUpdated is true"); + } + yield; +} + +// needed because iTween can't directly call a function that yields; +function YieldDisableStereoUpdatesVR () { + yield DisableStereoUpdatesVR(); +} + +function DisableStereoUpdatesVR () { + // Existence check required for StereoControllerComponent since + // it takes 1+ seconds to instantiate via GVR plugin: + if (FallingLaunch.isVRMode && StereoControllerComponent) { + // Just to make sure the below parent camera alterations + // actually propagate to the relevant stereo cameras: + if ((StereoControllerComponent as StereoController).keepStereoUpdated == false) { + (StereoControllerComponent as StereoController).keepStereoUpdated = true; + } + + eyeCamerasVR = getChildVRCameras(mainCamera); + // Debug.Log('eyeCamerasVR are: ' + eyeCamerasVR); + // Debug.Log("is keepStereoUpdated true ? " + + // (StereoControllerComponent as StereoController).keepStereoUpdated ); + for (var camera : Camera in eyeCamerasVR) { + if (Debug.isDebugBuild) { + Debug.Log("Setting camera " + camera + "'s farClipPlane to " + cam.farClipPlane); + } + camera.farClipPlane = cam.farClipPlane; + } + + // it takes at least one frame for the GVR plugin to update the relevant cameras + // based on the keepStereoUpdated boolean, so this assumes at least 2fps: + + // ...or handle StereoController existence check via a coroutine/callbacks? + yield WaitForSeconds(.5); + // Type coercion is required... details in setVRMode.Start(): + (StereoControllerComponent as StereoController).keepStereoUpdated = false; + } + return; +} + +function EnableOceanCamera (isVR: boolean) { + if (!isVR) { + oceanCamera.GetComponent(Camera).enabled = true; + } + oceanRenderer.enabled = true; - cloudRenderer.enabled = true; - endSphereRenderer.enabled = true; +} + + +function getChildVRCameras(obj : GameObject) : Array{ + var children : Array = new Array(); + for (var child : Transform in obj.transform) { + var eyeCam = child.GetComponent.(); + if (Debug.isDebugBuild) { + Debug.Log("eyeCam is" + eyeCam); + } + if (eyeCam) { + children.Add(eyeCam); + } + } + return children; } \ No newline at end of file diff --git a/setVRMode.js b/setVRMode.js index 1ea9ca1..209a7b0 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -30,7 +30,7 @@ function Start () { cameraVRParent = Instantiate(cameraVRParentPrefab); - // Make the camera-VR-parent object (post-instantiation) a child of this (player) gameObject transform, + // Make the camera-VR-parent object (post-instantiation) a child of this (Player) gameObject transform, // then make the Camera (cameraObj) a child of the camera-VR-parent object: cameraVRParent.transform.SetParent(transform); cameraObj.transform.SetParent(cameraVRParent.transform); From 11a532f85683b114e173d32beeddda9d880c5543 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sun, 12 Nov 2017 16:55:28 -0800 Subject: [PATCH 45/77] VR UI as separate camera, with GvrHead rotation management --- FallingPlayer.js | 10 ++-- ObjectDistanceFade.js | 16 ++++--- changeBackdrop.js | 67 +++++++++++++++++--------- setVRMode.js | 107 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 159 insertions(+), 41 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index a1d4074..66adb72 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -403,10 +403,12 @@ function changeLevelBackdrop () { if (changeBackdrop.oceanCameraVR) { changeBackdrop.oceanCameraVR.GetComponent(Camera).enabled = false; } - if (changeBackdrop.oceanCamera) { - changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; - changeBackdrop.oceanRenderer.enabled = false; - } + } + + // needed even in VR mode, so the ocean renderer disables on respawn: + if (changeBackdrop.oceanCamera) { + changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false; + changeBackdrop.oceanRenderer.enabled = false; } // the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component diff --git a/ObjectDistanceFade.js b/ObjectDistanceFade.js index 8a085bf..e63ca7e 100644 --- a/ObjectDistanceFade.js +++ b/ObjectDistanceFade.js @@ -6,7 +6,7 @@ private var myTransform : Transform = null; private var myRendererMatl : Material; private var dist : Vector3; private var sqrLen : float; -private var sqrRtLen : float; +private var lenToObj : float; function Start () { myTransform = transform; @@ -18,16 +18,20 @@ function OnBecameVisible() { } function OnBecameInvisible() { + if (myRendererMatl) {myRendererMatl.color.a = 0.0;} isEnabled = false; } function Update () { - if (isEnabled == true) { - //var dist = Vector3.Distance(myTransform.position, other.position); + if (isEnabled) { dist = myTransform.position - other.position; sqrLen = dist.sqrMagnitude; - sqrRtLen = Mathf.Sqrt(sqrLen); - if (sqrLen < solidDistance*solidDistance) {sqrRtLen = solidDistance;} - myRendererMatl.color.a = solidDistance / sqrRtLen; + lenToObj = Mathf.Sqrt(sqrLen); + + if (sqrLen < solidDistance*solidDistance) { + lenToObj = solidDistance; + } + + myRendererMatl.color.a = solidDistance / lenToObj; } } \ No newline at end of file diff --git a/changeBackdrop.js b/changeBackdrop.js index 267ae07..5e094f3 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -19,7 +19,7 @@ static var cloudOriginalMaterial : Material; var oceanCamera : GameObject; var oceanCameraVR : GameObject; -var oceanCameraVRHead : GvrHead; +private var oceanCameraVRHead : GvrHead; var backdropCamera : GameObject; private var backdropCameraVRHead : GvrHead; @@ -97,22 +97,44 @@ function Update () { } if (oceanLevel && oceanCameraVR && !oceanCameraVRHead) { - oceanCameraVRHead = oceanCameraVR.GetComponent.().Head; - - // this GvrHead is already nested within the Player camera's - // StereoController, so to stay aligned with its parent, - // it shouldn't independently track rotation: - oceanCameraVRHead.trackRotation = false; + if (oceanCameraVR.GetComponent.()) { + // See note in FallingPlayer.SetupVRUI() for explanation: + // oceanCameraVRHead = oceanCameraVR.GetComponent.().Head; + oceanCameraVRHead = oceanCameraVR.GetComponent.(); + + // this GvrHead is already nested within the Player camera's + // StereoController, so to stay aligned with its parent, + // it shouldn't independently track rotation: + oceanCameraVRHead.trackRotation = false; + } } if (!backdropCameraVRHead) { - backdropCameraVRHead = backdropCamera.GetComponent.().Head; + if (backdropCamera.GetComponent.()) { + backdropCameraVRHead = backdropCamera.GetComponent.(); - // this GvrHead is already nested within the Player object, - // and the backdrop is meant to be static relative to the player, - // so therefore shouldn't independently track rotation: - backdropCameraVRHead.trackRotation = false; + // this GvrHead is already nested within the Player object, + // and the backdrop is meant to be static relative to the player, + // so therefore shouldn't independently track rotation: + backdropCameraVRHead.trackRotation = false; + } } + + // Unfortunately necessary, since any object with a GvrHead could potentially get + // an out-of-whack rotation from player input if trackRotation is ever true (the default), + // which causes dependent stereo cameras to have a rotational offset that needs zeroing. + // To correct for the race condition, we check whether trackRotation ever becomes true: + if (oceanLevel && oceanCameraVR) { + if (oceanCameraVRHead && oceanCameraVRHead.trackRotation) { + if (Debug.isDebugBuild) { + Debug.Log("oceanCameraVRHead.trackRotation value " + oceanCameraVRHead.trackRotation); + Debug.Log("about to reset oceanCameraVR's rotation"); + } + oceanCameraVR.transform.localRotation = Quaternion.identity; + } + } + } else { + return; } } @@ -249,7 +271,7 @@ function SmoothFogFade (type : int) { function ResetCameraClipPlane() { if (Debug.isDebugBuild) { Debug.Log("called ResetCameraClipPlane with current clip plane " + cam.farClipPlane); - Debug.Log("...and farClipPlaneValueOrig" + farClipPlaneValueOrig); + Debug.Log("...and farClipPlaneValueOrig " + farClipPlaneValueOrig); } // This function gets called on first level load (via LatestCheckpointRespawn), @@ -310,6 +332,7 @@ function YieldDisableStereoUpdatesVR () { } function DisableStereoUpdatesVR () { + Debug.Log("DisableStereoUpdatesVR"); // Existence check required for StereoControllerComponent since // it takes 1+ seconds to instantiate via GVR plugin: if (FallingLaunch.isVRMode && StereoControllerComponent) { @@ -319,10 +342,8 @@ function DisableStereoUpdatesVR () { (StereoControllerComponent as StereoController).keepStereoUpdated = true; } - eyeCamerasVR = getChildVRCameras(mainCamera); - // Debug.Log('eyeCamerasVR are: ' + eyeCamerasVR); - // Debug.Log("is keepStereoUpdated true ? " + - // (StereoControllerComponent as StereoController).keepStereoUpdated ); + eyeCamerasVR = getMainChildVRCameras(mainCamera); + for (var camera : Camera in eyeCamerasVR) { if (Debug.isDebugBuild) { Debug.Log("Setting camera " + camera + "'s farClipPlane to " + cam.farClipPlane); @@ -333,7 +354,7 @@ function DisableStereoUpdatesVR () { // it takes at least one frame for the GVR plugin to update the relevant cameras // based on the keepStereoUpdated boolean, so this assumes at least 2fps: - // ...or handle StereoController existence check via a coroutine/callbacks? + // ...or handle StereoController existence check via a coroutine/callback? yield WaitForSeconds(.5); // Type coercion is required... details in setVRMode.Start(): (StereoControllerComponent as StereoController).keepStereoUpdated = false; @@ -350,14 +371,18 @@ function EnableOceanCamera (isVR: boolean) { } -function getChildVRCameras(obj : GameObject) : Array{ +function getMainChildVRCameras(obj : GameObject) : Array{ var children : Array = new Array(); for (var child : Transform in obj.transform) { var eyeCam = child.GetComponent.(); if (Debug.isDebugBuild) { - Debug.Log("eyeCam is" + eyeCam); + Debug.Log("eyeCam is " + eyeCam); + Debug.Log("with name " + child.gameObject.name); } - if (eyeCam) { + if (eyeCam && (child.gameObject.name === 'Camera Left' || child.gameObject.name === 'Camera Right')) { + if (Debug.isDebugBuild) { + Debug.Log("Adding this eyeCam to results: " + eyeCam); + } children.Add(eyeCam); } } diff --git a/setVRMode.js b/setVRMode.js index 209a7b0..8c6e209 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -7,15 +7,36 @@ var cameraVRParentPrefab : GameObject; private var cameraVRParent : GameObject; var cameraObj : GameObject; + private var VRViewerComponent : Component; // var VRViewer : GvrViewer; private var hasCentered : boolean = false; +var VRUICameraObj : GameObject; +var VRUICamera : Camera; +private var VRUICameraVRHead : GvrHead; + +var VRUICameraVRTransform : Transform; +var oceanCameraVRTransform : Transform; + function Awake () { if (!cameraObj) {cameraObj = transform.FindChild("Camera").gameObject;} } function Start () { + + // oceanCameraVRTransform = cameraObj.transform.FindChild("Camera-for-ocean-VR"); + // VRUICameraVRTransform = cameraObj.transform.FindChild("Camera-for-VR-UI"); + + // VR UI Camera lives two levels down from the Player GameObject, + // inside the main parent Camera: + + oceanCameraVRTransform = cameraObj.transform.FindChild("Camera-for-ocean-VR"); + + VRUICameraVRTransform = cameraObj.transform.FindChild("Camera-for-VR-UI"); + VRUICameraObj = VRUICameraVRTransform ? VRUICameraVRTransform.gameObject : null; + VRUICamera = VRUICameraObj.GetComponent.(); + // NOTE: Would be best to perform these lookups elsewhere, but // due to JS/C# interactions and compilation order it's less feasible. // http://answers.unity3d.com/questions/507580/bce0019-enabled-is-not-a-member-of-unityenginecomp-3.html @@ -34,7 +55,20 @@ function Start () { // then make the Camera (cameraObj) a child of the camera-VR-parent object: cameraVRParent.transform.SetParent(transform); cameraObj.transform.SetParent(cameraVRParent.transform); - + + // oceanCameraVR in particular seems to sometimes to adopt skewed rotation. + // (related to whether Player is tilted when the main VR camera object is re-parented?) + // Consider manually forcing it and the UI camera to (0,0,0) post-reparenting, to be safe: + if (oceanCameraVRTransform) { + // Debug.Log("found oceanCameraVRTransform with rotation " + oceanCameraVRTransform.rotation); + oceanCameraVRTransform.localRotation = Quaternion.identity; + } + + if (VRUICameraVRTransform) { + // Debug.Log("found VRUICameraVRTransform with rotation " + VRUICameraVRTransform.rotation); + VRUICameraVRTransform.localRotation = Quaternion.identity; + } + // center cardboard view post-instantiation: // TODO: This recentering needs some kind of rotational offset to account for the parent head's 90-degree (we want to map 'forward' in cardboard to 'down' in world space) // if (!hasCentered) { @@ -52,14 +86,67 @@ function Start () { } function Update () { - if (FallingLaunch.isVRMode && VRViewerComponent) { - // See note in Start() about unfortunate-but-required type coercion: - if ( (VRViewerComponent as GvrViewer).BackButtonPressed ) { - // When Cardboard SDK close icon / back button tapped, return home: - FallingPlayer.isPausable = false; - FallingLaunch.isVRMode = false; - FallingPlayer.UIscriptComponent.SaveCheckpointVR(); - FallingPlayer.UIscriptComponent.LoadHomeNow(); - } + MaintainVRUI(); + // Early return if not in VR mode: + // if (!FallingLaunch.isVRMode) { + // return; + // } else + if (FallingLaunch.isVRMode) { + if (VRViewerComponent) { + // See note in Start() about unfortunate-but-required type coercion: + if ( (VRViewerComponent as GvrViewer).BackButtonPressed ) { + // When Cardboard SDK close icon / back button tapped, return home: + FallingPlayer.isPausable = false; + FallingLaunch.isVRMode = false; + FallingPlayer.UIscriptComponent.SaveCheckpointVR(); + FallingPlayer.UIscriptComponent.LoadHomeNow(); + } + } + } + +} + + +function MaintainVRUI () { + // Existence check required for StereoControllerComponent in Update() + // since it takes 1+ seconds to set up everything via GVR plugin: + if (!VRUICameraVRHead && VRUICameraObj && VRUICamera) { + // Early return if we're not in VR mode and we've already disabled the VR UI camera: + if (!FallingLaunch.isVRMode && VRUICamera.enabled == false) { + return; + } + + if (FallingLaunch.isVRMode) { + if (VRUICameraObj.GetComponent.()) { + + // This GvrHead is already nested within the Player object, + // and the UI is meant to be static relative to the player, + // so therefore shouldn't independently track rotation. + + // We use getComponent. instead of the Google plugin's Head getter, + // because the latter is not guaranteed to be located on this component. + // It could be a parent object's GvrHead, since the GvrHeads are applied at runtime + // by GVRViewer, which adds a StereoController to `Camera.allCameras`'s results array. + // Then StereoController executes `AddStereoRig`, which only adds a new GvrHead if a + // component's parent is not presumed to have one. Otherwise, the parent GvrHead is used. + + // If we just set `trackRotation` on StereoController.Head directly, we might be disabling + // the parent (main) camera's ability to track with head movement, which is `no bueno.` + + // Keep VR UI aligned with parent gameObject, in case of drift via GvrHead + // (currently, this gameObj doesn't get its own GvrHead, but the order of assignment + // is nondeterministic, constructed by looping through an array of Camera.allCameras). + // Thus, the below is defensive code in case it does ever get its own GvrHead. + if (Debug.isDebugBuild) { + Debug.Log("Found matching GvrHead for VRUICameraVRHead"); + } + + VRUICameraVRHead = VRUICameraObj.GetComponent.(); + VRUICameraVRHead.trackRotation = false; + } + } else if (!FallingLaunch.isVRMode && VRUICamera.enabled) { + // Disable VR-specific UI camera if we're not in VR mode: + VRUICamera.enabled = false; + } } } \ No newline at end of file From 457a0672712b3ac92badcd8d3e0bdd23567ef482 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sun, 12 Nov 2017 17:27:24 -0800 Subject: [PATCH 46/77] Coroutine to check and fix secondary VR camera GvrHead alignment --- changeBackdrop.js | 113 ++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/changeBackdrop.js b/changeBackdrop.js index 5e094f3..63a4d0e 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -86,6 +86,14 @@ function Start () { closePlaneRenderer = closePlaneTransform.GetComponent.(); } } + + // HACK: A coroutine to check for out-of-alignment sub-camera GvrHeads and fix them + // (Ocean and Backdrop cameras). A more robust solution would be to ensure that + // only one master GvrHead is applied to the scene at all, so we don't have to worry + // about manging its rotation and inherited stereo cameras' values. + if (FallingLaunch.isVRMode) { + CheckAndFixSecondaryVRCameras(1.5); + } } function Update () { @@ -95,47 +103,67 @@ function Update () { if (mainCamera && !StereoControllerComponent) { StereoControllerComponent = mainCamera.GetComponent.(); } + } else { + return; + } +} - if (oceanLevel && oceanCameraVR && !oceanCameraVRHead) { - if (oceanCameraVR.GetComponent.()) { - // See note in FallingPlayer.SetupVRUI() for explanation: - // oceanCameraVRHead = oceanCameraVR.GetComponent.().Head; - oceanCameraVRHead = oceanCameraVR.GetComponent.(); - - // this GvrHead is already nested within the Player camera's - // StereoController, so to stay aligned with its parent, - // it shouldn't independently track rotation: - oceanCameraVRHead.trackRotation = false; - } - } +function CheckAndFixSecondaryVRCameras (interval : float) { + while (true && FallingLaunch.isVRMode) { + yield WaitForSeconds(interval); + MaintainOceanVRCamera(); + MaintainBackdropVRCamera(); + } +} - if (!backdropCameraVRHead) { - if (backdropCamera.GetComponent.()) { - backdropCameraVRHead = backdropCamera.GetComponent.(); +function MaintainBackdropVRCamera () { + if (!backdropCameraVRHead) { + if (backdropCamera.GetComponent.()) { + backdropCameraVRHead = backdropCamera.GetComponent.(); - // this GvrHead is already nested within the Player object, - // and the backdrop is meant to be static relative to the player, - // so therefore shouldn't independently track rotation: - backdropCameraVRHead.trackRotation = false; - } + // this GvrHead is already nested within the Player object, + // and the backdrop is meant to be static relative to the player, + // so therefore shouldn't independently track rotation: + backdropCameraVRHead.trackRotation = false; } + } +} - // Unfortunately necessary, since any object with a GvrHead could potentially get - // an out-of-whack rotation from player input if trackRotation is ever true (the default), - // which causes dependent stereo cameras to have a rotational offset that needs zeroing. - // To correct for the race condition, we check whether trackRotation ever becomes true: - if (oceanLevel && oceanCameraVR) { - if (oceanCameraVRHead && oceanCameraVRHead.trackRotation) { - if (Debug.isDebugBuild) { - Debug.Log("oceanCameraVRHead.trackRotation value " + oceanCameraVRHead.trackRotation); - Debug.Log("about to reset oceanCameraVR's rotation"); - } - oceanCameraVR.transform.localRotation = Quaternion.identity; - } +function MaintainOceanVRCamera () { + if (oceanLevel && oceanCameraVR && !oceanCameraVRHead) { + if (oceanCameraVR.GetComponent.()) { + // See note in FallingPlayer.SetupVRUI() for explanation: + // oceanCameraVRHead = oceanCameraVR.GetComponent.().Head; + oceanCameraVRHead = oceanCameraVR.GetComponent.(); + + // this GvrHead is already nested within the Player camera's + // StereoController, so to stay aligned with its parent, + // it shouldn't independently track rotation: + oceanCameraVRHead.trackRotation = false; } - } else { - return; } + + // Unfortunately necessary, since any object with a GvrHead could potentially get + // an out-of-whack rotation from player input for unknown causes, + // which causes dependent stereo cameras to have a rotational offset that needs zeroing. + // I thought it was caused by trackRotation ever being true (the default) after instantiation, + // but I've caught strange rotations in the Editor without the localRotation conditional + // ever logging as true... due to cached values persisting from GvrHead setup? + + // To correct for the potential race condition, we check whether trackRotation ever becomes true + // or if the ocean camera VR component's rotation is ever non-zero: + if (oceanLevel && oceanCameraVR && oceanCameraVRHead) { + if (oceanCameraVRHead.trackRotation || + oceanCameraVR.transform.localRotation != Quaternion.identity + ) { + if (Debug.isDebugBuild) { + Debug.Log("oceanCameraVRHead.trackRotation value " + oceanCameraVRHead.trackRotation); + Debug.Log("oceanCameraVR.localRotation value " + oceanCameraVR.transform.localRotation); + Debug.Log("about to reset oceanCameraVR's rotation"); + } + oceanCameraVR.transform.localRotation = Quaternion.identity; + } + } } function OnTriggerEnter (other : Collider) { @@ -315,13 +343,17 @@ function ChangeCameraFarClipPlane (i : int) { } function EnableStereoUpdatesVR () { - Debug.Log("called EnableStereoUpdatesVR"); + if (Debug.isDebugBuild) { + Debug.Log("called EnableStereoUpdatesVR"); + } // Existence check required for StereoControllerComponent since // it takes 1+ seconds to instantiate via GVR plugin: if (FallingLaunch.isVRMode && StereoControllerComponent) { // Type coercion is required... details in setVRMode.Start(): (StereoControllerComponent as StereoController).keepStereoUpdated = true; - Debug.Log("keepStereoUpdated is true"); + if (Debug.isDebugBuild) { + Debug.Log("keepStereoUpdated is true"); + } } yield; } @@ -332,7 +364,9 @@ function YieldDisableStereoUpdatesVR () { } function DisableStereoUpdatesVR () { - Debug.Log("DisableStereoUpdatesVR"); + if (Debug.isDebugBuild) { + Debug.Log("DisableStereoUpdatesVR"); + } // Existence check required for StereoControllerComponent since // it takes 1+ seconds to instantiate via GVR plugin: if (FallingLaunch.isVRMode && StereoControllerComponent) { @@ -379,7 +413,10 @@ function getMainChildVRCameras(obj : GameObject) : Array{ Debug.Log("eyeCam is " + eyeCam); Debug.Log("with name " + child.gameObject.name); } - if (eyeCam && (child.gameObject.name === 'Camera Left' || child.gameObject.name === 'Camera Right')) { + + // HACK: Brittle attempt to filter by camera name to include only 'main' child cameras, + // and not those of VR UI, Ocean, or Backdrop cameras. + if (eyeCam && (child.gameObject.name == 'Camera Left' || child.gameObject.name == 'Camera Right')) { if (Debug.isDebugBuild) { Debug.Log("Adding this eyeCam to results: " + eyeCam); } From 7da9681d79bfa88f800e6950ec0f46b88b302936 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sun, 12 Nov 2017 17:52:05 -0800 Subject: [PATCH 47/77] In VR mode, attenuate speedup factor based on controlMultiplier --- MoveController.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MoveController.js b/MoveController.js index 66fd764..f1f3e64 100644 --- a/MoveController.js +++ b/MoveController.js @@ -289,8 +289,9 @@ function FallingSpeed () { // but the attenuated version is easier on the neck to control! // Mutate into a downwards vector that insists on negative y values - // (so you can't fly upwards). - extraForce = Vector3(0, Mathf.Min(extraForce.y, 0.0) * Slowdown, 0); + // (so you can't fly upwards). `controlMultiplier` is used so you + // can't reach max speed (Slowdown) while still lerping control in: + extraForce = Vector3(0, Mathf.Min(extraForce.y, 0.0) * Slowdown * controlMultiplier, 0); } else { extraForce = Vector3.down * Slowdown; From 72ead36a1d5216137bc4dca7534feed83c55941b Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Mon, 13 Nov 2017 00:31:03 -0800 Subject: [PATCH 48/77] VR skybox support, with toggle for regular mode --- FallingPlayer.js | 6 +++-- changeBackdrop.js | 65 ++++++++++++++++++++++++++++++++++++++++------- setVRMode.js | 17 +++++++++++-- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 66adb72..3e7e076 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -423,8 +423,10 @@ function changeLevelBackdrop () { if (myBackdropRenderer) { myBackdropRenderer.materials = [origMat]; } - iTween.ColorTo(BackdropMist,{"a": startingCloudsAlpha,"time": .5}); - } + if (BackdropMist) { + iTween.ColorTo(BackdropMist,{"a": startingCloudsAlpha,"time": .5}); + } +} function Update () { // playerTilt moves camera on device tilt. Enable if not in VR mode: diff --git a/changeBackdrop.js b/changeBackdrop.js index 63a4d0e..560e172 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -21,7 +21,10 @@ var oceanCamera : GameObject; var oceanCameraVR : GameObject; private var oceanCameraVRHead : GvrHead; -var backdropCamera : GameObject; +var backdropCameraObj : GameObject; +var backdropCamera : Camera; + +var backdropCameraVR : GameObject; private var backdropCameraVRHead : GvrHead; var oceanRenderer : Renderer; @@ -54,16 +57,20 @@ function Start () { var oceanCameraVRTransform : Transform = mainCamera.transform.FindChild("Camera-for-ocean-VR"); oceanCameraVR = oceanCameraVRTransform ? oceanCameraVRTransform.gameObject : null; - var backdropCameraTransform : Transform = transform.FindChild("Camera-for-backdrop"); - backdropCamera = backdropCameraTransform ? backdropCameraTransform.gameObject : null; - oceanRenderer = gameObject.Find("sky-water-ocean/Mesh").GetComponent.(); oceanRenderer.enabled = false; cloudRenderer = gameObject.Find("simple-cloud-plane/Mesh").GetComponent.(); cloudRenderer.enabled = false; } - + + var backdropCameraTransform : Transform = transform.FindChild("Camera-for-backdrop"); + backdropCameraObj = backdropCameraTransform ? backdropCameraTransform.gameObject : null; + backdropCamera = backdropCameraObj.GetComponent.(); + + var backdropCameraVRTransform : Transform = mainCamera.transform.FindChild("Camera-for-bg-VR"); + backdropCameraVR = backdropCameraVRTransform ? backdropCameraVRTransform.gameObject : null; + cam = mainCamera.GetComponent.(); farClipPlaneValueOrig = cam.farClipPlane; @@ -92,8 +99,16 @@ function Start () { // only one master GvrHead is applied to the scene at all, so we don't have to worry // about manging its rotation and inherited stereo cameras' values. if (FallingLaunch.isVRMode) { + ClearNonVRBackground(); CheckAndFixSecondaryVRCameras(1.5); + } else { + // if we want to keep the 'legacy' 2D rectangle-based backgrounds... + // SetupNonVRBackground(); } + // For now, try using the same skybox for VR and regular play, although + // (the latter won't benefit from the three-dimensionality yet, + // since the 3D cloud mesh group is a child of the Player object): + ClearNonVRBackground(); } function Update () { @@ -108,7 +123,29 @@ function Update () { } } +function ClearNonVRBackground () { + if (cloudCylinderObj) { + Debug.Log("about to disable cloudCylinderObj " + cloudCylinderObj); + cloudCylinderObj.SetActive(false); + } + if (backdropCameraObj) { + Debug.Log("about to disable backdropCameraObj " + backdropCameraObj); + backdropCameraObj.SetActive(false); + } +} + +function SetupNonVRBackground () { + // backdropCamera starts as disabled, so it shouldn't get a stereoController or GvrHead + // auto-applied (and thus shouldn't need manual checking or rotation-fixing): + if (backdropCamera) {backdropCamera.enabled = true;} + + if (backdropCameraVR) {backdropCameraVR.SetActive(false);} +} + function CheckAndFixSecondaryVRCameras (interval : float) { + MaintainOceanVRCamera(); + MaintainBackdropVRCamera(); + while (true && FallingLaunch.isVRMode) { yield WaitForSeconds(interval); MaintainOceanVRCamera(); @@ -117,16 +154,26 @@ function CheckAndFixSecondaryVRCameras (interval : float) { } function MaintainBackdropVRCamera () { - if (!backdropCameraVRHead) { - if (backdropCamera.GetComponent.()) { - backdropCameraVRHead = backdropCamera.GetComponent.(); + if (!backdropCameraVRHead && backdropCameraVR && backdropCameraVR.GetComponent.()) { + backdropCameraVRHead = backdropCameraVR.GetComponent.(); + } + if (backdropCameraVRHead) { + if (backdropCameraVRHead.trackRotation || + backdropCameraVR.transform.localRotation != Quaternion.identity + ) { + if (Debug.isDebugBuild) { + Debug.Log("backdropCameraVRHead.trackRotation value " + backdropCameraVRHead.trackRotation); + Debug.Log("backdropCameraVR.localRotation value " + backdropCameraVR.transform.localRotation); + Debug.Log("about to reset backdropCameraVR's rotation"); + } // this GvrHead is already nested within the Player object, // and the backdrop is meant to be static relative to the player, // so therefore shouldn't independently track rotation: backdropCameraVRHead.trackRotation = false; + backdropCameraVR.transform.localRotation = Quaternion.identity; } - } + } } function MaintainOceanVRCamera () { diff --git a/setVRMode.js b/setVRMode.js index 8c6e209..e57cc81 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -12,12 +12,15 @@ private var VRViewerComponent : Component; // var VRViewer : GvrViewer; private var hasCentered : boolean = false; +var VRUICameraVRTransform : Transform; +var oceanCameraVRTransform : Transform; + var VRUICameraObj : GameObject; var VRUICamera : Camera; private var VRUICameraVRHead : GvrHead; -var VRUICameraVRTransform : Transform; -var oceanCameraVRTransform : Transform; +var fogColor : Color; +var fogColorVR : Color; function Awake () { if (!cameraObj) {cameraObj = transform.FindChild("Camera").gameObject;} @@ -44,7 +47,17 @@ function Start () { // https://docs.unity3d.com/ScriptReference/Component.GetComponent.html VRViewerComponent = GvrViewerMainObject.GetComponent("GvrViewer"); + fogColor = RenderSettings.fogColor; + if (FallingLaunch.isVRMode && VRViewerComponent) { + + // Clear is the Unity-default color: + if (fogColorVR.ToString() != Color.clear.ToString()) { + Debug.Log('fogColorVR.ToString is ' + fogColorVR.ToString() ); + Debug.Log('Color.clear.ToString is ' + Color.clear.ToString() ); + RenderSettings.fogColor = fogColorVR; + } + (VRViewerComponent as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' (VRViewerComponent as GvrViewer).VRModeEnabled = true; // Re-parent camera for 90deg tilt offset (so player can look forward in VR): From eca31caf318994df389a2d17255c1bab5dcba5c9 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Tue, 14 Nov 2017 00:16:16 -0800 Subject: [PATCH 49/77] Bring VR skybox, with real perspective tilt, to non-VR mode too --- FallingPlayer.js | 9 +++++++-- MoveController.js | 19 ++++++++++++++----- changeBackdrop.js | 19 ++++++++++++------- setVRMode.js | 13 ++++++++----- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 3e7e076..da7eaab 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -108,6 +108,7 @@ var peakVol : float; private var myTransform : Transform; private var myMainCamera : Camera; +private var myMainCameraTransform : Transform; private var myBackdrop : GameObject; private var myBackdropRenderer : Renderer; @@ -135,6 +136,8 @@ function Start() { } myMainCamera = Camera.main; + // Go up one level; this is the Player-cameras container object, which will get rotated on tilt: + myMainCameraTransform = myMainCamera.gameObject.transform.parent; myBackdrop = GameObject.Find("plane-close"); BackdropMist = GameObject.Find("Cylinder"); myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.() : null; @@ -470,8 +473,10 @@ function playerTilt() { tiltAroundX = FallingLaunch.invertVertAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.x * tiltAngle)), -tiltAngle, tiltAngle); var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); - // Dampen towards the target rotation - myTransform.rotation = Quaternion.Lerp(myTransform.rotation, target, + // Dampen towards the target rotation + // Rotating the camera transform, not the Player transform itself, so the 3D clouds + // (which are the child of the Player object) have correct tilt context. + myMainCameraTransform.rotation = Quaternion.Lerp(myMainCameraTransform.rotation, target, Time.deltaTime * smooth); } } diff --git a/MoveController.js b/MoveController.js index f1f3e64..3396de0 100644 --- a/MoveController.js +++ b/MoveController.js @@ -27,8 +27,9 @@ static var speedingUp : int = 1; static var controlMultiplier : float = 1.0; private var controlModifierTotal : float; -var mainCameraObj : GameObject; private var mainCamera : Camera; +var mainCameraObj : GameObject; +var playerCamerasTransform : Transform; private var myHead : GvrHead; var GvrViewerMainObject : GameObject; // In each scene, manually add the GvrViewerMain obj via Inspector @@ -67,12 +68,13 @@ function Start() { if (mainCameraObj) { mainCamera = mainCameraObj.GetComponent.(); - } - else { // if it wasn't set already via the Inspector UI... - mainCameraObj = GameObject.FindWithTag("MainCamera"); + } else { // if it wasn't set already via the Inspector UI... + // mainCameraObj = GameObject.FindWithTag("MainCamera"); mainCamera = Camera.main; + mainCameraObj = Camera.main.gameObject; } + playerCamerasTransform = mainCameraObj.transform.parent; audioSource = mainCamera.GetComponent.(); //Calibrate(); @@ -294,7 +296,14 @@ function FallingSpeed () { extraForce = Vector3(0, Mathf.Min(extraForce.y, 0.0) * Slowdown * controlMultiplier, 0); } else { - extraForce = Vector3.down * Slowdown; + // Debug.Log("playerCamerasTransform.up " + playerCamerasTransform.up); + // Debug.Log("negative playerCamerasTransform.up " + -playerCamerasTransform.up); + // negative because we want to go "down" and not actually "up"; + // this corresponds (more or less) to the non-VR camera tilt at this moment. + extraForce = -playerCamerasTransform.up * Slowdown; + + // Old way (when we could assume this script's transform was already tilted): + // extraForce = Vector3.down * Slowdown; } // Debug.Log('extraForce: ' + extraForce); diff --git a/changeBackdrop.js b/changeBackdrop.js index 560e172..f61da36 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -50,11 +50,16 @@ var farClipPlaneFadeTime2 : float = 2; function Start () { if (oceanLevel == true) { - if (!mainCamera) {mainCamera = transform.FindChild("Camera").gameObject;} + if (!mainCamera) { + mainCamera = Camera.main.gameObject; + // mainCamera = transform.Find("Player-cameras/Camera").gameObject; + } - oceanCamera = transform.FindChild("Camera-for-ocean").gameObject; + oceanCamera = + transform.Find("Player-cameras/Camera-for-ocean") ? + transform.Find("Player-cameras/Camera-for-ocean").gameObject : null; - var oceanCameraVRTransform : Transform = mainCamera.transform.FindChild("Camera-for-ocean-VR"); + var oceanCameraVRTransform : Transform = mainCamera.transform.Find("Camera-for-ocean-VR"); oceanCameraVR = oceanCameraVRTransform ? oceanCameraVRTransform.gameObject : null; oceanRenderer = gameObject.Find("sky-water-ocean/Mesh").GetComponent.(); @@ -64,11 +69,11 @@ function Start () { cloudRenderer.enabled = false; } - var backdropCameraTransform : Transform = transform.FindChild("Camera-for-backdrop"); + var backdropCameraTransform : Transform = transform.Find("Player-cameras/Camera-for-backdrop"); backdropCameraObj = backdropCameraTransform ? backdropCameraTransform.gameObject : null; backdropCamera = backdropCameraObj.GetComponent.(); - var backdropCameraVRTransform : Transform = mainCamera.transform.FindChild("Camera-for-bg-VR"); + var backdropCameraVRTransform : Transform = mainCamera.transform.Find("Camera-for-bg-VR"); backdropCameraVR = backdropCameraVRTransform ? backdropCameraVRTransform.gameObject : null; cam = mainCamera.GetComponent.(); @@ -86,8 +91,8 @@ function Start () { startingCloudAlpha = cloudOriginalMaterial.color.a; // Storing for later use. } - if (!closePlaneTransform) { - closePlaneTransform = transform.Find("plane-close"); + if (!closePlaneTransform && backdropCameraTransform) { + closePlaneTransform = backdropCameraTransform.Find("plane-close"); } if (closePlaneTransform) { closePlaneRenderer = closePlaneTransform.GetComponent.(); diff --git a/setVRMode.js b/setVRMode.js index e57cc81..87c0da2 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -23,20 +23,23 @@ var fogColor : Color; var fogColorVR : Color; function Awake () { - if (!cameraObj) {cameraObj = transform.FindChild("Camera").gameObject;} + if (!cameraObj) { + cameraObj = Camera.main.gameObject; + // cameraObj = transform.Find("Player-cameras/Camera").gameObject; + } } function Start () { - // oceanCameraVRTransform = cameraObj.transform.FindChild("Camera-for-ocean-VR"); - // VRUICameraVRTransform = cameraObj.transform.FindChild("Camera-for-VR-UI"); + // oceanCameraVRTransform = cameraObj.transform.Find("Camera-for-ocean-VR"); + // VRUICameraVRTransform = cameraObj.transform.Find("Camera-for-VR-UI"); // VR UI Camera lives two levels down from the Player GameObject, // inside the main parent Camera: - oceanCameraVRTransform = cameraObj.transform.FindChild("Camera-for-ocean-VR"); + oceanCameraVRTransform = cameraObj.transform.Find("Camera-for-ocean-VR"); - VRUICameraVRTransform = cameraObj.transform.FindChild("Camera-for-VR-UI"); + VRUICameraVRTransform = cameraObj.transform.Find("Camera-for-VR-UI"); VRUICameraObj = VRUICameraVRTransform ? VRUICameraVRTransform.gameObject : null; VRUICamera = VRUICameraObj.GetComponent.(); From 85ca87e4f110db28e3804472cf3dd29610e3731a Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 17 Nov 2017 09:16:26 -0800 Subject: [PATCH 50/77] Fixes for auto-orientation assert crashes in portrait mode, launching VR mode from landscapeRight --- FallingLaunch.js | 55 +++++++++++++++++++++++++++++++++---------- fallingStartMenuUI.js | 27 +++++++++++---------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 23ff5f6..6620102 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -2,7 +2,6 @@ static var flipMultiplier : float = 1.0; static var levelEndSlowdown : float = 0.0; static var alreadyLaunched : boolean = false; -static var hasSetOrientation : boolean = false; static var NewGamePlus : boolean = false; var targetFPS : int = 30; @@ -55,7 +54,7 @@ enum iPads { }; function Awake () { - isVRMode = false; // TODO: Let user pick this via UI + isVRMode = false; // User can override this via start menu UI } function Start () { @@ -190,21 +189,30 @@ function ChangeTilt (toFlat : int) { Calibrate(); } +// Only relevant in non-VR mode. +// In VR mode, we simply set landscapeLeft in all cases to meet the Google Cardboard SDK's expectations. function LockDeviceOrientation (waitTime: float) { cachedScreenOrientation = Screen.orientation; + // Our outer function shouldn't actually get called if in VR mode, but for + // safety, defensively force landscapeLeft and early return in that case... + if (isVRMode) { + LockLandscapeLeftOrientation(isVRMode); + return; + } + // Let the device auto-rotate if necessary: Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = true; Screen.orientation = ScreenOrientation.AutoRotation; // iOS/Unity can give strange/wrong orientation values while screen is mid-rotation - // or close to flat, so we manually add a wait yield. + // or close to flat, so we manually add a wait yield (~1s). yield WaitForSeconds(waitTime); switch (Input.deviceOrientation) { case DeviceOrientation.LandscapeLeft: - LockLandscapeLeftOrientation(); + LockLandscapeLeftOrientation(isVRMode); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeLeft", 0.0); break; @@ -220,8 +228,9 @@ function LockDeviceOrientation (waitTime: float) { break; } - Screen.autorotateToLandscapeLeft = false; - Screen.autorotateToLandscapeRight = false; + // These are handled within each individual LockLandscapeLeft/Right function: + // Screen.autorotateToLandscapeLeft = false; + // Screen.autorotateToLandscapeRight = false; Calibrate(); @@ -246,7 +255,7 @@ function HandleDeviceOrientationMismatch() { Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape left..."); } initialInputDeviceOrientation = Input.deviceOrientation; - LockLandscapeLeftOrientation(); + LockLandscapeLeftOrientation(isVRMode); } else if (initialInputDeviceOrientation == DeviceOrientation.LandscapeRight) { if (Debug.isDebugBuild) { Debug.Log("There's been a cached/current deviceOrientation mismatch. Setting to landscape right..."); @@ -281,16 +290,36 @@ function DefaultToLandscapeLeftOrientation() { if (Debug.isDebugBuild) { Debug.Log("Defaulting to LandscapeLeft, since Screen.orientation / Input.deviceOrientation were not LandscapeRight"); } - LockLandscapeLeftOrientation(); + LockLandscapeLeftOrientation(isVRMode); } } -function LockLandscapeLeftOrientation () { - if (Debug.isDebugBuild) {Debug.Log("Locking LandscapeLeft orientation");} +function LockLandscapeLeftOrientation (isVR : boolean) { + if (Debug.isDebugBuild) {Debug.Log("Locking LandscapeLeft orientation with isVR " + isVR);} + + // if the device is held in landscapeRight already, + // the autorotateToLandscapeRight = false below is not enough + // to force the left-hand orientation needed for VR mode. + if (isVR) { + // We disable all autorotation before forcing the new orientation, to prevent + // UnityViewControllerBaseiOS.mm `UnityShouldAutorotate` assert crashes: + Screen.autorotateToLandscapeLeft = false; + Screen.autorotateToLandscapeRight = false; + Screen.autorotateToPortrait = false; + Screen.autorotateToPortraitUpsideDown = false; + Screen.orientation = ScreenOrientation.LandscapeLeft; + } - Screen.orientation = ScreenOrientation.LandscapeLeft; cachedScreenOrientation = Screen.orientation; + // Further interaction with Screen.autorotate... values will crash + // the app if we've already forced a given Screen.orientation + // (see UnityViewControllerBaseiOS.mm assert note above), so the below + // is for non-VR mode only: + if (!isVR) { + Screen.autorotateToLandscapeRight = false; + } + neutralPosTilted = neutralPosTiltedRegular; neutralPosVertical = neutralPosVerticalRegular; flipMultiplier = 1.0; @@ -299,9 +328,11 @@ function LockLandscapeLeftOrientation () { function LockLandscapeRightOrientation () { if (Debug.isDebugBuild) {Debug.Log("Locking LandscapeRight orientation");} - Screen.orientation = ScreenOrientation.LandscapeRight; + // Screen.orientation = ScreenOrientation.LandscapeRight; cachedScreenOrientation = Screen.orientation; + Screen.autorotateToLandscapeLeft = false; + neutralPosTilted = neutralPosTiltedFlipped; neutralPosVertical = neutralPosVerticalFlipped; flipMultiplier = -1.0; diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 13b69bf..bebd94c 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -110,9 +110,10 @@ function Awake () { function Start () { - // Just to be safe, exclude portrait modes from potential autorotation: - Screen.autorotateToPortrait = false; - Screen.autorotateToPortraitUpsideDown = false; + // // Just to be safe, exclude portrait modes from potential autorotation: + // BUG: Causes crash if device actually is in portrait or portrait upside-down. + // Screen.autorotateToPortrait = false; + // Screen.autorotateToPortraitUpsideDown = false; // We have to use autoRotation here, due to crashes on force-changing Screen.orientation // in conjunction with permitted-via-settings autoRotation @@ -125,7 +126,7 @@ function Start () { // (the edge cases are iPads lying on a flat surface, which could have either screen orientation): // This function waits an [arbitrary] second for iOS's autorotation to settle, then locks it. - // It's not yielded, so it doesn't delay execution of the `hasSetOrientation = true` below. + // It's not yielded, so it doesn't delay execution of the below. if (!FallingLaunch.isVRMode) { fallingLaunchComponent.LockDeviceOrientation(1.0); } @@ -986,17 +987,17 @@ function OpenVRModeMenu() { function LaunchVRMode() { FallingLaunch.isVRMode = true; - // NB: If your phone is tilted a little beyond flat (away from you) on level load, - // then all other game objects will be behind you when you look up: 180deg wrong - // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse - // quaternion in some cases based on Head gaze direction/ gameObj position, - // or in the menu UI, ensure the phone orientation is not flat before - // letting the user load the scene. + // NB: If your phone is tilted a little beyond flat (away from you) on level load, + // then all other game objects will be behind you when you look up: 180deg wrong + // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse + // quaternion in some cases based on Head gaze direction/ gameObj position, + // or in the menu UI, ensure the phone orientation is not flat before + // letting the user load the scene. - // HACK: But as a temporary workaround, force landscape left orientation - // in VR for Cardboard compatibility (Google's SDK also enforces this mode + // HACK: But as a temporary workaround, force landscape left orientation + // in VR for Cardboard compatibility (Google's SDK also enforces this mode // with 'tilt your phone' UI when device is in landscape right): - fallingLaunchComponent.LockLandscapeLeftOrientation(); + fallingLaunchComponent.LockLandscapeLeftOrientation(FallingLaunch.isVRMode); ResumeGame(); } From 7aebcd3554f861cf7b4e912438ace91dcbc74fd1 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 17 Nov 2017 23:12:28 -0800 Subject: [PATCH 51/77] Misc. fixes for outro cinematic --- EndSequence1stPerson.js | 24 +++++++++++++++++++----- EndSequenceTrigger.js | 14 ++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 20e7662..7810d36 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -14,6 +14,7 @@ var MusicBedInterpolated : AudioVolumeInterpolate; var UIscriptEndMenuName : GameObject; var UIscriptEndMenuComponent : FallingEndMenuUI; +var reticleVRUIScript : VRLifeMeter; //var outroShards : GameObject; var outroCompletedOrb : GameObject; @@ -26,15 +27,19 @@ function Start () { 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.(); + } // 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 + // GameAnalytics events for beating the game var isNewGamePlus : String = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); @@ -56,7 +61,13 @@ function PlayOutro () { //PlayerController.SpeedLinesOff(1); yield WaitForSeconds (1); PlayerController.enabled = false; - FallingPlayer.UIscriptComponent.BeginOutroUI(); + + if (FallingLaunch.isVRMode) { + reticleVRUIScript.FadeReticleOut(0.5); + } else { + FallingPlayer.UIscriptComponent.BeginOutroUI(); + } + ScoreController.IncrementScore(35); LerpTowardsDiamond(10); @@ -91,7 +102,10 @@ function PlayOutro () { ScoreController.enabled = true; LifeController.enabled = true; lifeCountdown.inOutro = false; - FallingPlayer.UIscriptComponent.GameCompleteUI(); + if (!FallingLaunch.isVRMode) { + Debug.Log("Please add VR mode ending UI!"); + FallingPlayer.UIscriptComponent.GameCompleteUI(); + } UIscriptEndMenuComponent.ShowEndGameUI(); FadeAudioListener (4); yield WaitForSeconds(1); @@ -187,7 +201,7 @@ function FadeEndMenuLogo(timer:float){ i += step * Time.deltaTime; EndMenuLogoObject.GetComponent.().material.color.a = Mathf.Lerp(start, end, i); yield; - } + } yield WaitForSeconds (timer); } diff --git a/EndSequenceTrigger.js b/EndSequenceTrigger.js index 0a6daaf..b44caed 100644 --- a/EndSequenceTrigger.js +++ b/EndSequenceTrigger.js @@ -1,6 +1,7 @@ #pragma strict var Player : GameObject; +var FallingPlayerScript : FallingPlayer; var EndScriptComponent : EndSequence1stPerson; var shards : Array; @@ -18,6 +19,7 @@ function Awake () { function Start () { audioSource = GetComponent.(); + FallingPlayerScript = Player.GetComponent("FallingPlayer"); } function OnTriggerEnter (other : Collider) { @@ -55,9 +57,13 @@ function getDiamondCenter() { } function SwapDiamonds(timer : float){ - FallingPlayer.ScoreFlashTextureScript.FadeFlash(3.0, FadeDir.Out); - FallingPlayer.UIscriptComponent.OutroDiamondFlash(2); - //yield WaitForSeconds (.2); + if (!FallingLaunch.isVRMode) { + FallingPlayer.ScoreFlashTextureScript.FadeFlash(3.0, FadeDir.Out); + FallingPlayer.UIscriptComponent.OutroDiamondFlash(2); + } else { + FallingPlayerScript.ScoreFlashVR(0.8, FadeDir.Out); + } + endDiamond.active = true; var start = shardColor.color; @@ -68,7 +74,7 @@ function SwapDiamonds(timer : float){ while (i <= 1.0) { i += step * Time.deltaTime; - for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) + for (var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) shard.transform.Find("sky-rock-angled-segment").GetComponent.().material.color = Color.Lerp(start, end, i); yield; From 0d8c2cecc73cccc043f8906f1a199ce397dbfc38 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 00:52:16 -0800 Subject: [PATCH 52/77] Add game end logo in VR mode --- EndSequence1stPerson.js | 36 +++++++++++++++++++++++++++++++++--- EndSequenceTrigger.js | 2 +- FallingPlayer.js | 14 ++++++++++++++ fallingUITest.js | 2 -- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 7810d36..63526df 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -1,10 +1,13 @@ #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; @@ -21,6 +24,7 @@ var outroCompletedOrb : GameObject; var outroCompletionPoint : GameObject; function Start () { + FallingPlayerScript = GetComponent("FallingPlayer"); PlayerController = GetComponent("MoveController"); ScoreController = GetComponent("ScoreController"); LifeController = GetComponent("lifeCountdown"); @@ -62,6 +66,9 @@ function PlayOutro () { yield WaitForSeconds (1); PlayerController.enabled = false; + FallingPlayer.isPausable = false; + Player.transform.GetComponent.().isKinematic = true; + if (FallingLaunch.isVRMode) { reticleVRUIScript.FadeReticleOut(0.5); } else { @@ -103,13 +110,18 @@ function PlayOutro () { LifeController.enabled = true; lifeCountdown.inOutro = false; if (!FallingLaunch.isVRMode) { - Debug.Log("Please add VR mode ending UI!"); FallingPlayer.UIscriptComponent.GameCompleteUI(); + UIscriptEndMenuComponent.ShowEndGameUI(); } - UIscriptEndMenuComponent.ShowEndGameUI(); FadeAudioListener (4); yield WaitForSeconds(1); - FadeEndMenuLogo(3); + + if (FallingLaunch.isVRMode) { + FadeEndMenuLogoVR(3.0); + FallingPlayerScript.WhiteFadeVREndGame(5.0); + } else { + FadeEndMenuLogo(3.0); + } FallingLaunch.NewGamePlus = true; //UIscriptComponent.LevelComplete(); } @@ -188,6 +200,24 @@ function RotateTowardsDiamond (timer : float) { // } +function FadeEndMenuLogoVR(timer:float){ + + EndMenuLogoObjectVR.GetComponent.().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.().material.color.a = Mathf.Lerp(start, end, i); + yield; + } + + yield WaitForSeconds (timer); +} + + function FadeEndMenuLogo(timer:float){ EndMenuLogoCamera.GetComponent(Camera).enabled = true; diff --git a/EndSequenceTrigger.js b/EndSequenceTrigger.js index b44caed..4b0337c 100644 --- a/EndSequenceTrigger.js +++ b/EndSequenceTrigger.js @@ -61,7 +61,7 @@ function SwapDiamonds(timer : float){ FallingPlayer.ScoreFlashTextureScript.FadeFlash(3.0, FadeDir.Out); FallingPlayer.UIscriptComponent.OutroDiamondFlash(2); } else { - FallingPlayerScript.ScoreFlashVR(0.8, FadeDir.Out); + FallingPlayerScript.ScoreFlashVR(3.0, FadeDir.Out); } endDiamond.active = true; diff --git a/FallingPlayer.js b/FallingPlayer.js index da7eaab..ded9754 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -625,6 +625,20 @@ function WhiteFadeVR (timer : float, fadeType : FadeDir) { } } +function WhiteFadeVREndGame (timer : float) { + + var start = 0.0; + var end = 0.66; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + whiteFadeUIVRMatl.color.a = Mathf.Lerp(start, end, i); + yield; + } +} + function OnCollisionEnter (collision : Collision) { // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x); // Screen.sleepTimeout = 0.0f; diff --git a/fallingUITest.js b/fallingUITest.js index 12279e9..1e0be07 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -679,8 +679,6 @@ function LevelComplete(timer1 : float, timer2 : float) { function BeginOutroUI() { FadeOutGUI(); - FallingPlayer.isPausable = false; - player.GetComponent.().isKinematic = true; } // function GameComplete() { From abe06afccb89f5101efcaff75ef5e778572c0ec0 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 13:18:51 -0800 Subject: [PATCH 53/77] At endgame, tap to exit VR mode --- EndSequence1stPerson.js | 2 +- FallingLaunch.js | 1 + FallingPlayer.js | 68 ++++++++++++++++++++++++++++++++--------- lifeCountdown.js | 2 +- setVRMode.js | 9 +++--- 5 files changed, 61 insertions(+), 21 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 63526df..6abfaae 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -122,8 +122,8 @@ function PlayOutro () { } else { FadeEndMenuLogo(3.0); } + FallingLaunch.NewGamePlus = true; - //UIscriptComponent.LevelComplete(); } function LerpTowardsDiamond (timer : float) { diff --git a/FallingLaunch.js b/FallingLaunch.js index 6620102..930ba1e 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -36,6 +36,7 @@ var testFlightToken : String; static var isVRMode : boolean = false; static var shouldShowVRIntroUI : boolean = false; +static var showingVREndGameUI : boolean = false; //GameAnalytics variables static var secondsAlive : float = 0; diff --git a/FallingPlayer.js b/FallingPlayer.js index ded9754..746fb1c 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -77,6 +77,10 @@ var whiteFadeUIVR : GameObject; private var whiteFadeUIVRRenderer : Renderer; private var whiteFadeUIVRMatl : Material; +var whiteFadeEndGameUIVR : GameObject; +private var whiteFadeEndGameUIVRRenderer : Renderer; +private var whiteFadeEndGameUIVRMatl : Material; + var scoreUIVR : GameObject; private var scoreUIVRRenderer : Renderer; private var scoreUIVRMatl : Material; @@ -85,6 +89,10 @@ private var peakScoreFlashValueVR : float = 1.0; var reticleVRUIObj : GameObject; static var reticleVRUIScript : VRLifeMeter; +var endGameUIObjVR : GameObject; +private var endGameUIVRRenderer : Renderer; +private var endGameUIVRMatl : Material; + var clearDestroyedObjects : boolean = false; var whiteFader : FadeInOutAlt; @@ -154,6 +162,12 @@ function Start() { whiteFadeUIVRMatl = whiteFadeUIVRRenderer.material; whiteFadeUIVRMatl.color.a = 0; + if (whiteFadeEndGameUIVR) { + whiteFadeEndGameUIVRRenderer = whiteFadeEndGameUIVR.GetComponent.(); + whiteFadeEndGameUIVRMatl = whiteFadeEndGameUIVRRenderer.material; + whiteFadeEndGameUIVRMatl.color.a = 0; + } + // Hack to have two separate death/fade-to-black sphere objects, // but neither shader does everything. The inverted transparent shader occludes // all physical objects, but the UIToolkit one is needed for covering light halos. @@ -438,24 +452,36 @@ function Update () { } // disable VR mode and return to menu on screen touch while dead: - if (FallingLaunch.isVRMode && isAlive == 0 && deathPauseUIVR.activeInHierarchy && isExitableFromVR) { - for (var i = 0; i < Input.touchCount; ++i) { - if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { - isPausable = false; - FallingLaunch.isVRMode = false; - - UIscriptComponent.SaveCheckpointVR(); - Application.LoadLevel("Falling-scene-menu"); + if (FallingLaunch.isVRMode) { + + if (FallingLaunch.showingVREndGameUI) { + for (var i3 = 0; i3 < Input.touchCount; ++i3) { + if (Input.GetTouch(i3).phase == TouchPhase.Ended && Input.GetTouch(i3).phase != TouchPhase.Canceled) { + Application.LoadLevel("Falling-scene-menu"); + } } } - } - if (FallingLaunch.isVRMode && levelStartUIVR.activeInHierarchy && FallingLaunch.shouldShowVRIntroUI) { - for (var i2 = 0; i2 < Input.touchCount; ++i2) { - if (Input.GetTouch(i2).phase == TouchPhase.Ended && Input.GetTouch(i2).phase != TouchPhase.Canceled) { - ContinueFromLevelStartVR(); + if (isAlive == 0 && deathPauseUIVR.activeInHierarchy && isExitableFromVR) { + for (var i = 0; i < Input.touchCount; ++i) { + if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { + isPausable = false; + FallingLaunch.isVRMode = false; + + UIscriptComponent.SaveCheckpointVR(); + Application.LoadLevel("Falling-scene-menu"); + } } } + + if (levelStartUIVR.activeInHierarchy && FallingLaunch.shouldShowVRIntroUI) { + for (var i2 = 0; i2 < Input.touchCount; ++i2) { + if (Input.GetTouch(i2).phase == TouchPhase.Ended && Input.GetTouch(i2).phase != TouchPhase.Canceled) { + ContinueFromLevelStartVR(); + } + } + } + } //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); @@ -631,12 +657,26 @@ function WhiteFadeVREndGame (timer : float) { var end = 0.66; var i = 0.0; var step = 1.0/timer; + + if (endGameUIObjVR) { + endGameUIObjVR.SetActive(true); + endGameUIVRRenderer = endGameUIObjVR.GetComponent.(); + endGameUIVRMatl = endGameUIVRRenderer.material; + } + + if (whiteFadeEndGameUIVR) { + whiteFadeEndGameUIVR.SetActive(true); + } while (i <= 1.0) { i += step * Time.deltaTime; - whiteFadeUIVRMatl.color.a = Mathf.Lerp(start, end, i); + whiteFadeEndGameUIVRMatl.color.a = Mathf.Lerp(start, end, i); + if (endGameUIVRMatl) {endGameUIVRMatl.color.a = Mathf.Lerp(start, end, i);} yield; } + + // this will allow screen taps to return to the main menu: + FallingLaunch.showingVREndGameUI = true; } function OnCollisionEnter (collision : Collision) { diff --git a/lifeCountdown.js b/lifeCountdown.js index ecb6d84..74e6941 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -145,6 +145,6 @@ function LifeFlashCheck (delay : float, score : int) { LifeFlashTextureScript.FadeFlash(delay, FadeDir.Out); } - yield WaitForSeconds((delay*3)); // stagger the flash timing (compare w/ `delay` above) + yield WaitForSeconds(delay*3); // stagger the flash timing (compare w/ `delay` above) } } \ No newline at end of file diff --git a/setVRMode.js b/setVRMode.js index 87c0da2..7a9cd24 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -102,12 +102,11 @@ function Start () { } function Update () { - MaintainVRUI(); // Early return if not in VR mode: - // if (!FallingLaunch.isVRMode) { - // return; - // } else - if (FallingLaunch.isVRMode) { + if (!FallingLaunch.isVRMode) { + return; + } else if (FallingLaunch.isVRMode) { + MaintainVRUI(); if (VRViewerComponent) { // See note in Start() about unfortunate-but-required type coercion: if ( (VRViewerComponent as GvrViewer).BackButtonPressed ) { From 44144e8b7da05fffb373126a8cb2f33ff8c705b8 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 15:00:09 -0800 Subject: [PATCH 54/77] Use native lerp for fog fade, not iTween --- changeBackdrop.js | 75 ++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/changeBackdrop.js b/changeBackdrop.js index f61da36..014ca34 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -232,7 +232,7 @@ function OnTriggerEnter (other : Collider) { // Debug.Log("You hit a changeBackdrop trigger! " + other.gameObject); FadeCameraFarClipPlane (1); - if (FogOnly == true) {SmoothFogFade (3);} + if (FogOnly) { SmoothFogFade (3); } if (ShouldUseOceanCamera) { if (FallingLaunch.isVRMode) { EnableOceanCamera(true); @@ -247,7 +247,7 @@ function OnTriggerEnter (other : Collider) { // Debug.Log("You hit an alt changeBackdrop trigger!"); FadeCameraFarClipPlane (2); - if (FogOnly == true) {SmoothFogFade (2);} + if (FogOnly) {SmoothFogFade (2);} if (ShouldUseOceanCamera) { if (FallingLaunch.isVRMode) { EnableOceanCamera(true); @@ -306,45 +306,42 @@ function FadeCameraFarClipPlane (type : int) { function SmoothFogFade (type : int) { if (type == 1) { - iTween.ValueTo ( gameObject, - { - "from" : FallingPlayer.startingFogEndDistance, - "to" : fogEndValue, - "onupdate" : "ChangeFogEndDistance", - "time" : 3, - "easetype" : "easeInExpo" - }); + FogLerp(3.0, RenderSettings.fogEndDistance, fogEndValue); } else if (type == 2) { - iTween.ValueTo ( gameObject, - { - "from" : FallingPlayer.startingFogEndDistance, - "to" : fogEndValue2, - "onupdate" : "ChangeFogEndDistance", - "time" : farClipPlaneFadeTime2, - "easetype" : "easeInExpo" - }); + FogLerp(farClipPlaneFadeTime2, RenderSettings.fogStartDistance, fogEndValue2); } else if (type == 3) { // Effectively zeroes out fog via gentler distance dispersal. // Assumes that fogEndValue is large enough that halving it // will still place the fog start far from the camera. var fogStartType3 : float = fogEndValue * .5; - - iTween.ValueTo ( gameObject, - { - "from" : FallingPlayer.startingFogStartDistance, - "to" : fogStartType3, - "onupdate" : "ChangeFogStartDistance", - "time" : 3, - "easetype" : "easeInExpo" - }); - iTween.ValueTo ( gameObject, - { - "from" : FallingPlayer.startingFogEndDistance, - "to" : fogEndValue, - "onupdate" : "ChangeFogEndDistance", - "time" : 3, - "easetype" : "easeInExpo" - }); + + FogLerp(10.0, fogStartType3, fogEndValue); + } +} + +function FogLerp (timer : float, startVal : float, endVal : float) { + var initStart = RenderSettings.fogStartDistance; + var initEnd = RenderSettings.fogEndDistance; + + var start = startVal; + var end = endVal; + var i = 0.0; + var step = 1.0/timer; + + while (i <= 1.0) { + i += step * Time.deltaTime; + var t : float = i*i * (3f - 2f*i); // smoothstep lerp + RenderSettings.fogStartDistance = Mathf.Lerp(initStart, start, t); + RenderSettings.fogEndDistance = Mathf.Lerp(initEnd, end, t); + + // Reset fog if player dies mid-fog-lerp: + if (FallingPlayer.isAlive == 0) { + RenderSettings.fogStartDistance = initStart; + RenderSettings.fogEndDistance = initEnd; + break; + } + + yield; } } @@ -382,14 +379,6 @@ function ResetFarClipPlane() : IEnumerator { cam.farClipPlane = farClipPlaneValueOrig; } -function ChangeFogEndDistance (i : int) { - RenderSettings.fogEndDistance = i; -} - -function ChangeFogStartDistance (i : int) { - RenderSettings.fogStartDistance = i; -} - function ChangeCameraFarClipPlane (i : int) { cam.farClipPlane = i; } From 73e19f1552e5f1603d4ed695e5dada6227b36d3d Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 15:11:06 -0800 Subject: [PATCH 55/77] Resume background audio for level 4 end area ducking --- AudioDuckingRegion.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AudioDuckingRegion.js b/AudioDuckingRegion.js index 67ff86c..7978223 100644 --- a/AudioDuckingRegion.js +++ b/AudioDuckingRegion.js @@ -27,6 +27,9 @@ function OnTriggerExit (other : Collider) { } function lerpDuck (timer : float, endVal : float) { + + if (!StopAudioOnComplete && !audioSource.isPlaying) {audioSource.UnPause();} + var start = audioSource.volume; var end = endVal; var i = 0.0; @@ -39,5 +42,5 @@ function lerpDuck (timer : float, endVal : float) { } yield WaitForSeconds (timer); - if (StopAudioOnComplete) {audioSource.Stop();} + if (StopAudioOnComplete) {audioSource.Pause();} } From 68ca5188ff3983cf81fef4ced7593aa46d13ea05 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 15:36:57 -0800 Subject: [PATCH 56/77] Basic VR mode analytics --- EndSequence1stPerson.js | 2 +- FallingLaunch.js | 11 +++++++++++ FallingPlayer.js | 14 +++++++------- ProjectileDestroy.js | 2 +- fallingStartMenuUI.js | 2 +- fallingUITest.js | 13 +++++++++++-- lifeCountdown.js | 2 +- setVRMode.js | 7 ++++++- 8 files changed, 39 insertions(+), 14 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 6abfaae..66692da 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -48,7 +48,7 @@ function PlayOutro () { FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "GameComplete:" + isNewGamePlus, + "GameComplete:" + FallingLaunch.vrModeAnalyticsString + isNewGamePlus, FallingLaunch.secondsInLevel ); diff --git a/FallingLaunch.js b/FallingLaunch.js index 930ba1e..0450791 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -35,6 +35,7 @@ static var debugMode : boolean = false; // true; var testFlightToken : String; static var isVRMode : boolean = false; +static var vrModeAnalyticsString : String = "nonVRMode:"; static var shouldShowVRIntroUI : boolean = false; static var showingVREndGameUI : boolean = false; @@ -152,6 +153,16 @@ function OnLevelWasLoaded (level : int) { //Debug.Log("my loaded level is... " + Application.loadedLevelName); } +function EnableVRMode () { + isVRMode = true; + vrModeAnalyticsString = "isVRMode:"; +} + +function DisableVRMode () { + isVRMode = false; + vrModeAnalyticsString = "nonVRMode:"; +} + function SetAxesInversion () { if (PlayerPrefs.GetInt("invertHorizAxis", 0) == 1) {invertHorizAxisVal = -1;} else {invertHorizAxisVal = 1;} diff --git a/FallingPlayer.js b/FallingPlayer.js index 746fb1c..fbcd14c 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -466,7 +466,8 @@ function Update () { for (var i = 0; i < Input.touchCount; ++i) { if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { isPausable = false; - FallingLaunch.isVRMode = false; + + fallingLaunchComponent.DisableVRMode(); UIscriptComponent.SaveCheckpointVR(); Application.LoadLevel("Falling-scene-menu"); @@ -699,10 +700,10 @@ function OnCollisionEnter (collision : Collision) { if (audioDeath) {audioDeath.Play();} - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "Death:Collision:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, - FallingLaunch.secondsAlive - ); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "Death:Collision:" + FallingLaunch.vrModeAnalyticsString + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + FallingLaunch.secondsAlive + ); //Debug.Log("you died in the area " + FallingLaunch.thisLevelArea); //Debug.Log("You died in a fatal collision with " + collision.gameObject); @@ -770,9 +771,8 @@ function OnTriggerEnter (other : Collider) { var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - levelStartTime); - // TODO: Send separate event indicating whether you were in VR mode? GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "LevelComplete:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, + "LevelComplete:" + FallingLaunch.vrModeAnalyticsString + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, FallingLaunch.secondsInLevel ); diff --git a/ProjectileDestroy.js b/ProjectileDestroy.js index 5267093..e94cea1 100644 --- a/ProjectileDestroy.js +++ b/ProjectileDestroy.js @@ -16,7 +16,7 @@ function OnCollisionEnter (collision : Collision) { // throw an analytics event! GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "Projectile:Collision:" + ProjectileName, + "Projectile:Collision:" + FallingLaunch.vrModeAnalyticsString + ProjectileName, FallingLaunch.secondsAlive ); diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index bebd94c..8cffb75 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -985,7 +985,7 @@ function OpenVRModeMenu() { } function LaunchVRMode() { - FallingLaunch.isVRMode = true; + fallingLaunchComponent.EnableVRMode(); // NB: If your phone is tilted a little beyond flat (away from you) on level load, // then all other game objects will be behind you when you look up: 180deg wrong diff --git a/fallingUITest.js b/fallingUITest.js index 1e0be07..7984a96 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -105,6 +105,13 @@ function Start () { if (!FallingLaunch.isVRMode) { SetupLevelUI(); } else { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "LevelBegin:" + + FallingLaunch.vrModeAnalyticsString + + SceneManagement.SceneManager.GetActiveScene().name + ":" + + FallingLaunch.thisLevelArea, + FallingLaunch.secondsInLevel + ); return; } } @@ -427,8 +434,10 @@ function SetupLevelUI() { // Loop (); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "LevelBegin:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, - FallingLaunch.secondsInLevel + "LevelBegin:" + FallingLaunch.vrModeAnalyticsString + + SceneManagement.SceneManager.GetActiveScene().name + ":" + + FallingLaunch.thisLevelArea, + FallingLaunch.secondsInLevel ); // Analytics reporting for tilt prefs, and horizontal/vertical axis prefs, respectively: diff --git a/lifeCountdown.js b/lifeCountdown.js index 74e6941..1dc5328 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -104,7 +104,7 @@ function TickingAway (delay : float) { //Debug.Log("You died!"); GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( - "Death:Drained:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, + "Death:Drained:" + FallingLaunch.vrModeAnalyticsString + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive ); diff --git a/setVRMode.js b/setVRMode.js index 7a9cd24..3d5ae12 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -1,5 +1,8 @@ #pragma strict +private var fallingLaunch : GameObject; +private var fallingLaunchComponent : FallingLaunch; + var GvrViewerMainObject : GameObject; // should be a prefab tilted 90 degrees in X axis, so the user faces forward in headset: @@ -30,6 +33,8 @@ function Awake () { } function Start () { + fallingLaunch = GameObject.Find("LaunchGameObject"); + fallingLaunchComponent = fallingLaunch.GetComponent.(); // oceanCameraVRTransform = cameraObj.transform.Find("Camera-for-ocean-VR"); // VRUICameraVRTransform = cameraObj.transform.Find("Camera-for-VR-UI"); @@ -112,7 +117,7 @@ function Update () { if ( (VRViewerComponent as GvrViewer).BackButtonPressed ) { // When Cardboard SDK close icon / back button tapped, return home: FallingPlayer.isPausable = false; - FallingLaunch.isVRMode = false; + fallingLaunchComponent.DisableVRMode(); FallingPlayer.UIscriptComponent.SaveCheckpointVR(); FallingPlayer.UIscriptComponent.LoadHomeNow(); } From 76b27773efcc762ea4b5aa7c488bfaf196982db4 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 15:50:25 -0800 Subject: [PATCH 57/77] Analytics for menus prior to entering VR mode --- fallingStartMenuUI.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 8cffb75..30d0adc 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -975,6 +975,12 @@ function OpenAbout() { function OpenVRModeMenu() { + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + + Screen.orientation, + FallingLaunch.levelAchieved + ); + HideStartMenuElements(); ShowBackButton(); @@ -987,6 +993,12 @@ function OpenVRModeMenu() { function LaunchVRMode() { fallingLaunchComponent.EnableVRMode(); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + "EnteringVRMode:" + FallingLaunch.vrModeAnalyticsString + + Screen.orientation, + FallingLaunch.levelAchieved + ); + // NB: If your phone is tilted a little beyond flat (away from you) on level load, // then all other game objects will be behind you when you look up: 180deg wrong // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse From 4d8d305b18112dafc0d20587e390e0473a46a09a Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 16:55:27 -0800 Subject: [PATCH 58/77] After beating the game in VR mode, resume from level 1 in New Game Plus --- FallingPlayer.js | 3 +++ IntroSequence1stPerson.js | 21 ++++++++++++--------- Respawn.js | 2 +- changeBackdrop.js | 5 +---- fallingStartMenuUI.js | 4 ++++ setVRMode.js | 2 -- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index fbcd14c..abf4664 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -457,6 +457,9 @@ function Update () { if (FallingLaunch.showingVREndGameUI) { for (var i3 = 0; i3 < Input.touchCount; ++i3) { if (Input.GetTouch(i3).phase == TouchPhase.Ended && Input.GetTouch(i3).phase != TouchPhase.Canceled) { + // PlayerPrefs.DeleteKey("LatestCheckpoint"); + // PlayerPrefs.SetString("LatestLevel", "Falling-scene-tutorial"); + FallingLaunch.showingVREndGameUI = false; Application.LoadLevel("Falling-scene-menu"); } } diff --git a/IntroSequence1stPerson.js b/IntroSequence1stPerson.js index 9682777..c2a679c 100644 --- a/IntroSequence1stPerson.js +++ b/IntroSequence1stPerson.js @@ -20,14 +20,6 @@ function Start () { FallingPlayer.UIscriptComponent.HideGUI(); } - for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { - destructible = shard.GetComponent(ProjectileDestroy); - var shardRenderer : Renderer = shard.GetComponent.(); - shardRenderer.enabled = false; - shard.GetComponent.().isKinematic = true; - destructible.enabled = false; - shardColor = shardRenderer.material.color; - } } else if (FallingLaunch.NewGamePlus) { PlayerController.enabled = true; ScoreController.enabled = true; @@ -37,6 +29,17 @@ function Start () { FallingPlayer.UIscriptComponent.UnhideGUI(); } } + + // Disable all shards' self-destruction scripts so they don't vanish + // before the player triggers their fall: + for (var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { + destructible = shard.GetComponent(ProjectileDestroy); + var shardRenderer : Renderer = shard.GetComponent.(); + shardRenderer.enabled = false; + shard.GetComponent.().isKinematic = true; + destructible.enabled = false; + shardColor = shardRenderer.material.color; + } } function EndIntro (playAudio : boolean) { @@ -52,7 +55,7 @@ function EndIntro (playAudio : boolean) { FallingPlayer.reticleVRUIScript.FadeReticleIn(1.5); } - for(var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { + for (var shard : GameObject in GameObject.FindGameObjectsWithTag("Shard")) { destructible = shard.GetComponent(ProjectileDestroy); shard.GetComponent.().isKinematic = false; //yield WaitForSeconds(.25); diff --git a/Respawn.js b/Respawn.js index d76b8c2..807f15d 100644 --- a/Respawn.js +++ b/Respawn.js @@ -71,7 +71,7 @@ function Start() if (PlayerPrefs.HasKey("LatestLevel") && PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) { myCheckpoint = PlayerPrefs.GetString("LatestCheckpoint"); - currentRespawn = GameObject.Find(myCheckpoint).GetComponent(Respawn); + currentRespawn = myCheckpoint ? GameObject.Find(myCheckpoint).GetComponent(Respawn) : initialRespawn; var tempPlayer : GameObject = GameObject.Find("Player"); var tempPlayerComponent : FallingPlayer = tempPlayer.GetComponent("FallingPlayer"); var IntroScriptComponent : IntroSequence1stPerson = tempPlayer.GetComponent("IntroSequence1stPerson"); diff --git a/changeBackdrop.js b/changeBackdrop.js index 014ca34..7787952 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -104,15 +104,12 @@ function Start () { // only one master GvrHead is applied to the scene at all, so we don't have to worry // about manging its rotation and inherited stereo cameras' values. if (FallingLaunch.isVRMode) { - ClearNonVRBackground(); CheckAndFixSecondaryVRCameras(1.5); } else { // if we want to keep the 'legacy' 2D rectangle-based backgrounds... // SetupNonVRBackground(); } - // For now, try using the same skybox for VR and regular play, although - // (the latter won't benefit from the three-dimensionality yet, - // since the 3D cloud mesh group is a child of the Player object): + // For now, try using the same skybox for VR and regular play: ClearNonVRBackground(); } diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 30d0adc..4af5bf8 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -754,6 +754,10 @@ function FadeAudio (timer : float) { } function ResumeGame() { + // This means we just beat the game, and are now continuing via menu: + if (FallingLaunch.NewGamePlus && PlayerPrefs.GetString("LatestLevel") == level4) { + StartLevelLoad(level1); + } if (PlayerPrefs.HasKey("LatestLevel")) { StartLevelLoad(PlayerPrefs.GetString("LatestLevel")); } else if (FallingLaunch.isVRMode) { diff --git a/setVRMode.js b/setVRMode.js index 3d5ae12..37dc32c 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -61,8 +61,6 @@ function Start () { // Clear is the Unity-default color: if (fogColorVR.ToString() != Color.clear.ToString()) { - Debug.Log('fogColorVR.ToString is ' + fogColorVR.ToString() ); - Debug.Log('Color.clear.ToString is ' + Color.clear.ToString() ); RenderSettings.fogColor = fogColorVR; } From cb0d322a90180e0afc0df7cba36feabb55f9f8f6 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 17:50:27 -0800 Subject: [PATCH 59/77] Route all analytics calls through custom wrapper util --- AnalyticsUtil.js | 6 ++++++ EndSequence1stPerson.js | 2 +- FallingLaunch.js | 14 +++++++++----- FallingPlayer.js | 4 ++-- MoveController.js | 2 +- ProjectileDestroy.js | 2 +- fallingStartMenuUI.js | 4 ++-- fallingUITest.js | 24 ++++++++++++------------ lifeCountdown.js | 2 +- 9 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 AnalyticsUtil.js diff --git a/AnalyticsUtil.js b/AnalyticsUtil.js new file mode 100644 index 0000000..7caa6ca --- /dev/null +++ b/AnalyticsUtil.js @@ -0,0 +1,6 @@ +#pragma strict + +function Event (eventString: String, eventArg: float) { + // Debug.Log("Received event " + eventString + " with arg: " + eventArg); + GameAnalyticsSDK.GameAnalytics.NewDesignEvent(eventString, eventArg); +} \ No newline at end of file diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 66692da..3283fdd 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -47,7 +47,7 @@ function PlayOutro () { var isNewGamePlus : String = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "GameComplete:" + FallingLaunch.vrModeAnalyticsString + isNewGamePlus, FallingLaunch.secondsInLevel ); diff --git a/FallingLaunch.js b/FallingLaunch.js index 0450791..9f970fe 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -1,4 +1,7 @@ #pragma strict + +static var Analytics : AnalyticsUtil; + static var flipMultiplier : float = 1.0; static var levelEndSlowdown : float = 0.0; static var alreadyLaunched : boolean = false; @@ -63,6 +66,7 @@ function Start () { // PlayerPrefs.DeleteAll(); if (!alreadyLaunched) { + Analytics = GetComponent.(); // TestFlightUnity.TestFlight.TakeOff( testFlightToken ); if (Debug.isDebugBuild) { @@ -226,17 +230,17 @@ function LockDeviceOrientation (waitTime: float) { case DeviceOrientation.LandscapeLeft: LockLandscapeLeftOrientation(isVRMode); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeLeft", 0.0); + FallingLaunch.Analytics.Event("DeviceOrientationSet:LandscapeLeft", 0.0); break; case DeviceOrientation.LandscapeRight: LockLandscapeRightOrientation(); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:LandscapeRight", 0.0); + FallingLaunch.Analytics.Event("DeviceOrientationSet:LandscapeRight", 0.0); break; default: HandleDeviceOrientationMismatch(); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationCheck:NonLandscape:" + Input.deviceOrientation, 0.0); + FallingLaunch.Analytics.Event("DeviceOrientationCheck:NonLandscape:" + Input.deviceOrientation, 0.0); break; } @@ -257,7 +261,7 @@ function LockDeviceOrientation (waitTime: float) { function HandleDeviceOrientationMismatch() { if (initialInputDeviceOrientation != Input.deviceOrientation) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "DeviceOrientationCheck:CachedAndCurrentMismatch:" + Input.deviceOrientation + ":" + initialInputDeviceOrientation, 0.0 ); @@ -282,7 +286,7 @@ function HandleDeviceOrientationMismatch() { if (Debug.isDebugBuild) { Debug.Log("InitialInputDeviceOrientation and Input.deviceOrientation do match, as " + Input.deviceOrientation); } - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ("DeviceOrientationSet:CachedAndCurrentMatch:" + Input.deviceOrientation, 0.0); + FallingLaunch.Analytics.Event("DeviceOrientationSet:CachedAndCurrentMatch:" + Input.deviceOrientation, 0.0); // But we must choose left or right, ultimately... DefaultToLandscapeLeftOrientation(); diff --git a/FallingPlayer.js b/FallingPlayer.js index abf4664..3aa28a0 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -703,7 +703,7 @@ function OnCollisionEnter (collision : Collision) { if (audioDeath) {audioDeath.Play();} - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "Death:Collision:" + FallingLaunch.vrModeAnalyticsString + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive ); @@ -774,7 +774,7 @@ function OnTriggerEnter (other : Collider) { var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game"; FallingLaunch.secondsInLevel = (Time.time - levelStartTime); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "LevelComplete:" + FallingLaunch.vrModeAnalyticsString + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus, FallingLaunch.secondsInLevel ); diff --git a/MoveController.js b/MoveController.js index 3396de0..17845a4 100644 --- a/MoveController.js +++ b/MoveController.js @@ -237,7 +237,7 @@ function FallingSpeed () { Slowdown = maxSlowdown; speedingUp = 2; speedsUp(); - // GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + // FallingLaunch.Analytics.Event( // "Control:SpeedBoost:Start:" + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, // FallingLaunch.secondsAlive // ); diff --git a/ProjectileDestroy.js b/ProjectileDestroy.js index e94cea1..9f02d95 100644 --- a/ProjectileDestroy.js +++ b/ProjectileDestroy.js @@ -15,7 +15,7 @@ function OnCollisionEnter (collision : Collision) { if (collision.gameObject.CompareTag ("Player")) { // throw an analytics event! - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "Projectile:Collision:" + FallingLaunch.vrModeAnalyticsString + ProjectileName, FallingLaunch.secondsAlive ); diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 4af5bf8..257a276 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -979,7 +979,7 @@ function OpenAbout() { function OpenVRModeMenu() { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + Screen.orientation, FallingLaunch.levelAchieved @@ -997,7 +997,7 @@ function OpenVRModeMenu() { function LaunchVRMode() { fallingLaunchComponent.EnableVRMode(); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "EnteringVRMode:" + FallingLaunch.vrModeAnalyticsString + Screen.orientation, FallingLaunch.levelAchieved diff --git a/fallingUITest.js b/fallingUITest.js index 7984a96..a78b671 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -105,7 +105,7 @@ function Start () { if (!FallingLaunch.isVRMode) { SetupLevelUI(); } else { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "LevelBegin:" + FallingLaunch.vrModeAnalyticsString + SceneManagement.SceneManager.GetActiveScene().name + ":" + @@ -433,7 +433,7 @@ function SetupLevelUI() { animateProgressBar (lifeBar); // Loop (); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "LevelBegin:" + FallingLaunch.vrModeAnalyticsString + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, @@ -442,41 +442,41 @@ function SetupLevelUI() { // Analytics reporting for tilt prefs, and horizontal/vertical axis prefs, respectively: if (FallingLaunch.restPosition == FallingLaunch.neutralPosFlat) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, 0.0 ); } else if (FallingLaunch.restPosition == FallingLaunch.neutralPosVertical) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, 90.0f ); } else { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "TiltPreference:" + SceneManagement.SceneManager.GetActiveScene().name, 45.0f ); } if (FallingLaunch.invertHorizAxisVal == 1) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "AxesPreference:Horizontal:" + SceneManagement.SceneManager.GetActiveScene().name, 1.0f ); } else if (FallingLaunch.invertHorizAxisVal == -1) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "AxesPreference:Horizontal:" + SceneManagement.SceneManager.GetActiveScene().name, -1.0f ); } if (FallingLaunch.invertVertAxisVal == -1) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, -1.0f ); } else if (FallingLaunch.invertVertAxisVal == 1) { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "AxesPreference:Vertical:" + SceneManagement.SceneManager.GetActiveScene().name, 1.0f ); @@ -538,7 +538,7 @@ function PauseGame() { FallingLaunch.secondsInLevel = (Time.time - FallingPlayer.levelStartTime); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "GUI:PauseGame:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel ); @@ -629,7 +629,7 @@ function RestartLevel() { // Camera.main.SendMessage("fadeOut"); //fadeOut(); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "GUI:RestartLevel:" + SceneManagement.SceneManager.GetActiveScene().name + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsInLevel ); @@ -1144,7 +1144,7 @@ function ToggleTiltNeutral () { } function SaveCheckpointVR () { - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "ExitVRMode:" + SceneManagement.SceneManager.GetActiveScene().name, FallingLaunch.secondsInLevel ); diff --git a/lifeCountdown.js b/lifeCountdown.js index 1dc5328..8b1ac0a 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -103,7 +103,7 @@ function TickingAway (delay : float) { //Debug.Log("You died!"); - GameAnalyticsSDK.GameAnalytics.NewDesignEvent ( + FallingLaunch.Analytics.Event( "Death:Drained:" + FallingLaunch.vrModeAnalyticsString + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea, FallingLaunch.secondsAlive ); From fcf22823a2323613b9a6cbbc6aa7c20e641e7bc9 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 21:58:37 -0800 Subject: [PATCH 60/77] Auto-recenter Cardboard view on level start --- setVRMode.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/setVRMode.js b/setVRMode.js index 37dc32c..cabf170 100644 --- a/setVRMode.js +++ b/setVRMode.js @@ -66,6 +66,16 @@ function Start () { (VRViewerComponent as MonoBehaviour).enabled = true; // type coercion required to access 'enabled' (VRViewerComponent as GvrViewer).VRModeEnabled = true; + + // Center Cardboard view post-instantiation, but before calling setParent on + // the main camera to make it the child of the 90-degree-offset prefab, + // since we want to map 'forward' in Cardboard-land to 'down' in world space: + if (!hasCentered) { + var VRViewer = GvrViewerMainObject.GetComponent.(); + VRViewer.Instance.Recenter(); + hasCentered = true; + } + // Re-parent camera for 90deg tilt offset (so player can look forward in VR): cameraVRParent = Instantiate(cameraVRParentPrefab); @@ -88,13 +98,6 @@ function Start () { VRUICameraVRTransform.localRotation = Quaternion.identity; } - // center cardboard view post-instantiation: - // TODO: This recentering needs some kind of rotational offset to account for the parent head's 90-degree (we want to map 'forward' in cardboard to 'down' in world space) - // if (!hasCentered) { - // VRViewer = GvrViewerMainObject.GetComponent.(); - // VRViewer.Instance.Recenter(); - // hasCentered = true; - // } } else if (VRViewerComponent) { (VRViewerComponent as GvrViewer).VRModeEnabled = false; } From ea07c823d9fba5e1114d4c3222022494b314f92e Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 18 Nov 2017 22:20:14 -0800 Subject: [PATCH 61/77] Skybox 'sunrise' swap for level 1 end --- changeBackdrop.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/changeBackdrop.js b/changeBackdrop.js index 7787952..51ec226 100644 --- a/changeBackdrop.js +++ b/changeBackdrop.js @@ -39,6 +39,10 @@ var oceanLevel : boolean = false; var ShouldUseOceanCamera : boolean = false; var ShouldChangeBackdrop : boolean = false; var FogOnly : boolean = false; + +private var origSkybox : Material; +var altSkybox : Material; + var farClipPlaneValueOrig : int; var farClipPlaneValue : int = 2500; var fogEndValue : int = 3000; @@ -69,6 +73,10 @@ function Start () { cloudRenderer.enabled = false; } + if (ShouldChangeBackdrop) { + origSkybox = RenderSettings.skybox; + } + var backdropCameraTransform : Transform = transform.Find("Player-cameras/Camera-for-backdrop"); backdropCameraObj = backdropCameraTransform ? backdropCameraTransform.gameObject : null; backdropCamera = backdropCameraObj.GetComponent.(); @@ -218,6 +226,10 @@ function MaintainOceanVRCamera () { function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("changeBackdrop")) { + if (ShouldChangeBackdrop && altSkybox) { + RenderSettings.skybox = altSkybox; + } + if (ShouldChangeBackdrop && closePlaneRenderer) { closePlaneRenderer.materials = [newMat]; } @@ -267,6 +279,11 @@ function OnTriggerExit (other : Collider) { iTween.ColorTo(cloudCylinderObj,{"a": startingCloudAlpha, "time": .5}); } } + + // Only used by level 1/tutorial ending 'dawn' skybox: + if (other.gameObject.CompareTag ("changeBackdrop") && ShouldChangeBackdrop) { + RenderSettings.skybox = origSkybox; + } } // TODO: Switch iTween clip plane transitions to a regular lerp From 2f296ff0482c98b837c28de14acbf3f5e8da3b71 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Mon, 20 Nov 2017 20:46:40 -0800 Subject: [PATCH 62/77] Start menu VR mode UI tweaks --- FallingLaunch.js | 9 --------- fallingStartMenuUI.js | 8 +++++--- fallingUITest.js | 45 ++++--------------------------------------- 3 files changed, 9 insertions(+), 53 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 9f970fe..4a16ea1 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -148,15 +148,6 @@ function OnApplicationPause(pauseStatus: boolean) { } } -function OnLevelWasLoaded (level : int) { - //loadedLevel = Application.loadedLevelName; -// var loadedLevel : GALevel = new GALevel(); -// GoogleAnalytics.instance.Add(loadedLevel); -// GoogleAnalytics.instance.Dispatch(); - - //Debug.Log("my loaded level is... " + Application.loadedLevelName); -} - function EnableVRMode () { isVRMode = true; vrModeAnalyticsString = "isVRMode:"; diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 257a276..9293a20 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -233,14 +233,16 @@ function Start () { // HACK: reusing existing button sprite as a transparent background // for the "VR Mode" text label (which is not clickable): vrModeButton = UIButton.create("newgame.png", "newgame.png", 0,0); - vrModeButton.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + // vrModeButton.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + vrModeButton.positionFromBottom(.05); vrModeButton.normalTouchOffsets = new UIEdgeOffsets( 40 ); vrModeButton.highlightedTouchOffsets = new UIEdgeOffsets( 40 ); vrModeButton.onTouchUpInside += OpenVRModeMenu; vrModeButton.alphaTo(0.01f, 0.0f, Easing.Sinusoidal.easeOut); - vrModeLabel = boldText.addTextInstance( "VR MODE", 0, 0 ); - vrModeLabel.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + vrModeLabel = boldText.addTextInstance( "TRY VR MODE", 0, 0 ); + // vrModeLabel.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + vrModeLabel.positionFromBottom(.05); vrModeLaunchButton = UIButton.create("startDown.png","startDown.png", 0, 0); vrModeLaunchButton.positionFromCenter(.1, 0); diff --git a/fallingUITest.js b/fallingUITest.js index a78b671..796c00c 100644 --- a/fallingUITest.js +++ b/fallingUITest.js @@ -16,7 +16,6 @@ var lifeBarOutline : UIProgressBar; var lifeBar : UIProgressBar; var lifeBarThreat : UIProgressBar; var rightArrow : UIButton; -var leftArrow : UIButton; var loadNewLevelButton : UIButton; var loadLevelOne : UIButton; var loadLevelTwo : UIButton; @@ -186,12 +185,7 @@ function SetupLevelUI() { rightArrow.positionFromTopRight(buttonScaleFactor,0.2f); rightArrow.onTouchUpInside += PauseGameCheck; - leftArrow = UIButton.create("restart.png","restart.png", 0, 0); - leftArrow.positionFromBottomLeft(.05f, .05f); - leftArrow.onTouchUpInside += RestartLevel; - rightArrow.hidden = true; - leftArrow.hidden = true; BackToPauseMenuButton = UIButton.create("back.png","back.png", 40, 40); BackToPauseMenuButton.positionFromBottomLeft ( .05f, (.05f * screenAspectRatio) ); @@ -559,16 +553,13 @@ function PauseGame() { AudioListener.pause = true; rightArrow.hidden = false; - //leftArrow.hidden = false; if (level2Unlocked) {loadNewLevelButton.hidden = false;} BackToHomeMenuButton.hidden = false; optionsButton.hidden = false; bgSprite.hidden = false; - //DisplayTiltOnPause(); - - //clear any unused stuff in pause menu. - //audio and video should be stopped, so any hiccuping won't be as obvious. + // Clear any unused stuff in pause menu. + // Audio and video should be stopped, so any hiccuping won't be as obvious. Resources.UnloadUnusedAssets(); initialRespawn.SaveCheckpoint(); @@ -590,7 +581,7 @@ function UnPauseGame(resume : boolean) { bgSprite.hidden = true; rightArrow.hidden = true; - leftArrow.hidden = true; + loadNewLevelButton.hidden = true; BackToHomeMenuButton.hidden = true; HideOptionsButton(); @@ -753,7 +744,6 @@ function LevelSelect() { function HidePauseMenuElements() { rightArrow.hidden = true; - leftArrow.hidden = true; pauseButton.hidden = true; optionsButton.hidden = true; loadNewLevelButton.hidden = true; @@ -765,7 +755,6 @@ function ShowBackButton() { } function BackToPauseMenu() { - //leftArrow.hidden = false; rightArrow.hidden = false; pauseButton.hidden = false; @@ -1088,24 +1077,11 @@ function PauseGameNow() { AudioListener.pause = true; rightArrow.hidden = false; - //leftArrow.hidden = false; if (level2Unlocked) {loadNewLevelButton.hidden = false;} bgSprite.hidden = false; optionsButton.hidden = false; - //DisplayTiltOnPause(); } -// function PauseGameBackgroundCheck() { -// if (FallingPlayer.isPausable == true) { -// if (Time.timeScale == 0) { -// UnPauseGame(true); -// } -// else { -// PauseGameNow(); -// } -// } -// } - function setHoldingPauseButtonTrue() { holdingPauseButton = true; } @@ -1150,17 +1126,4 @@ function SaveCheckpointVR () { ); initialRespawn.SaveCheckpoint(); -} - -function DisplayTiltOnPause () { - - if (PlayerPrefs.GetInt("TiltNeutral", 0) == 1) { - angledTiltLabel.hidden = false; - } - else if (PlayerPrefs.GetInt("TiltNeutral", 0) == 2) { - verticalTiltLabel.hidden = false; - } - else { - flatTiltLabel.hidden = false; - } -} +} \ No newline at end of file From b898e51963768b2841d746e0b2a880dceeba22f4 Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Tue, 21 Nov 2017 12:16:26 -0800 Subject: [PATCH 63/77] Add score-dependent near-death ping sounds --- lifeCountdown.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lifeCountdown.js b/lifeCountdown.js index 8b1ac0a..2f6a71c 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -8,6 +8,8 @@ var lifeFlashUIVR : GameObject; private var lifeFlashUIRenderer : Renderer; private var lifeFlashUIMatl : Material; private var peakLifeFlashValueVR : float = 0.7; +var lifeFlashAudioObj : GameObject; +private var lifeFlashAudio : AudioSource; var fallingIntroUIComponent : fallingIntroUI; @@ -28,6 +30,8 @@ function Start () { lifeFlashUIMatl.color.a = 0; } + lifeFlashAudio = lifeFlashAudioObj.GetComponent.(); + maxSlowdownThreshold = MoveController.maxSlowdown - 1; Loop (); Loop2 (); @@ -44,7 +48,7 @@ function Loop () { function Loop2 () { while (true && inOutro == false) { - yield LifeFlashCheck(.2, 5); + yield LifeFlashCheck(.2, ScoreController.maxScore/4.0); } } @@ -57,8 +61,8 @@ function ScoreLerpLoop () { function FadeFlashVR (timer : float, fadeType : FadeDir) { - var start = fadeType == FadeDir.In? 0.0 : peakLifeFlashValueVR; - var end = fadeType == FadeDir.In? peakLifeFlashValueVR : 0.0; + var start = fadeType == FadeDir.In ? 0.0 : peakLifeFlashValueVR; + var end = fadeType == FadeDir.In ? peakLifeFlashValueVR : 0.0; var i = 0.0; var step = 1.0/timer; @@ -81,7 +85,7 @@ function TickingAway (delay : float) { // the UI health bar's lerp would lag behind the actual value, so the player would // appear to die too soon in some cases. if (ScoreController.currentScore > 0 || ScoreController.visibleScore > 0) { - + if (MoveController.Slowdown > maxSlowdownThreshold) { script.DecrementScore(delay); yield WaitForSeconds((delay/4)); // 4x health penalty during player speedup @@ -135,16 +139,29 @@ function LifeFlashCheck (delay : float, score : int) { if (ScoreController.currentScore < score && inOutro == false) { + if (lifeFlashAudio) { + var deathPromixityScore = 1.0 - (ScoreController.currentScore / score); + // Clamp to a min volume of 0.2, max volume of .75; + lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore, 0.2, 0.9); + // lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore, 0.2, 0.75); + // lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore / 1.5, 0.15, 0.75); + } + if (FallingLaunch.isVRMode) { FadeFlashVR(delay, FadeDir.In); + if (lifeFlashAudio) {lifeFlashAudio.Play();} yield WaitForSeconds(delay); FadeFlashVR(delay, FadeDir.Out); } else { LifeFlashTextureScript.FadeFlash(delay, FadeDir.In); + if (lifeFlashAudio) {lifeFlashAudio.Play();} yield WaitForSeconds(delay); LifeFlashTextureScript.FadeFlash(delay, FadeDir.Out); } - yield WaitForSeconds(delay*3); // stagger the flash timing (compare w/ `delay` above) - } -} \ No newline at end of file + // increase the flash frequency as death draws near (compare w/ `delay` above): + yield WaitForSeconds(Mathf.Max(delay*(ScoreController.currentScore / score)*8.0, delay*4.0) ); + } else { + return; + } +} From a8fbb072dcbdcfc89055eb6bc36f35c0dcc8560f Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Tue, 21 Nov 2017 12:28:43 -0800 Subject: [PATCH 64/77] Special-case death drain flashes when in boost mode --- lifeCountdown.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lifeCountdown.js b/lifeCountdown.js index 2f6a71c..0fb4bb2 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -139,12 +139,18 @@ function LifeFlashCheck (delay : float, score : int) { if (ScoreController.currentScore < score && inOutro == false) { + var lowLifeRatio = ScoreController.currentScore / score; + if (lifeFlashAudio) { - var deathPromixityScore = 1.0 - (ScoreController.currentScore / score); - // Clamp to a min volume of 0.2, max volume of .75; - lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore, 0.2, 0.9); - // lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore, 0.2, 0.75); - // lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore / 1.5, 0.15, 0.75); + // if speeding up, use a louder ping volume for audibility, plus a shorter + // yield wait since the health drain is 4x higher: + if (MoveController.Slowdown > maxSlowdownThreshold) { + lifeFlashAudio.volume = 0.9; + } else { + var deathPromixityScore = 1.0 - lowLifeRatio; + // Clamp to a min volume of 0.2, max volume of .9; + lifeFlashAudio.volume = Mathf.Clamp(deathPromixityScore, 0.2, 0.9); + } } if (FallingLaunch.isVRMode) { @@ -160,7 +166,12 @@ function LifeFlashCheck (delay : float, score : int) { } // increase the flash frequency as death draws near (compare w/ `delay` above): - yield WaitForSeconds(Mathf.Max(delay*(ScoreController.currentScore / score)*8.0, delay*4.0) ); + if (MoveController.Slowdown > maxSlowdownThreshold) { + // 4x delay when speeding up due to increased health drain: + yield WaitForSeconds( Mathf.Max(delay*lowLifeRatio*2.0, delay) ); + } else { + yield WaitForSeconds( Mathf.Max(delay*lowLifeRatio*8.0, delay*4.0) ); + } } else { return; } From 15b65ca32df7c1f519e1ada33c8d3f6a0fdc7392 Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Wed, 22 Nov 2017 15:39:05 -0800 Subject: [PATCH 65/77] VR mode death interstitial: tap vs. hold to respawn/return to menu --- FallingLaunch.js | 25 ++----- FallingPlayer.js | 185 ++++++++++++++++++++++++++++++++--------------- VRLifeMeter.js | 42 ++++++++++- 3 files changed, 173 insertions(+), 79 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 4a16ea1..5695078 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -139,15 +139,6 @@ function Start () { //the device around and the accelerometer readings haven't settled yet. } -function OnApplicationPause(pauseStatus: boolean) { - //paused = pauseStatus; - if (pauseStatus) { -// myTimer.Stop(); -// GoogleAnalytics.instance.Add(myTimer); -// GoogleAnalytics.instance.Dispatch(); - } -} - function EnableVRMode () { isVRMode = true; vrModeAnalyticsString = "isVRMode:"; @@ -196,7 +187,7 @@ function ChangeTilt (toFlat : int) { Calibrate(); } -// Only relevant in non-VR mode. +// Only relevant in non-VR mode. // In VR mode, we simply set landscapeLeft in all cases to meet the Google Cardboard SDK's expectations. function LockDeviceOrientation (waitTime: float) { cachedScreenOrientation = Screen.orientation; @@ -238,7 +229,7 @@ function LockDeviceOrientation (waitTime: float) { // These are handled within each individual LockLandscapeLeft/Right function: // Screen.autorotateToLandscapeLeft = false; // Screen.autorotateToLandscapeRight = false; - + Calibrate(); if (Debug.isDebugBuild) { @@ -270,7 +261,7 @@ function HandleDeviceOrientationMismatch() { initialInputDeviceOrientation = Input.deviceOrientation; LockLandscapeRightOrientation(); } else { - DefaultToLandscapeLeftOrientation(); + DefaultToLandscapeLeftOrientation(); } } else { @@ -298,14 +289,14 @@ function DefaultToLandscapeLeftOrientation() { Debug.Log("Defaulting to LandscapeLeft, since Screen.orientation / Input.deviceOrientation were not LandscapeRight"); } LockLandscapeLeftOrientation(isVRMode); - } + } } function LockLandscapeLeftOrientation (isVR : boolean) { if (Debug.isDebugBuild) {Debug.Log("Locking LandscapeLeft orientation with isVR " + isVR);} // if the device is held in landscapeRight already, - // the autorotateToLandscapeRight = false below is not enough + // the autorotateToLandscapeRight = false below is not enough // to force the left-hand orientation needed for VR mode. if (isVR) { // We disable all autorotation before forcing the new orientation, to prevent @@ -319,8 +310,8 @@ function LockLandscapeLeftOrientation (isVR : boolean) { cachedScreenOrientation = Screen.orientation; - // Further interaction with Screen.autorotate... values will crash - // the app if we've already forced a given Screen.orientation + // Further interaction with Screen.autorotate... values will crash + // the app if we've already forced a given Screen.orientation // (see UnityViewControllerBaseiOS.mm assert note above), so the below // is for non-VR mode only: if (!isVR) { @@ -343,4 +334,4 @@ function LockLandscapeRightOrientation () { neutralPosTilted = neutralPosTiltedFlipped; neutralPosVertical = neutralPosVerticalFlipped; flipMultiplier = -1.0; -} \ No newline at end of file +} diff --git a/FallingPlayer.js b/FallingPlayer.js index 3aa28a0..687dec8 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -48,6 +48,8 @@ var tiltAroundX : float; var script : ScoreController; script = GetComponent("ScoreController"); +private var homeLevel : String = "Falling-scene-menu"; + static var isAlive : int = 1; static var lifeStartTime : float = 0; @@ -125,6 +127,10 @@ private var BackdropMist : GameObject; private var myVRViewer : GameObject; +private var holdTime : float = 2.0; // continuous hold time needed to trigger a return-to-menu +private var holdAccumTime : float = 0.0; +private var holdThresholdForShowingLoadingBar : float = 0.5; + var rb : Rigidbody; function Awake() { @@ -225,7 +231,7 @@ function Start() { rb.isKinematic = false; } - // introComponent's existence is a proxy for level 1, + // introComponent's existence is a proxy for level 1, // where we don't want the reticle to be visible yet // (resuming from a level 1 post-intro checkpoint // is handled in Respawn.js (mainRespawnScript): @@ -259,7 +265,7 @@ function introFade() { whiteFader.enabled = false; } -function introNow() { +function introNow() { LatestCheckpointRespawn(); yield WaitForSeconds (3); FallingLaunch.LoadedLatestLevel = false; @@ -283,6 +289,66 @@ function FadeAudio(timer : float, fadeType : FadeDir) { } } +function ShowDeathInterstitialVR() { + rb.isKinematic = true; + isAlive = 0; + + deathPauseUIVR.SetActive(true); + + yield DeathFadeVR(1.0, FadeDir.In); + // yield UIscriptComponent.fadeIn(false); + + // Managing isExitableFromVR gives finer control over the exit UI, + // preventing the player from tapping mid-respawn fadeout. + isExitableFromVR = true; + // yield WaitForSeconds(4); + + while (true && FallingLaunch.isVRMode && isAlive == 0 && Input.touchCount == 0 && + deathPauseUIVR.activeInHierarchy && isExitableFromVR) { + yield WaitForSeconds(4); + if (isAlive == 0 && Input.touchCount == 0 && deathPauseUIVR.activeInHierarchy && + isExitableFromVR) { + // Debug.Log("it's been enough time; auto-respawning"); + RespawnAfterDeathInterstitialVR(); + } + } + + // // Only execute this if it's been four seconds and a respawn is not already underway: + // if (isAlive == 0 && deathPauseUIVR.activeInHierarchy && isExitableFromVR) { + // RespawnAfterDeathInterstitialVR(); + // } +} + +function RespawnAfterDeathInterstitialVR() { + Debug.Log('called RespawnAfterDeathInterstitialVR'); + isExitableFromVR = false; + + yield DeathFadeVR(0.5, FadeDir.Out); + + rb.isKinematic = false; + + // TODO: Fade out material here instead of toggling the whole object outright? + deathPauseUIVR.SetActive(false); + + // resetting score to max here for VR, to avoid the score + // ticking away over the preceding ~4 WaitForSeconds. + script.ResetScore(); + + // In VR mode, we ignore fadeTime in favor of a longer fade-in + // matched to the longer waiting interval below: + FadeAudio(2.0, FadeDir.In); + + DeathFadeVR(1.0, FadeDir.In); + isPausable = true; + + // setting isAlive is order-dependent with lerpControlIn below + // (isAlive = 0 will break its loop): + isAlive = 1; + lerpControlIn(3.0); + + yield WaitForSeconds(1); + reticleVRUIScript.FadeReticleIn(1.5); +} function DeathRespawn () { isPausable = false; @@ -328,47 +394,7 @@ function DeathRespawn () { MoveController.controlMultiplier = 1.0; if (FallingLaunch.isVRMode && deathPauseUIVR && deathFadeUIVR) { - - rb.isKinematic = true; - isAlive = 0; - - deathPauseUIVR.SetActive(true); - - DeathFadeVR(1.0, FadeDir.In); - // yield UIscriptComponent.fadeIn(false); - - // Managing isExitableFromVR gives finer control over the exit UI, - // preventing the player from tapping mid-respawn fadeout. - isExitableFromVR = true; - yield WaitForSeconds(4); - isExitableFromVR = false; - - yield DeathFadeVR(0.5, FadeDir.Out); - - rb.isKinematic = false; - - // TODO: Fade out material here instead of toggling the whole object outright? - deathPauseUIVR.SetActive(false); - - // resetting score to max here for VR, to avoid the score - // ticking away over the preceding ~4 WaitForSeconds. - script.ResetScore(); - - // In VR mode, we ignore fadeTime in favor of a longer fade-in - // matched to the longer waiting interval below: - FadeAudio(2.0, FadeDir.In); - - DeathFadeVR(1.0, FadeDir.In); - isPausable = true; - - // setting isAlive is order-dependent with lerpControlIn below - // (isAlive = 0 will break its loop): - isAlive = 1; - lerpControlIn(3.0); - - yield WaitForSeconds(1); - reticleVRUIScript.FadeReticleIn(1.5); - + ShowDeathInterstitialVR(); } else { FadeAudio(fadeTime, FadeDir.In); lerpControlIn(3.0); @@ -401,7 +427,7 @@ function LatestCheckpointRespawn () { myTransform.position = respawnPosition; // + Vector3.up; FadeAudio(fadeTime, FadeDir.In); - + if (!FallingLaunch.isVRMode) { rb.isKinematic = false; lerpControlIn(3.0); @@ -460,21 +486,60 @@ function Update () { // PlayerPrefs.DeleteKey("LatestCheckpoint"); // PlayerPrefs.SetString("LatestLevel", "Falling-scene-tutorial"); FallingLaunch.showingVREndGameUI = false; - Application.LoadLevel("Falling-scene-menu"); + Application.LoadLevel(homeLevel); } } } - if (isAlive == 0 && deathPauseUIVR.activeInHierarchy && isExitableFromVR) { - for (var i = 0; i < Input.touchCount; ++i) { - if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled) { - isPausable = false; - - fallingLaunchComponent.DisableVRMode(); - - UIscriptComponent.SaveCheckpointVR(); - Application.LoadLevel("Falling-scene-menu"); - } + if (isAlive == 0 && deathPauseUIVR.activeInHierarchy) { //} && isExitableFromVR) { + + if (Input.touchCount > 0) { + // as soon as any fingers are on screen, block the auto-respawning: + isExitableFromVR = false; + + // if (holdAccumTime = 0.0) {reticleVRUIScript.FadeReticleIn(1.5);} + holdAccumTime += Input.GetTouch(0).deltaTime; + + var adjustedHoldAccumTime : float = + Mathf.Max(holdAccumTime - holdThresholdForShowingLoadingBar, 0.0); + + if (adjustedHoldAccumTime > 0.0) { + reticleVRUIScript.UpdateLoadingCircle( + adjustedHoldAccumTime / holdTime + ); + } + + // Long tap (3+ secs): + if (adjustedHoldAccumTime >= holdTime) { + // Debug.Log("long tap with holdAccumTime " + holdAccumTime); + reticleVRUIScript.HideLoadingCircle(); + isPausable = false; + fallingLaunchComponent.DisableVRMode(); + UIscriptComponent.SaveCheckpointVR(); + Application.LoadLevel(homeLevel); + } + + if (Input.GetTouch(0).phase == TouchPhase.Ended) { + reticleVRUIScript.HideLoadingCircle(); + + // Short-ish tap (in practice, under 1.5 seconds): + if (adjustedHoldAccumTime <= holdTime / 4.0) { + // Debug.Log( + // "With adjustedHoldAccumTime " + adjustedHoldAccumTime + + // ", that counts as a short tap; time to respawn!" + // ); + RespawnAfterDeathInterstitialVR(); + } + // else { + // Debug.Log("mid-length tap, so not respawning yet"); + // } + + holdAccumTime = 0; + } + } else { + // Once no fingers are touching, restting this boolean will let the loop + // in ShowDeathInterstitialVR respawn the player after a 4-second delay. + isExitableFromVR = true; } } @@ -485,7 +550,7 @@ function Update () { } } } - + } //Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol); @@ -504,7 +569,7 @@ function playerTilt() { var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); // Dampen towards the target rotation - // Rotating the camera transform, not the Player transform itself, so the 3D clouds + // Rotating the camera transform, not the Player transform itself, so the 3D clouds // (which are the child of the Player object) have correct tilt context. myMainCameraTransform.rotation = Quaternion.Lerp(myMainCameraTransform.rotation, target, Time.deltaTime * smooth); @@ -661,7 +726,7 @@ function WhiteFadeVREndGame (timer : float) { var end = 0.66; var i = 0.0; var step = 1.0/timer; - + if (endGameUIObjVR) { endGameUIObjVR.SetActive(true); endGameUIVRRenderer = endGameUIObjVR.GetComponent.(); @@ -797,8 +862,8 @@ function OnTriggerEnter (other : Collider) { if (FallingLaunch.isVRMode) { WhiteFadeVR(3.0, FadeDir.Out); } - // Handles 2D (non-VR) UI logic in its own conditional, - // plus saves progress, loads the next level, etc. + // Handles 2D (non-VR) UI logic in its own conditional, + // plus saves progress, loads the next level, etc. UIscriptComponent.LevelComplete(3.0, 1.5); } } diff --git a/VRLifeMeter.js b/VRLifeMeter.js index ca5f269..88bedd2 100644 --- a/VRLifeMeter.js +++ b/VRLifeMeter.js @@ -1,6 +1,9 @@ #pragma strict var thisImage : UnityEngine.UI.Image; +var loadingCircleVR : UnityEngine.UI.Image; +var loadingCircleVRObj : GameObject; + // private var thisImageMatl : Material; var fullColor: Color = Color32(255, 255, 255, 165); var emptyColor: Color = Color.red; // Color32(156, 24, 24, 255); @@ -14,6 +17,22 @@ function Awake() { peakOpacity = fullColor.a; } +function Start() { + if ( FallingLaunch.isVRMode && (!loadingCircleVR || !loadingCircleVRObj) ) { + loadingCircleVRObj = GameObject.Find("loading-bar"); + + var loadingObjTransform : Transform = + loadingCircleVRObj ? loadingCircleVRObj.transform : null; + + loadingCircleVR = // loadingCircleVR || + loadingObjTransform ? loadingObjTransform.GetComponent.() : null; + } + + if (FallingLaunch.isVRMode && loadingCircleVR) { + HideLoadingCircle(); + } +} + function FadeReticle(timer : float, fadeType : FadeDir) { var start = fadeType == FadeDir.In ? 0.0 : peakOpacity; @@ -43,13 +62,31 @@ function FadeReticleOut (timer : float) { isVisible = false; } +function UpdateLoadingCircle (value : float) { + if (loadingCircleVRObj && loadingCircleVR) { + if (!loadingCircleVRObj.activeInHierarchy) { + loadingCircleVRObj.SetActive(true); + } + + loadingCircleVR.color.a = 1.0; + loadingCircleVR.fillAmount = value; + } +} + +function HideLoadingCircle () { + if (loadingCircleVRObj && loadingCircleVR) { + loadingCircleVR.color.a = 0; + loadingCircleVRObj.SetActive(false); + } +} + function Update () { // Deactivate the VR reticle and early return if we're not in VR mode. if (!FallingLaunch.isVRMode) { gameObject.SetActive(false); return; } - + if (FallingPlayer.isAlive == 1 && isVisible) { lifePercentage = parseFloat(ScoreController.visibleScore)/parseFloat(ScoreController.maxScore); thisImage.fillAmount = lifePercentage; @@ -59,5 +96,6 @@ function Update () { thisImage.color = Color.Lerp(emptyColor, fullColor, Mathf.Clamp(lifePercentage*2 - .2, 0.0, 1.0) ); } else { thisImage.color.a = 0; + // loadingCircleVR.color.a = 0; } -} \ No newline at end of file +} From 3329ed951df5d587e84a7e26a027a3aa9ba842c9 Mon Sep 17 00:00:00 2001 From: Tyson Kubota Date: Sun, 26 Nov 2017 07:42:02 -0800 Subject: [PATCH 66/77] Only show tilt warning when user hasn't beaten the first level --- fallingStartMenuUI.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 9293a20..d31a172 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -623,9 +623,15 @@ function Update () { if ((canShowStart == true) && (Mathf.Abs(Input.acceleration.x) < .7) && (Mathf.Abs(Input.acceleration.y) < .7)) { CheckTiltAngle(); bgCamera.backgroundColor = bgColor1; - } - else if (canShowStart == true) { - ShowTiltWarning(); + } else if (canShowStart) { + + // Only show tilt warning if it's presumed to be the player's first-ish session + // (Application.loadedLevel == 2 connotes the tutorial level, + // so levelAchieved < 3 means they haven't completed that level): + // TODO: Would it be less annoying to only show this on the first-ever app launch? + if (FallingLaunch.levelAchieved < 3) { + ShowTiltWarning(); + } var duration = 1.0; @@ -982,8 +988,8 @@ function OpenAbout() { function OpenVRModeMenu() { FallingLaunch.Analytics.Event( - "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + - Screen.orientation, + "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + + Screen.orientation, FallingLaunch.levelAchieved ); @@ -1000,8 +1006,8 @@ function LaunchVRMode() { fallingLaunchComponent.EnableVRMode(); FallingLaunch.Analytics.Event( - "EnteringVRMode:" + FallingLaunch.vrModeAnalyticsString + - Screen.orientation, + "EnteringVRMode:" + FallingLaunch.vrModeAnalyticsString + + Screen.orientation, FallingLaunch.levelAchieved ); @@ -1010,9 +1016,9 @@ function LaunchVRMode() { // in the Z direction (e.g. 90 vs -90 (aka 270) degrees). May need to apply an inverse // quaternion in some cases based on Head gaze direction/ gameObj position, // or in the menu UI, ensure the phone orientation is not flat before - // letting the user load the scene. + // letting the user load the scene. - // HACK: But as a temporary workaround, force landscape left orientation + // HACK: But as a temporary workaround, force landscape left orientation // in VR for Cardboard compatibility (Google's SDK also enforces this mode // with 'tilt your phone' UI when device is in landscape right): fallingLaunchComponent.LockLandscapeLeftOrientation(FallingLaunch.isVRMode); From a298df9864f16b6b9612e952e2426a2ca679aba9 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 29 Nov 2017 20:12:21 -0800 Subject: [PATCH 67/77] Fix VR mode long-press exit-to-menu to utilize touch phases --- FallingPlayer.js | 53 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 687dec8..ca64f13 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -127,9 +127,11 @@ private var BackdropMist : GameObject; private var myVRViewer : GameObject; -private var holdTime : float = 2.0; // continuous hold time needed to trigger a return-to-menu +private var holdTime : float = 1.5; // continuous hold time needed to trigger a return-to-menu private var holdAccumTime : float = 0.0; private var holdThresholdForShowingLoadingBar : float = 0.5; +private var touchHoldStartTime : float = 0.0; +private var isTouchingResetUI : boolean = false; var rb : Rigidbody; @@ -304,10 +306,10 @@ function ShowDeathInterstitialVR() { // yield WaitForSeconds(4); while (true && FallingLaunch.isVRMode && isAlive == 0 && Input.touchCount == 0 && - deathPauseUIVR.activeInHierarchy && isExitableFromVR) { + deathPauseUIVR.activeInHierarchy && isExitableFromVR && !isTouchingResetUI) { yield WaitForSeconds(4); if (isAlive == 0 && Input.touchCount == 0 && deathPauseUIVR.activeInHierarchy && - isExitableFromVR) { + isExitableFromVR && !isTouchingResetUI) { // Debug.Log("it's been enough time; auto-respawning"); RespawnAfterDeathInterstitialVR(); } @@ -494,24 +496,38 @@ function Update () { if (isAlive == 0 && deathPauseUIVR.activeInHierarchy) { //} && isExitableFromVR) { if (Input.touchCount > 0) { + // Debug.Log("Starting touchHoldStartTime " + touchHoldStartTime); + // Debug.Log("Time.time " + Time.time); + // as soon as any fingers are on screen, block the auto-respawning: isExitableFromVR = false; - // if (holdAccumTime = 0.0) {reticleVRUIScript.FadeReticleIn(1.5);} - holdAccumTime += Input.GetTouch(0).deltaTime; + if (Input.GetTouch(0).phase == TouchPhase.Began) { + touchHoldStartTime = Time.time; + isTouchingResetUI = true; + } + + // var adjustedHoldAccumTime : float = (touchHoldStartTime < Time.time) ? 0.0 : + var adjustedHoldAccumTime : float = !isTouchingResetUI ? 0.0 : + Mathf.Max(Time.time - touchHoldStartTime - holdThresholdForShowingLoadingBar, 0.0); - var adjustedHoldAccumTime : float = - Mathf.Max(holdAccumTime - holdThresholdForShowingLoadingBar, 0.0); + // holdAccumTime += Input.GetTouch(0).deltaTime; + + // Old way, using accumulated touch time instead of subtractive via Time.time: + // var adjustedHoldAccumTime : float = (touchHoldStartTime < Time.time) ? 0.0 : + // Mathf.Max(holdAccumTime - holdThresholdForShowingLoadingBar, 0.0); if (adjustedHoldAccumTime > 0.0) { + // Debug.Log("Updating loading circle with adjustedHoldAccumTime " + adjustedHoldAccumTime); + // takes care of showing and updating filled 'loading' sprite: reticleVRUIScript.UpdateLoadingCircle( adjustedHoldAccumTime / holdTime ); } - // Long tap (3+ secs): + // Long tap (~2+ secs): if (adjustedHoldAccumTime >= holdTime) { - // Debug.Log("long tap with holdAccumTime " + holdAccumTime); + // Debug.Log("long tap with adjustedHoldAccumTime " + adjustedHoldAccumTime); reticleVRUIScript.HideLoadingCircle(); isPausable = false; fallingLaunchComponent.DisableVRMode(); @@ -522,25 +538,32 @@ function Update () { if (Input.GetTouch(0).phase == TouchPhase.Ended) { reticleVRUIScript.HideLoadingCircle(); - // Short-ish tap (in practice, under 1.5 seconds): - if (adjustedHoldAccumTime <= holdTime / 4.0) { + var actualTouchTime : float = !isTouchingResetUI ? 0.0 : Time.time - touchHoldStartTime; + // Short-ish tap (in practice, under ~.875 seconds): + if (actualTouchTime > 0.0 && adjustedHoldAccumTime <= holdTime / 4.0) { // Debug.Log( // "With adjustedHoldAccumTime " + adjustedHoldAccumTime + // ", that counts as a short tap; time to respawn!" // ); + // Debug.Log( + // "With actualTouchTime " + actualTouchTime + + // ", that counts as a short tap; time to respawn!" + // ); RespawnAfterDeathInterstitialVR(); } - // else { - // Debug.Log("mid-length tap, so not respawning yet"); - // } holdAccumTime = 0; } } else { - // Once no fingers are touching, restting this boolean will let the loop + // holdAccumTime = 0; + isTouchingResetUI = false; + + // Once no fingers are touching, resetting this boolean will let the loop // in ShowDeathInterstitialVR respawn the player after a 4-second delay. isExitableFromVR = true; } + } else { + isTouchingResetUI = false; } if (levelStartUIVR.activeInHierarchy && FallingLaunch.shouldShowVRIntroUI) { From e44388008729d9989d3aa1a55d2a381d88c17920 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 29 Nov 2017 22:48:03 -0800 Subject: [PATCH 68/77] Hide VR entry UI on iPads --- FallingLaunch.js | 7 +++--- fallingStartMenuUI.js | 50 ++++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/FallingLaunch.js b/FallingLaunch.js index 5695078..23b45eb 100644 --- a/FallingLaunch.js +++ b/FallingLaunch.js @@ -100,16 +100,17 @@ function Start () { var screenWidthInInches: float = (Screen.width / screenDPI); var screenHeightInInches: float = (Screen.height / screenDPI); - var hasLargeScreen: boolean = screenDPI > 0 && (screenWidthInInches > 8 && screenHeightInInches > 5); // Debug.Log("Screen DPI: " + screenDPI); // Debug.Log("Screen width in inches: " + screenWidthInInches); // Debug.Log("Screen height in inches: " + screenHeightInInches); - if (iOSGen.ToString().Contains("iPad") || hasLargeScreen) { + // DPI/screen size no longer a good heuristic for tablet vs. phone, so just use the iPad string regex: + // var hasLargeScreen: boolean = screenDPI > 0 && (screenWidthInInches > 8 && screenHeightInInches > 5); + if (iOSGen.ToString().Contains("iPad")) { // Debug.Log("Looks like a tablet!"); isTablet = true; } else { - // Debug.Log("Based on reported screen size, not a tablet..."); + // Debug.Log("Based on device generation name string, not a tablet..."); isTablet = false; } diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index d31a172..ee26a79 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -555,8 +555,11 @@ function ShowStart() { rightArrow.hidden = false; aboutButtonStart.hidden = false; howToButton.hidden = false; - vrModeButton.hidden = false; - vrModeLabel.hidden = false; + + if (!FallingLaunch.isTablet) { + vrModeButton.hidden = false; + vrModeLabel.hidden = false; + } rightArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); leftArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); @@ -732,10 +735,12 @@ function BackToPauseMenu() { text3.hidden = true; openSiteButtonText.hidden = true; - vrModeLaunchButton.hidden = true; - vrExplanatoryText.hidden = true; - vrModeButton.hidden = false; - vrModeLabel.hidden = false; + if (!FallingLaunch.isTablet) { + vrModeLaunchButton.hidden = true; + vrExplanatoryText.hidden = true; + vrModeButton.hidden = false; + vrModeLabel.hidden = false; + } HideOptions(); @@ -986,20 +991,25 @@ function OpenAbout() { } function OpenVRModeMenu() { - - FallingLaunch.Analytics.Event( - "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + - Screen.orientation, - FallingLaunch.levelAchieved - ); - - HideStartMenuElements(); - ShowBackButton(); - - vrExplanatoryText.hidden = false; - vrModeLaunchButton.hidden = false; - vrExplanatoryText.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); - vrModeLaunchButton.alphaFromTo( 1.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeInOut); + // This user shouldn't be able to trigger this OpenVRModeMenu + // function on a tablet, but just to be safe... + if (!FallingLaunch.isTablet) { + FallingLaunch.Analytics.Event( + "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + + Screen.orientation, + FallingLaunch.levelAchieved + ); + + HideStartMenuElements(); + ShowBackButton(); + + vrExplanatoryText.hidden = false; + vrModeLaunchButton.hidden = false; + vrExplanatoryText.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); + vrModeLaunchButton.alphaFromTo( 1.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeInOut); + } else { + return; + } } function LaunchVRMode() { From 033e44f5626137178db63bb1504b537ba98d0452 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Wed, 29 Nov 2017 23:53:49 -0800 Subject: [PATCH 69/77] Fix conditional tilt-warning based on player progress --- fallingStartMenuUI.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index ee26a79..cbe1f42 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -628,22 +628,22 @@ function Update () { bgCamera.backgroundColor = bgColor1; } else if (canShowStart) { - // Only show tilt warning if it's presumed to be the player's first-ish session - // (Application.loadedLevel == 2 connotes the tutorial level, + // Only show tilt warning and lerp to red if it's presumed to be the player's + // first-ish session (Application.loadedLevel == 2 connotes the tutorial level, // so levelAchieved < 3 means they haven't completed that level): // TODO: Would it be less annoying to only show this on the first-ever app launch? if (FallingLaunch.levelAchieved < 3) { ShowTiltWarning(); + bgCamera.backgroundColor = Color.Lerp (bgColor1, bgColor2, 1.0); + } else { + // just show the start menu immediately if the player has made enough progress: + ShowStart(); } - var duration = 1.0; - - bgCamera.backgroundColor = Color.Lerp (bgColor1, bgColor2, 1.0); - - //var t : float = Mathf.Repeat (Time.time, duration) / duration; - - //var t : float = Mathf.PingPong (Time.time, duration) / duration; - //bgCamera.backgroundColor = Color.Lerp (bgColor1, bgColor2, t); + // var duration = 1.0; + // var t : float = Mathf.Repeat (Time.time, duration) / duration; + // var t : float = Mathf.PingPong (Time.time, duration) / duration; + // bgCamera.backgroundColor = Color.Lerp (bgColor1, bgColor2, t); } // Debug.Log ("your input accel y is " + Input.acceleration.y + " and input accel x is " + Input.acceleration.x); From 75fff6a67938598fb984b95582ade1ef09a96ec4 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Fri, 1 Dec 2017 18:17:02 -0800 Subject: [PATCH 70/77] Special VR mode button for larger phones --- fallingStartMenuUI.js | 51 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index cbe1f42..5ebc1e9 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -71,7 +71,6 @@ var isSaving : boolean = false; var openSiteButtonText : UIButton; var vrModeButton : UIButton; -var vrModeLabel : UITextInstance; var vrModeLaunchButton : UIButton; var vrExplanatoryText : UITextInstance; @@ -232,21 +231,25 @@ function Start () { // TODO: Use real VR Mode icon and button sprite here. // HACK: reusing existing button sprite as a transparent background // for the "VR Mode" text label (which is not clickable): - vrModeButton = UIButton.create("newgame.png", "newgame.png", 0,0); + + // When this toggle is based on rendered pixels, only the larger iPhones should pass, + // e.g. the "Plus" lineup (6/7/8+) and iPhone X (https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html): + var vrModeButtonSpriteString : String = Screen.width > 1700 ? "vrModeLarge.png" : "vrMode.png"; + vrModeButton = UIButton.create(vrModeButtonSpriteString, vrModeButtonSpriteString, 0,0); + + // bottom-left corner: // vrModeButton.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); + + // to center: vrModeButton.positionFromBottom(.05); + vrModeButton.normalTouchOffsets = new UIEdgeOffsets( 40 ); vrModeButton.highlightedTouchOffsets = new UIEdgeOffsets( 40 ); vrModeButton.onTouchUpInside += OpenVRModeMenu; - vrModeButton.alphaTo(0.01f, 0.0f, Easing.Sinusoidal.easeOut); - - vrModeLabel = boldText.addTextInstance( "TRY VR MODE", 0, 0 ); - // vrModeLabel.positionFromBottomLeft ( .05, (.05 * screenAspectRatio) ); - vrModeLabel.positionFromBottom(.05); vrModeLaunchButton = UIButton.create("startDown.png","startDown.png", 0, 0); vrModeLaunchButton.positionFromCenter(.1, 0); - // vrModeLaunchButton.positionFromTopRight(buttonScaleFactor,0.2f); + vrModeLaunchButton.onTouchUpInside += LaunchVRMode; vrModeLaunchButton.onTouchDown += fadeInVRLaunchButton; vrModeLaunchButton.onTouchUp += fadeOutVRLaunchButton; @@ -259,7 +262,6 @@ function Start () { vrExplanatoryText.positionFromCenter(-.2, 0); vrModeButton.hidden = true; - vrModeLabel.hidden = true; vrModeLaunchButton.hidden = true; vrExplanatoryText.hidden = true; @@ -558,7 +560,7 @@ function ShowStart() { if (!FallingLaunch.isTablet) { vrModeButton.hidden = false; - vrModeLabel.hidden = false; + vrModeButton.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); } rightArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); @@ -566,9 +568,6 @@ function ShowStart() { aboutButtonStart.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); howToButton.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - // fake button remains transparent: - // vrModeButton.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - vrModeLabel.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); canShowStart = false; //yield FixWrongInitialScreenOrientation(); } @@ -719,6 +718,12 @@ function BackToPauseMenu() { aboutButtonStart.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); howToButton.alphaFromTo( 1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + if (!FallingLaunch.isTablet) { + vrModeLaunchButton.hidden = true; + vrExplanatoryText.hidden = true; + vrModeButton.hidden = false; + } + fadeInPauseMenu(); loadLevelOne.hidden = true; @@ -735,13 +740,6 @@ function BackToPauseMenu() { text3.hidden = true; openSiteButtonText.hidden = true; - if (!FallingLaunch.isTablet) { - vrModeLaunchButton.hidden = true; - vrExplanatoryText.hidden = true; - vrModeButton.hidden = false; - vrModeLabel.hidden = false; - } - HideOptions(); // if (PlayerPrefs.HasKey("LatestLevel")) { @@ -957,8 +955,12 @@ function FadeOutAllStartMenuElements(timer: float) { howToButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); optionsButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); - vrModeLaunchButton.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); - vrExplanatoryText.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); + if (!FallingLaunch.isTablet) { + vrModeButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); + vrModeLaunchButton.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); + vrExplanatoryText.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); + } + yield; } @@ -1155,7 +1157,6 @@ function HideStartMenuElements() { optionsButton.hidden = true; vrModeButton.hidden = true; - vrModeLabel.hidden = true; //angledTiltChooser.hidden = true; //flatTiltChooser.hidden = true; } @@ -1240,6 +1241,10 @@ function fadeInPauseMenu() { leftArrow.alphaFromTo( 0.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeInOut); aboutButtonStart.alphaFromTo( 0.5f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); howToButton.alphaFromTo( 0.5f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + + if (!FallingLaunch.isTablet) { + vrModeButton.alphaFromTo( 0.5f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + } } function downLevel1() { From 28144e144d0b84b6fd6bf1a9ac9fb1e11bcf2c5c Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 11:33:51 -0800 Subject: [PATCH 71/77] Fix about menu item centering --- FallingEndMenuUI.js | 12 ++++-------- fallingStartMenuUI.js | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/FallingEndMenuUI.js b/FallingEndMenuUI.js index 9d97cac..484f085 100644 --- a/FallingEndMenuUI.js +++ b/FallingEndMenuUI.js @@ -79,17 +79,13 @@ function Start () { thinText.wrapMode = UITextLineWrapMode.None; text1 = thinText.addTextInstance( "CREATED BY TYSON KUBOTA", 0, 0 ); - //text1.positionFromTop(.3f); - //text1.positionFromCenter(-.1f,0f); - text1.pixelsFromCenter( -25, 0 ); + text1.pixelsFromCenter( -55, 0 ); text2 = boldText.addTextInstance( "tysonkubota.net/skydrift", 0, 0); - text2.positionCenter(); + text2.pixelsFromCenter( -30, 0 ); - //text3 = thinText.addTextInstance( "Music by Evan Kubota\nTextures: nobiax\nSound effects: freesound.org", 0, 0 ); - text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", - 0, 0, 0.8f, 1, Color.white, UITextAlignMode.Center, UITextVerticalAlignMode.Bottom ); - text3.positionFromBottom(.3f); + text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", 0, 0); + text3.pixelsFromCenter( 45, 0 ); text1.hidden = true; text2.hidden = true; diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 5ebc1e9..5353878 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -216,17 +216,13 @@ function Start () { thinText.wrapMode = UITextLineWrapMode.None; text1 = thinText.addTextInstance( "CREATED BY TYSON KUBOTA", 0, 0 ); - //text1.positionFromTop(.3f); - //text1.positionFromCenter(-.1f,0f); - text1.pixelsFromCenter( -25, 0 ); + text1.pixelsFromCenter( -55, 0 ); text2 = boldText.addTextInstance( "tysonkubota.net/skydrift", 0, 0); - text2.positionCenter(); + text2.pixelsFromCenter( -30, 0 ); - //text3 = thinText.addTextInstance( "Music by Evan Kubota\nTextures: nobiax\nSound effects: freesound.org", 0, 0 ); - text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", - 0, 0, 0.8f, 1, Color.white, UITextAlignMode.Center, UITextVerticalAlignMode.Bottom ); - text3.positionFromBottom(.3f); + text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", 0, 0); + text3.pixelsFromCenter( 45, 0 ); // TODO: Use real VR Mode icon and button sprite here. // HACK: reusing existing button sprite as a transparent background From f74d92389c3bf2acf0245ce3a975b3958290f755 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 12:40:58 -0800 Subject: [PATCH 72/77] Add App Store review link to start menu --- fallingStartMenuUI.js | 69 +++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 5353878..7aedddc 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -56,6 +56,10 @@ var thinText : UIText; var text1 : UITextInstance; var text2 : UITextInstance; var text3 : UITextInstance; + +var appStoreButtonText : UITextInstance; +var appStoreButtonBg : UIButton; + var tiltText1 : UITextInstance; var tiltText2 : UITextInstance; var invertHorizAxisText : UITextInstance; @@ -224,6 +228,28 @@ function Start () { text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", 0, 0); text3.pixelsFromCenter( 45, 0 ); + openSiteButtonText = UIButton.create("tutorialBackground.png","tutorialBackground.png", 40, 40); + openSiteButtonText.positionFromCenter(0,0); + openSiteButtonText.onTouchUpInside += OpenFallingSite; + openSiteButtonText.scaleTo( 0.1f, new Vector3( (Screen.width), 3, 1 ), Easing.Sinusoidal.easeOut); + openSiteButtonText.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); + + appStoreButtonText = boldText.addTextInstance( "WRITE A REVIEW...", 0, 0); + appStoreButtonText.positionFromBottom(.05); + + // A transparent tappable background; chosen for its width: + appStoreButtonBg = UIButton.create("spheresText.png", "spheresText.png", 0,0); + appStoreButtonBg.positionFromBottom(.05); + appStoreButtonBg.onTouchUpInside += OpenAppStorePage; + appStoreButtonBg.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); + + text1.hidden = true; + text2.hidden = true; + text3.hidden = true; + openSiteButtonText.hidden = true; + appStoreButtonText.hidden = true; + appStoreButtonBg.hidden = true; + // TODO: Use real VR Mode icon and button sprite here. // HACK: reusing existing button sprite as a transparent background // for the "VR Mode" text label (which is not clickable): @@ -251,7 +277,7 @@ function Start () { vrModeLaunchButton.onTouchUp += fadeOutVRLaunchButton; var vrExplanatoryString : String = - "VR MODE REQUIRES GOOGLE CARDBOARD.\n\nPRESS PLAY BELOW, THEN PUT ON HEADSET."; + "VR MODE REQUIRES GOOGLE CARDBOARD.\n\nPRESS PLAY BELOW, THEN PLACE IN HEADSET."; vrExplanatoryText = thinText.addTextInstance( vrExplanatoryString, 0, 0); @@ -379,18 +405,6 @@ function Start () { verticalTiltChooser.onTouchUpInside += ToggleTiltNeutral; verticalTiltChooser.hidden = true; - - openSiteButtonText = UIButton.create("tutorialBackground.png","tutorialBackground.png", 40, 40); - openSiteButtonText.positionFromCenter(0,0); - openSiteButtonText.hidden = true; - openSiteButtonText.onTouchUpInside += OpenFallingSite; - openSiteButtonText.scaleTo( 0.1f, new Vector3( (Screen.width), 3, 1 ), Easing.Sinusoidal.easeOut); - openSiteButtonText.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); - - text1.hidden = true; - text2.hidden = true; - text3.hidden = true; - tiltWarning = UIButton.create("tiltwarning.png","tiltwarning.png", 0, 0); tiltWarning.positionFromTop(buttonScaleFactor); @@ -736,6 +750,9 @@ function BackToPauseMenu() { text3.hidden = true; openSiteButtonText.hidden = true; + appStoreButtonBg.hidden = true; + appStoreButtonText.hidden = true; + HideOptions(); // if (PlayerPrefs.HasKey("LatestLevel")) { @@ -978,14 +995,18 @@ function OpenAbout() { HideStartMenuElements(); ShowBackButton(); + + appStoreButtonBg.hidden = false; + appStoreButtonText.hidden = false; openSiteButtonText.hidden = false; text1.hidden = false; text2.hidden = false; text3.hidden = false; - text1.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); - text2.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeOut); - text3.alphaFromTo(1.5f, 0.0f, 0.6f, Easing.Sinusoidal.easeInOut); + text1.alphaFromTo(1.0, 0.0, 0.8, Easing.Sinusoidal.easeOut); + text2.alphaFromTo(1.0, 0.0, 1.0, Easing.Sinusoidal.easeOut); + text3.alphaFromTo(1.5, 0.0, 0.6, Easing.Sinusoidal.easeInOut); + appStoreButtonText.alphaFromTo(3.5, 0.0, 1.0, Easing.Sinusoidal.easeInOut); } function OpenVRModeMenu() { @@ -993,7 +1014,7 @@ function OpenVRModeMenu() { // function on a tablet, but just to be safe... if (!FallingLaunch.isTablet) { FallingLaunch.Analytics.Event( - "OpeningVRModeMenu:" + FallingLaunch.vrModeAnalyticsString + + "VRModeMenuOpen:" + FallingLaunch.vrModeAnalyticsString + Screen.orientation, FallingLaunch.levelAchieved ); @@ -1014,7 +1035,7 @@ function LaunchVRMode() { fallingLaunchComponent.EnableVRMode(); FallingLaunch.Analytics.Event( - "EnteringVRMode:" + FallingLaunch.vrModeAnalyticsString + + "VRModeEnter:" + FallingLaunch.vrModeAnalyticsString + Screen.orientation, FallingLaunch.levelAchieved ); @@ -1183,7 +1204,17 @@ function LoadLevel4ViaStart() { } function OpenFallingSite() { - Application.OpenURL ("http://tysonkubota.net/skydrift?utm_source=skydrift-game&utm_medium=ios&utm_campaign=skydrift-gui"); + var urlToOpen : String = "http://tysonkubota.net/skydrift?utm_source=skydrift-game&utm_medium=ios&utm_campaign=skydrift-gui"; + // use a float instead of an int, as required by the GameAnalytics SDK: + FallingLaunch.Analytics.Event("OpenURL:FallingSite", FallingLaunch.levelAchieved*1.0); + Application.OpenURL(urlToOpen); +} + +function OpenAppStorePage() { + var urlToOpen : String = "https://itunes.apple.com/us/app/skydrift/id728636851?action=write-review&mt=8"; + // use a float instead of an int, as required by the GameAnalytics SDK: + FallingLaunch.Analytics.Event("OpenURL:AppStorePage", FallingLaunch.levelAchieved*1.0); + Application.OpenURL(urlToOpen); } function HideGUI() { From f85331dd005bca6e3593fc492d03be18b2dc0d4c Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 12:50:42 -0800 Subject: [PATCH 73/77] Add App Store review link link to endgame menu --- FallingEndMenuUI.js | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/FallingEndMenuUI.js b/FallingEndMenuUI.js index 484f085..fb578be 100644 --- a/FallingEndMenuUI.js +++ b/FallingEndMenuUI.js @@ -20,6 +20,9 @@ var text3 : UITextInstance; var openSiteButtonText : UIButton; var BackToEndMenuButton : UIButton; +var appStoreButtonText : UITextInstance; +var appStoreButtonBg : UIButton; + function Start () { textHeight = (UIT.isHD == true) ? 18 : 18; @@ -87,16 +90,28 @@ function Start () { text3 = thinText.addTextInstance( "MUSIC BY EVAN KUBOTA\n\nSOUND EFFECTS: freesound.org", 0, 0); text3.pixelsFromCenter( 45, 0 ); - text1.hidden = true; - text2.hidden = true; - text3.hidden = true; - openSiteButtonText = UIButton.create("tutorialBackground.png","tutorialBackground.png", 40, 40); openSiteButtonText.positionFromCenter(0,0); openSiteButtonText.onTouchUpInside += OpenFallingSite; openSiteButtonText.scaleTo( 0.1f, new Vector3( (Screen.width), 3, 1 ), Easing.Sinusoidal.easeOut); openSiteButtonText.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); + + appStoreButtonText = boldText.addTextInstance( "WRITE A REVIEW...", 0, 0); + appStoreButtonText.positionFromBottom(.05); + + // A transparent tappable background; chosen for its width: + appStoreButtonBg = UIButton.create("spheresText.png", "spheresText.png", 0,0); + appStoreButtonBg.positionFromBottom(.05); + appStoreButtonBg.onTouchUpInside += OpenAppStorePage; + appStoreButtonBg.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); + + text1.hidden = true; + text2.hidden = true; + text3.hidden = true; + openSiteButtonText.hidden = true; + appStoreButtonText.hidden = true; + appStoreButtonBg.hidden = true; } @@ -182,6 +197,8 @@ function OpenAbout() { EndMenuLogoCamera.GetComponent(Camera).enabled = false; + appStoreButtonBg.hidden = false; + appStoreButtonText.hidden = false; openSiteButtonText.hidden = false; text1.hidden = false; text2.hidden = false; @@ -189,10 +206,12 @@ function OpenAbout() { text1.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); text2.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeOut); text3.alphaFromTo(1.5f, 0.0f, 0.6f, Easing.Sinusoidal.easeInOut); - + appStoreButtonText.alphaFromTo(2.5, 0.0, 1.0, Easing.Sinusoidal.easeInOut); } function BackToEndMenu() { + appStoreButtonBg.hidden = true; + appStoreButtonText.hidden = true; BackToEndMenuButton.hidden = true; @@ -227,9 +246,18 @@ function fadeOutContinue() { } function OpenFallingSite() { - Application.OpenURL ("http://tysonkubota.net/skydrift?utm_source=skydrift-game&utm_medium=ios&utm_campaign=skydrift-gui"); + var urlToOpen : String = "http://tysonkubota.net/skydrift?utm_source=skydrift-game&utm_medium=ios&utm_campaign=skydrift-gui"; + // use a float instead of an int, as required by the GameAnalytics SDK: + FallingLaunch.Analytics.Event("OpenURL:FallingSite", FallingLaunch.levelAchieved*1.0); + Application.OpenURL(urlToOpen); } +function OpenAppStorePage() { + var urlToOpen : String = "https://itunes.apple.com/us/app/skydrift/id728636851?action=write-review&mt=8"; + // use a float instead of an int, as required by the GameAnalytics SDK: + FallingLaunch.Analytics.Event("OpenURL:AppStorePage", FallingLaunch.levelAchieved*1.0); + Application.OpenURL(urlToOpen); +} function ShowLevel1Logo() { fallingUITest.nextLevelLabel.hidden = false; From c613c27c98528407d4161bf0a5605278deabe0da Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 15:29:53 -0800 Subject: [PATCH 74/77] Add App store review link to home menu in New Game Plus --- fallingStartMenuUI.js | 47 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index 7aedddc..a1b5494 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -60,6 +60,9 @@ var text3 : UITextInstance; var appStoreButtonText : UITextInstance; var appStoreButtonBg : UIButton; +var appStoreButtonHomeText : UITextInstance; +var appStoreButtonHomeBg : UIButton; + var tiltText1 : UITextInstance; var tiltText2 : UITextInstance; var invertHorizAxisText : UITextInstance; @@ -243,12 +246,24 @@ function Start () { appStoreButtonBg.onTouchUpInside += OpenAppStorePage; appStoreButtonBg.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); + appStoreButtonHomeText = boldText.addTextInstance( "WRITE A REVIEW...", 0, 0); + appStoreButtonHomeText.positionFromTop(.05); + + // A transparent tappable background; chosen for its width: + appStoreButtonHomeBg = UIButton.create("spheresText.png", "spheresText.png", 0,0); + appStoreButtonHomeBg.positionFromTop(.05); + appStoreButtonHomeBg.onTouchUpInside += OpenAppStorePage; + appStoreButtonHomeBg.alphaFromTo(0.1f, 0.0f, 0.0f, Easing.Sinusoidal.easeOut); + + text1.hidden = true; text2.hidden = true; text3.hidden = true; openSiteButtonText.hidden = true; appStoreButtonText.hidden = true; + appStoreButtonHomeText.hidden = true; appStoreButtonBg.hidden = true; + appStoreButtonHomeBg.hidden = true; // TODO: Use real VR Mode icon and button sprite here. // HACK: reusing existing button sprite as a transparent background @@ -573,6 +588,12 @@ function ShowStart() { vrModeButton.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); } + if (FallingLaunch.NewGamePlus) { + appStoreButtonHomeBg.hidden = false; + appStoreButtonHomeText.hidden = false; + appStoreButtonHomeText.alphaFromTo( 3.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + } + rightArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); leftArrow.alphaFromTo( 2.0f, 0.0f, 0.4f, Easing.Sinusoidal.easeIn); aboutButtonStart.alphaFromTo( 2.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); @@ -753,6 +774,11 @@ function BackToPauseMenu() { appStoreButtonBg.hidden = true; appStoreButtonText.hidden = true; + if (FallingLaunch.NewGamePlus) { + appStoreButtonHomeBg.hidden = false; + appStoreButtonHomeText.hidden = false; + } + HideOptions(); // if (PlayerPrefs.HasKey("LatestLevel")) { @@ -968,6 +994,10 @@ function FadeOutAllStartMenuElements(timer: float) { howToButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); optionsButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); + if (FallingLaunch.NewGamePlus) { + appStoreButtonHomeText.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); + } + if (!FallingLaunch.isTablet) { vrModeButton.alphaTo(timer, 0.0f, Easing.Sinusoidal.easeOut); vrModeLaunchButton.alphaTo(timer, 0.0, Easing.Sinusoidal.easeOut); @@ -1174,6 +1204,9 @@ function HideStartMenuElements() { optionsButton.hidden = true; vrModeButton.hidden = true; + + appStoreButtonHomeBg.hidden = true; + appStoreButtonHomeText.hidden = true; //angledTiltChooser.hidden = true; //flatTiltChooser.hidden = true; } @@ -1264,13 +1297,17 @@ function fadeInLoadNewLevels() { } function fadeInPauseMenu() { - rightArrow.alphaFromTo( 0.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeInOut); - leftArrow.alphaFromTo( 0.5f, 0.0f, 0.4f, Easing.Sinusoidal.easeInOut); - aboutButtonStart.alphaFromTo( 0.5f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); - howToButton.alphaFromTo( 0.5f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + rightArrow.alphaFromTo( 0.5, 0.0, 0.4, Easing.Sinusoidal.easeInOut); + leftArrow.alphaFromTo( 0.5, 0.0, 0.4, Easing.Sinusoidal.easeInOut); + aboutButtonStart.alphaFromTo( 0.5, 0.0, 1.0, Easing.Sinusoidal.easeIn); + howToButton.alphaFromTo( 0.5, 0.0, 1.0, Easing.Sinusoidal.easeIn); if (!FallingLaunch.isTablet) { - vrModeButton.alphaFromTo( 0.5f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + vrModeButton.alphaFromTo( 0.5, 0.0, 1.0, Easing.Sinusoidal.easeIn); + } + + if (FallingLaunch.NewGamePlus) { + appStoreButtonHomeText.alphaFromTo( 1.0, 0.0, 1.0, Easing.Sinusoidal.easeIn); } } From e5df2920b0fa6c0832cd9558aa634db68a6b1f67 Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 17:34:59 -0800 Subject: [PATCH 75/77] Fix end sequence local rotation for non-VR mode --- EndSequence1stPerson.js | 13 +++++++++++-- FallingPlayer.js | 8 +++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/EndSequence1stPerson.js b/EndSequence1stPerson.js index 3283fdd..9725818 100644 --- a/EndSequence1stPerson.js +++ b/EndSequence1stPerson.js @@ -172,12 +172,21 @@ function RotateTowardsDiamond (timer : float) { 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; } } diff --git a/FallingPlayer.js b/FallingPlayer.js index ca64f13..7fcf7b9 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -587,10 +587,12 @@ function playerTilt() { if (FallingLaunch.hasSetAccel == false) { FallingLaunch.accelerator = FallingLaunch.calibrationRotation * Input.acceleration; } - tiltAroundZ = FallingLaunch.invertHorizAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.y * tiltAngle)), -tiltAngle, tiltAngle); - tiltAroundX = FallingLaunch.invertVertAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.x * tiltAngle)), -tiltAngle, tiltAngle); + + tiltAroundX = FallingLaunch.invertVertAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.x * tiltAngle)), -tiltAngle, tiltAngle); - var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); + tiltAroundZ = FallingLaunch.invertHorizAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.y * tiltAngle)), -tiltAngle, tiltAngle); + + var target : Quaternion = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); // Dampen towards the target rotation // Rotating the camera transform, not the Player transform itself, so the 3D clouds // (which are the child of the Player object) have correct tilt context. From 9e30c03c409df414d18efd71ceb2ac8cda143e2c Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 17:49:18 -0800 Subject: [PATCH 76/77] Tweak start menu App Store link fade --- FallingEndMenuUI.js | 10 +++++----- fallingStartMenuUI.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FallingEndMenuUI.js b/FallingEndMenuUI.js index fb578be..7a5fd0c 100644 --- a/FallingEndMenuUI.js +++ b/FallingEndMenuUI.js @@ -193,7 +193,7 @@ function OpenAbout() { endGameSprite.hidden = true; BackToEndMenuButton.hidden = false; - BackToEndMenuButton.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeIn); + BackToEndMenuButton.alphaFromTo(1.0, 0.0, 1.0, Easing.Sinusoidal.easeIn); EndMenuLogoCamera.GetComponent(Camera).enabled = false; @@ -203,10 +203,10 @@ function OpenAbout() { text1.hidden = false; text2.hidden = false; text3.hidden = false; - text1.alphaFromTo(1.0f, 0.0f, 0.8f, Easing.Sinusoidal.easeOut); - text2.alphaFromTo(1.0f, 0.0f, 1.0f, Easing.Sinusoidal.easeOut); - text3.alphaFromTo(1.5f, 0.0f, 0.6f, Easing.Sinusoidal.easeInOut); - appStoreButtonText.alphaFromTo(2.5, 0.0, 1.0, Easing.Sinusoidal.easeInOut); + text1.alphaFromTo(1.0, 0.0, 0.8, Easing.Sinusoidal.easeOut); + text2.alphaFromTo(1.0, 0.0, 1.0, Easing.Sinusoidal.easeOut); + text3.alphaFromTo(1.5, 0.0, 0.6, Easing.Sinusoidal.easeInOut); + appStoreButtonText.alphaFromTo(2.5, 0.0, 1.0, Easing.Sinusoidal.easeIn); } function BackToEndMenu() { diff --git a/fallingStartMenuUI.js b/fallingStartMenuUI.js index a1b5494..4fc91e3 100644 --- a/fallingStartMenuUI.js +++ b/fallingStartMenuUI.js @@ -1036,7 +1036,7 @@ function OpenAbout() { text1.alphaFromTo(1.0, 0.0, 0.8, Easing.Sinusoidal.easeOut); text2.alphaFromTo(1.0, 0.0, 1.0, Easing.Sinusoidal.easeOut); text3.alphaFromTo(1.5, 0.0, 0.6, Easing.Sinusoidal.easeInOut); - appStoreButtonText.alphaFromTo(3.5, 0.0, 1.0, Easing.Sinusoidal.easeInOut); + appStoreButtonText.alphaFromTo(2.5, 0.0, 1.0, Easing.Sinusoidal.easeIn); } function OpenVRModeMenu() { From 8129f20e5dd80cd313867795f86e84e081d78e2b Mon Sep 17 00:00:00 2001 From: tyson-kubota Date: Sat, 2 Dec 2017 18:26:06 -0800 Subject: [PATCH 77/77] Minor note re. tutorial hints post-respawn in VR mode --- FallingPlayer.js | 35 ++++++++++++++++------------------- lifeCountdown.js | 7 +++++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/FallingPlayer.js b/FallingPlayer.js index 7fcf7b9..3d689b4 100644 --- a/FallingPlayer.js +++ b/FallingPlayer.js @@ -322,7 +322,6 @@ function ShowDeathInterstitialVR() { } function RespawnAfterDeathInterstitialVR() { - Debug.Log('called RespawnAfterDeathInterstitialVR'); isExitableFromVR = false; yield DeathFadeVR(0.5, FadeDir.Out); @@ -353,10 +352,10 @@ function RespawnAfterDeathInterstitialVR() { } function DeathRespawn () { - isPausable = false; - rb.isKinematic = true; - lifeStartTime = Time.time; - var respawnPosition = Respawn.currentRespawn.transform.position; + isPausable = false; + rb.isKinematic = true; + lifeStartTime = Time.time; + var respawnPosition = Respawn.currentRespawn.transform.position; if (FallingLaunch.isVRMode) { reticleVRUIScript.FadeReticleOut(0.5); @@ -378,22 +377,22 @@ function DeathRespawn () { } // If you want to clear destroyed projectiles (set per-level)... - if (clearDestroyedObjects) { - Resources.UnloadUnusedAssets(); - } + if (clearDestroyedObjects) { + Resources.UnloadUnusedAssets(); + } - isAlive = 1; - RenderSettings.fogEndDistance = startingFogEndDistance; - RenderSettings.fogStartDistance = startingFogStartDistance; + isAlive = 1; + RenderSettings.fogEndDistance = startingFogEndDistance; + RenderSettings.fogStartDistance = startingFogStartDistance; -// Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too - GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); - // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider. - myTransform.position = respawnPosition; // + Vector3.up; + // Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too + GetComponent.().attachedRigidbody.transform.Translate(respawnPosition); + // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider. + myTransform.position = respawnPosition; // + Vector3.up; - rb.isKinematic = false; + rb.isKinematic = false; - MoveController.controlMultiplier = 1.0; + MoveController.controlMultiplier = 1.0; if (FallingLaunch.isVRMode && deathPauseUIVR && deathFadeUIVR) { ShowDeathInterstitialVR(); @@ -801,8 +800,6 @@ function OnCollisionEnter (collision : Collision) { //Debug.Log("You died in a fatal collision with " + collision.gameObject); yield DeathRespawn (); - //isPausable = true; - //UIscriptComponent.UnhideGUI(); } } diff --git a/lifeCountdown.js b/lifeCountdown.js index 0fb4bb2..725e034 100644 --- a/lifeCountdown.js +++ b/lifeCountdown.js @@ -112,6 +112,13 @@ function TickingAway (delay : float) { FallingLaunch.secondsAlive ); + // In VR mode, DeathRespawn is now decoupled from the actual respawning time: + // e.g. the player has a several-second time interval to decide whether + // to exit or respawn. If they take more time than showIconVR's timer, + // the tutorial UI hint will already be transparent by the time they respawn. + // That's probably not a huge deal since it's non-critical UI, just a help hint. + // TODO: Pass optional args to DeathRespawn in VR mode, so we can show specific UI + // after user-initiated respawn or via a callback. yield GetComponent(FallingPlayer).DeathRespawn(); if (!FallingLaunch.isVRMode) {