//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public bool UpdateAnimation(float fAnimationSpeed = 1.0f) { if (!IsCompleted()) { if (m_bFirstUpdate) { OnFirstUpdate(); } // If timer is finished. Finish Animation if (m_ttTimer.Update(fAnimationSpeed)) { if (m_bPositionChanging) { Target.localPosition = m_vEndPosition; } if (m_bRotationChanging) { Target.localRotation = Quaternion.Euler(m_vEndRotation); } if (m_bScaleChanging) { Target.localScale = m_vEndScale; } if (m_bColourChanging) { UpdateColour(m_cEndColour, m_cEndColour, 1.0f); } } // Otherwise Update it according to Timer Completion Percentage else { float t = m_ttTimer.GetCompletionPercentage(); if (m_bPositionChanging) { Target.localPosition = Vector3.Lerp(m_vStartingPosition, m_vEndPosition, t); } if (m_bRotationChanging) { Target.localRotation = Quaternion.Euler(Vector3.Lerp(m_vStartingRotation, m_vEndRotation, t)); } if (m_bScaleChanging) { Target.localScale = Vector3.Lerp(m_vStartingScale, m_vEndScale, t); } if (m_bColourChanging) { UpdateColour(m_cStartingColour, m_cEndColour, t); } } } return(IsCompleted()); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Regular Fade //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void UpdateRegularFade() { if (m_ttFadeTracker.Update()) { IsFading = false; m_eCurrentFadeType = FadeType.NO_FADE; Volume = m_fEndFadeVolume; } else { Volume = Mathf.Lerp(m_fStartFadeVolume, m_fEndFadeVolume, m_ttFadeTracker.GetCompletionPercentage()); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public bool UpdateAnimation(float fAnimationSpeed = 1.0f) { if (!IsCompleted()) { // If timer is finished. Finish Animation if (m_ttTimer.Update(fAnimationSpeed)) { UpdateColour(m_cEndColour, m_cEndColour, 1.0f); } // Otherwise Update it according to Timer Completion Percentage else { UpdateColour(m_cStartingColour, m_cEndColour, m_ttTimer.GetCompletionPercentage()); } } return(IsCompleted()); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void Update() { m_TTTimeValue.Update(); if (m_TTTimeValue.TimeUp()) { m_ASource.volume = m_fEndVolume; DynamicUpdateManager.RemoveFadeEffect(m_ID); } if (m_bFadeIn) { m_ASource.volume = ((m_fEndVolume - m_fStartVolume) * m_TTTimeValue.GetCompletionPercentage()); } else { m_ASource.volume = (m_fStartVolume - (m_fStartVolume * m_TTTimeValue.GetCompletionPercentage())); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Intro Phase //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void UpdateIntroPhase() { m_ttIntroTimer.Update(); if (m_ttIntroTimer.TimeUp()) { m_eVisualPhase = VisualPhase.IDLE; Scale.Set(m_vIntroEndScale); } else { Scale.Set(Vector3.Lerp(m_vIntroStartScale, m_vIntroEndScale, m_ttIntroTimer.GetCompletionPercentage())); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Fade out //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void FadeOut() { m_ttFadeoutTimer.Update(); if (m_ttFadeoutTimer.TimeUp()) { this.gameObject.SetActive(false); } else { Color alpha = SpriteColour; alpha.a = Mathf.Lerp(m_fFadeoutStartAlpha, 0.0f, m_ttFadeoutTimer.GetCompletionPercentage()); SpriteColour = alpha; } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Fade in //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void FadeIn() { m_ttFadeinTimer.Update(); if (m_ttFadeinTimer.TimeUp()) { SpriteColour = Color.white; m_eAttackPhase = AttackPhase.MOVING; } else { Color alpha = SpriteColour; alpha.a = Mathf.Lerp(0.0f, 1.0f, m_ttFadeinTimer.GetCompletionPercentage()); SpriteColour = alpha; } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * Derived Method: Update //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void Update() { if (IsTransitioning) { if (sm_ttVignetteFadeTimer.Update()) { IsTransitioning = false; if (sm_OnCompleteCallback != null) { sm_OnCompleteCallback(); } } CurrentColour = Color.Lerp(sm_cPreviousColour, sm_cTransitioningColour, sm_ttVignetteFadeTimer.GetCompletionPercentage()); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Unsuccessful Hit~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void UpdateUnsuccessfulHit() { if (m_ttMissedMovementTracker.Update()) { SprRend.color = new Color(1.0f, 1.0f, 1.0f, 0.0f); m_eMovementPhase = MovementPhase.IDLE; } else { float timeAdjustment = Time.deltaTime * 10.0f; m_fMissedTime += timeAdjustment; float xAdjustment = Mathf.Cos(m_fMissedTime) * 0.01f; float newX = m_rChallengeModeInfo.targetLocation.x + xAdjustment; // Gradually Moving Left to Right float newY = LocalPosition.y - 0.1f * Time.deltaTime; // Gradually falling transform.localPosition = new Vector3(newX, newY, transform.localPosition.z); SprRend.color = new Color(1.0f, 1.0f, 1.0f, 1.0f - m_ttMissedMovementTracker.GetCompletionPercentage()); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Lerp //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ protected void UpdateLerp() { // Update Return Lerp to NOT OUT OF BOUNDS Position/Scale. If Illegal Colour has been enabled. Lerp that back to normal also. if (m_ttLerpTimer.Update()) { if (m_bIsLerpingScale) { LocalScale = m_vLerpEnd; } else { LocalPosition = m_vLerpEnd; } if (m_rSprRend != null) { m_rSprRend.color = Color.white; } m_ttLerpTimer.Reset(); m_bIsLerping = false; CheckLimit(); } else { float t = m_ttLerpTimer.GetCompletionPercentage(); if (m_bIsLerpingScale) { LocalScale = Vector3.Slerp(m_vLerpStart, m_vLerpEnd, t); } else { LocalPosition = Vector3.Slerp(m_vLerpStart, m_vLerpEnd, t); } if (m_rSprRend != null) { m_rSprRend.color = Color.Lerp(m_cReturnLerpStartColour, Color.white, t); } } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * Derived Method: Update //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void Update() { if (m_iCurrentElement < (m_iTotalElements - 1)) { m_ttMovementTransitionTimer.Update(); if (m_ttMovementTransitionTimer.TimeUp()) { m_ttMovementTransitionTimer.Reset(); transform.position = m_vMovementTargets[m_iCurrentElement + 1]; m_iCurrentElement += 1; } else { transform.position = Vector3.Lerp(m_vMovementTargets[m_iCurrentElement], m_vMovementTargets[m_iCurrentElement + 1], m_ttMovementTransitionTimer.GetCompletionPercentage()); } } else { Reset(); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Change TextBox Position to Challenge Mode Position //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private IEnumerator ChangeTutorialTextBoxPositionToChallengeMode() { m_bFreezeTutorialUpdate = true; { Vector3 vStartPos = m_rTextBoxTransitionEffect.transform.localPosition; TimeTracker ttLerpTimer = new TimeTracker(m_fPositionLerpTime); while (!ttLerpTimer.TimeUp()) { if (ttLerpTimer.Update()) { m_rTextBoxTransitionEffect.transform.localPosition = m_vChallengeModeTextBoxPosition; } else { m_rTextBoxTransitionEffect.transform.localPosition = Vector3.Lerp(vStartPos, m_vChallengeModeTextBoxPosition, ttLerpTimer.GetCompletionPercentage()); yield return(new WaitForEndOfFrame()); } } } m_bFreezeTutorialUpdate = false; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Text Information //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private IEnumerator UpdateTextInformation() { const float fTextDisplayTimer = 3.0f; const float fTextFadeTime = 0.5f; TimeTracker ttTextFadeTimer = new TimeTracker(fTextFadeTime); bool bShowingChallengeName = true; bool bRequiresMoreFeathers = (m_eButtonAvailability == ButtonAvailability.NEED_MORE_FEATHERS); while (true) { // Show Text yield return(new WaitForSeconds(fTextDisplayTimer)); // Fade out Text ttTextFadeTimer.Reset(); while (!ttTextFadeTimer.TimeUp()) { if (ttTextFadeTimer.Update()) { TextOpacity = 0.0f; if (!bShowingChallengeName && bRequiresMoreFeathers) { FeatherOpacity = 0.0f; } } else { TextOpacity = Mathf.Lerp(m_cUnavailableTextColour.a, 0.0f, ttTextFadeTimer.GetCompletionPercentage()); if (!bShowingChallengeName && bRequiresMoreFeathers) { FeatherOpacity = (1.0f - ttTextFadeTimer.GetCompletionPercentage()); } } yield return(new WaitForEndOfFrame()); } // Change Text bShowingChallengeName = !bShowingChallengeName; if (bShowingChallengeName) { if (bRequiresMoreFeathers) { m_rRequiredFeathersIcon.gameObject.SetActive(false); } MultiLanguageTextComponent.ApplyEffects(TextRenderer); } else { if (bRequiresMoreFeathers) { m_rRequiredFeathersIcon.gameObject.SetActive(true); int iFeathers = m_rChallengeManager.GetRequiredFeathersAmountForChallenge(m_eChallengeID); TextRenderer.text = " x" + (iFeathers < 10 ? "0" : "") + iFeathers.ToString(); } else { m_oUnavailableText.ApplyEffects(TextRenderer); } } TextOpacity = 0.0f; // Fade in Text ttTextFadeTimer.Reset(); while (!ttTextFadeTimer.TimeUp()) { if (ttTextFadeTimer.Update()) { TextOpacity = m_cUnavailableTextColour.a; if (!bShowingChallengeName && bRequiresMoreFeathers) { FeatherOpacity = 1.0f; } } else { TextOpacity = Mathf.Lerp(0.0f, m_cUnavailableTextColour.a, ttTextFadeTimer.GetCompletionPercentage()); if (!bShowingChallengeName && bRequiresMoreFeathers) { FeatherOpacity = ttTextFadeTimer.GetCompletionPercentage(); } } yield return(new WaitForEndOfFrame()); } } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Background Blur //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void UpdateBackgroundBlur() { if (m_ttLanscapeBlurTimer.Update()) { m_ttLanscapeBlurTimer.Reset(); m_srBackgroundSpriteRenderer.material.SetFloat("_Distance", m_fLandscapeBlurDistance); ProceedToNextPhase(); } else { m_srBackgroundSpriteRenderer.material.SetFloat("_Distance", Mathf.Lerp(0.0f, m_fLandscapeBlurDistance, m_ttLanscapeBlurTimer.GetCompletionPercentage())); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Fade Effect //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void UpdateFadeEffect() { // If the fadein timer has completed (or I got impatient on the PC); Show the Scene Fully Opaque / Fully Transparent #if UNITY_EDITOR if (m_ttTransitionTimer.Update() || Input.GetKeyDown(KeyCode.Space)) #else if (m_ttTransitionTimer.Update()) #endif { if (m_eTransitionState == TransitionState.FADEIN) { OnFadeIn(); } else { OnFadeout(); } m_eTransitionState = TransitionState.IDLE; } // Otherwise Fade in/out scene according to the completion percentage of the timer. else { float t = Mathf.Lerp(0.0f, 1.0f, (m_eTransitionState == TransitionState.FADEIN ? m_ttTransitionTimer.GetCompletionPercentage() : 1.0f - m_ttTransitionTimer.GetCompletionPercentage())); foreach (SpriteRenderer sr in m_lSprRends) { // Make Sure the Sprite Renderer is still valid if (sr != null) { Color colour = sr.color; colour.a = t; sr.color = colour; } } foreach (UnityEngine.UI.Text tr in m_lTextRends) { if (tr != null) { Color colour = tr.color; colour.a = t; tr.color = colour; } } foreach (UnityEngine.UI.Image ir in m_lImgRends) { if (ir != null) { Color colour = ir.color; colour.a = t; ir.color = colour; } } // If there is a Sound Player for BGM, fade in/out the audio volume also if (m_asSoundPlayer != null) { m_asSoundPlayer.volume = Mathf.Lerp(0.0f, 1.0f, t); } } }