/// <summary> /// Begins uploading upon player entering hack area /// </summary> /// <param name="col"></param> private void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Player") { if (hackStart == false) { // Animate the loading bar in. float fadeTime = 0.1f; LoadingBarPanel.gameObject.SetActive(true); loadingBarActive = true; LoadingBar.enabled = true; // Set the loading bar element alphas to 0. changeAlphaTo(LoadingBar, 0f); changeAlphaTo(LoadingBarSpin, 0f); changeAlphaTo(LoadingFrame, 0f); changeAlphaTo(LoadingBG, 0f); changeAlphaTo(LoadingPercent, 0f); // Start loading bar elements alpha tweens to 1. LoadingBar.DOFade(1, fadeTime); LoadingBarSpin.DOFade(1, fadeTime); LoadingFrame.DOFade(1, fadeTime); LoadingBG.DOFade(1, fadeTime); LoadingPercent.DOFade(1, fadeTime); } hackStart = true; startHackLoadingBar(); StartCoroutine(Uploading()); } }
/// <summary> /// Halts uploading upon player leaving hack area /// </summary> /// <param name="col"></param> private void OnTriggerExit2D(Collider2D col) { if (col.gameObject.tag == "Player") { hackStart = false; float fadeTime = 0.1f; // Check which element is visible to play appropriate fade out animation. if (loadingBarActive) { // Fade out the loading bar. // Set the loading bar element alphas to 1. changeAlphaTo(LoadingBar, 1f); changeAlphaTo(LoadingBarSpin, 1f); changeAlphaTo(LoadingFrame, 1f); changeAlphaTo(LoadingBG, 1f); changeAlphaTo(LoadingPercent, 1f); // Start loading bar elements alpha tweens to 0. LoadingBar.DOFade(0, fadeTime); LoadingBarSpin.DOFade(0, fadeTime); LoadingFrame.DOFade(0, fadeTime); LoadingBG.DOFade(0, fadeTime); LoadingPercent.DOFade(0, fadeTime); } else if (hackDialogActive) { // Fade out the hack dialog. // Set dialog's alpha to 1. changeAlphaTo(HackDialogBG, 1f); changeAlphaTo(QTEButton1, 1f); changeAlphaTo(QTEButton2, 1f); changeAlphaTo(QTEButton3, 1f); // Start dialog's alpha tween to 0. HackDialogBG.DOFade(0, fadeTime); QTEButton1.DOFade(0, fadeTime); QTEButton2.DOFade(0, fadeTime); QTEButton3.DOFade(0, fadeTime); HackDialogChevron1.DOFade(0, fadeTime); HackDialogChevron2.DOFade(0, fadeTime); HackDialogChevron3.DOFade(0, fadeTime); } resetHackLoadingBar(); StopCoroutine(Uploading()); loadingBarActive = false; hackDialogActive = false; LoadingBar.fillAmount = 0; } }
/// <summary> /// Swap the loading bar with the hack dialog through an animation. /// </summary> /// <returns></returns> private IEnumerator QTEStartAnimation() { // Define some animation time variables. float fadeTime = 0.1f; // Set dialog's alpha to 0. changeAlphaTo(HackDialogBG, 0f); changeAlphaTo(QTEButton1, 0f); changeAlphaTo(QTEButton2, 0f); changeAlphaTo(QTEButton3, 0f); // Set the loading bar element alphas to 1. changeAlphaTo(LoadingBar, 1f); changeAlphaTo(LoadingBarSpin, 1f); changeAlphaTo(LoadingFrame, 1f); changeAlphaTo(LoadingBG, 1f); changeAlphaTo(LoadingPercent, 1f); // Start loading bar elements alpha tweens to 0. LoadingBar.DOFade(0, fadeTime); LoadingBarSpin.DOFade(0, fadeTime); LoadingFrame.DOFade(0, fadeTime); LoadingBG.DOFade(0, fadeTime); LoadingPercent.DOFade(0, fadeTime); // Wait for the fade out tween to finish. yield return(new WaitForSeconds(fadeTime)); loadingBarActive = false; // Start dialog's alpha tween to 1. HackDialogBG.DOFade(1, fadeTime); QTEButton1.DOFade(1, fadeTime); QTEButton2.DOFade(1, fadeTime); QTEButton3.DOFade(1, fadeTime); hackDialogActive = true; // Run the QTE mechanisms. QTEManager.gameObject.SetActive(true); }