private void Quit() { GameManager.Instance.ReturnToMenu(ClearLeaks, () => StartCoroutine(LeaveThenDestroyFromNextFrame(-1000, 1))); void ClearLeaks() { if (teacher != null) { Destroy(teacher.gameObject); } StopAllCoroutines(); gameObject.AddComponent <CanvasGroup>().interactable = false; // make sure not interactable } IEnumerator LeaveThenDestroyFromNextFrame(float targetY, float duration) { // wait one frame to avoid lag spike yield return(null); shade.enabled = false; float startY = back.transform.localPosition.y; float startTime = Time.time; while (Time.time < startTime + duration) { float t = Tweens.QuadraticInOut((Time.time - startTime) / duration); float y = Mathf.Lerp(startY, targetY, t); back.transform.localPosition = new Vector2(transform.localPosition.x, y); yield return(null); } Destroy(gameObject); } }
void TweenFromFlag(float duration) { flagging = false; StartCoroutine(Spin()); IEnumerator Spin() { var rt = GetComponent <RectTransform>(); float startTime = Time.time; while (Time.time < startTime + duration) { float t = Tweens.QuadraticInOut((Time.time - startTime) / duration); float size = Mathf.Lerp(1, 0, t); float rot = Mathf.Lerp(0, 720, t); rt.localScale = new Vector3(size, size, 1); rt.localRotation = Quaternion.Euler(0, 0, rot); yield return(null); } rt.localScale = Vector3.zero; rt.localRotation = Quaternion.identity; flagBack.enabled = flagIcon.enabled = false; playButton.interactable = true; playButton.gameObject.SetActive(true); quitButton.gameObject.SetActive(false); replayButton.gameObject.SetActive(false); yield return(null); GameManager.Instance.ShowReportCard(); rt.localScale = Vector3.one; } }
void TweenToZeroPos(float duration, Transform newParent) { IEnumerator Tween() { while (tweeningPos) { yield return(null); } tweeningPos = true; transform.SetParent(newParent, true); transform.localScale = Vector3.one; Vector2 startPos = transform.localPosition; float startTime = Time.time; while (Time.time < startTime + duration) { float t = Tweens.QuadraticInOut((Time.time - startTime) / duration); transform.localPosition = Vector2.Lerp(startPos, Vector2.zero, t); yield return(null); } transform.localPosition = Vector2.zero; tweeningPos = false; } StartCoroutine(Tween()); }
void TweenFromCard(float duration) { StartCoroutine(Tween()); IEnumerator Tween() { while (tweeningCard == true) { yield return(null); } tweeningCard = true; var rt = GetComponent <RectTransform>(); var startSize = rt.sizeDelta; var endSize = new Vector2(100, 100); float aShade = shade.color.a; float aThumb = thumbnailGroup.alpha; float aCard = cardGroup.alpha; cardGroup.interactable = false; cardGroup.blocksRaycasts = false; thumbnailGroup.interactable = true; thumbnailGroup.blocksRaycasts = true; shade.raycastTarget = false; float startTime = Time.time; while (Time.time < startTime + duration) { float t = Tweens.QuadraticInOut((Time.time - startTime) / duration); rt.sizeDelta = Vector2.Lerp(startSize, endSize, t); shade.color = new Color(0, 0, 0, Mathf.Lerp(aShade, 0, t)); thumbnailGroup.alpha = Mathf.Lerp(aThumb, 1, t); cardGroup.alpha = Mathf.Lerp(aCard, 0, t); yield return(null); } rt.sizeDelta = endSize; shade.enabled = false; shade.color = new Color(0, 0, 0, 0); thumbnailGroup.alpha = 1; cardGroup.alpha = 0; cardCanvas.enabled = false; tweeningCard = false; RenderBelow(); } void RenderBelow() { #if UNITY_EDITOR // for play mode opened from the start // so card was never displayed in the first place if (extraCanvas == null) { return; } #endif extraCanvas.overrideSorting = false; // RectMask2D breaks otherwise Destroy(extraRaycaster); Destroy(extraCanvas); } }
void TweenToCard(float duration) { StartCoroutine(Tween()); IEnumerator Tween() { while (tweeningCard == true) { yield return(null); } RenderOnTop(5); tweeningCard = true; var rt = GetComponent <RectTransform>(); var startSize = rt.sizeDelta; var endSize = new Vector2(400, 400); float aShade = shade.color.a; float aThumb = thumbnailGroup.alpha; float aCard = cardGroup.alpha; cardCanvas.enabled = true; cardGroup.interactable = true; cardGroup.blocksRaycasts = true; thumbnailGroup.interactable = false; thumbnailGroup.blocksRaycasts = false; shade.enabled = true; shade.raycastTarget = true; float startTime = Time.time; while (Time.time < startTime + duration) { float t = Tweens.QuadraticInOut((Time.time - startTime) / duration); rt.sizeDelta = Vector2.Lerp(startSize, endSize, t); shade.color = new Color(0, 0, 0, Mathf.Lerp(aShade, .3f, t)); thumbnailGroup.alpha = Mathf.Lerp(aThumb, 0, t); cardGroup.alpha = Mathf.Lerp(aCard, 1, t); yield return(null); } rt.sizeDelta = endSize; shade.color = new Color(0, 0, 0, .3f); thumbnailGroup.alpha = 0; cardGroup.alpha = 1; tweeningCard = false; } void RenderOnTop(int sortOrder) { extraCanvas = gameObject.AddComponent <Canvas>(); extraRaycaster = gameObject.AddComponent <GraphicRaycaster>(); extraCanvas.overrideSorting = true; extraCanvas.sortingOrder = sortOrder; } }
IEnumerator TweenToZero(float duration) { yield return(null); // smelly wait so that localpos is set to shadow float startTime = Time.time; Vector3 startPos = transform.localPosition; Vector3 startScale = transform.localScale; while (Time.time < startTime + duration) { float t = Tweens.CubicInOut((Time.time - startTime) / duration); transform.localPosition = Vector3.Lerp(startPos, Vector3.zero, t); transform.localScale = Vector3.Lerp(startScale, Vector3.one, t); yield return(null); } transform.localPosition = Vector3.zero; transform.localScale = Vector3.one; }