using System; using System.Collections; using UnityEngine; public abstract class Minigame : MonoBehaviour { public global::Console Console { get; set; } protected int ConsoleId { get { if (!this.Console) { return 0; } return this.Console.ConsoleId; } } public static Minigame Instance; public const float Depth = -50f; public TransitionType TransType; protected PlayerTask MyTask; protected NormalPlayerTask MyNormTask; protected Minigame.CloseState amClosing; public AudioClip OpenSound; public AudioClip CloseSound; protected enum CloseState { None, Waiting, Closing } public virtual void Begin(PlayerTask task) { Minigame.Instance = this; this.MyTask = task; this.MyNormTask = (task as NormalPlayerTask); if (PlayerControl.LocalPlayer) { if (MapBehaviour.Instance) { MapBehaviour.Instance.Close(); } PlayerControl.LocalPlayer.NetTransform.Halt(); } base.StartCoroutine(this.CoAnimateOpen()); } protected IEnumerator CoStartClose(float duration = 0.75f) { if (this.amClosing != Minigame.CloseState.None) { yield break; } this.amClosing = Minigame.CloseState.Waiting; yield return Effects.Wait(duration); this.Close(); yield break; } [Obsolete("Don't use, I just don't want to reselect the close button event handlers", true)] public void Close(bool allowMovement) { this.Close(); } public virtual void Close() { if (this.amClosing != Minigame.CloseState.Closing) { if (this.CloseSound && Constants.ShouldPlaySfx()) { SoundManager.Instance.PlaySound(this.CloseSound, false, 1f); } this.amClosing = Minigame.CloseState.Closing; base.StartCoroutine(this.CoDestroySelf()); return; } UnityEngine.Object.Destroy(base.gameObject); } protected virtual IEnumerator CoAnimateOpen() { if (this.OpenSound && Constants.ShouldPlaySfx()) { SoundManager.Instance.PlaySound(this.OpenSound, false, 1f); } TransitionType transType = this.TransType; if (transType != TransitionType.SlideBottom) { if (transType == TransitionType.Alpha) { SpriteRenderer[] rends = base.GetComponentsInChildren(); for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime) { float t = timer / 0.25f; for (int i = 0; i < rends.Length; i++) { rends[i].color = Color.Lerp(Palette.ClearWhite, Color.white, t); } yield return null; } for (int j = 0; j < rends.Length; j++) { rends[j].color = Color.white; } rends = null; } } else { for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime) { float t2 = timer / 0.25f; base.transform.localPosition = new Vector3(0f, Mathf.SmoothStep(-8f, 0f, t2), -50f); yield return null; } base.transform.localPosition = new Vector3(0f, 0f, -50f); } yield break; } protected virtual IEnumerator CoDestroySelf() { TransitionType transType = this.TransType; if (transType != TransitionType.SlideBottom) { if (transType == TransitionType.Alpha) { SpriteRenderer[] rends = base.GetComponentsInChildren(); for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime) { float t = timer / 0.25f; for (int i = 0; i < rends.Length; i++) { rends[i].color = Color.Lerp(Color.white, Palette.ClearWhite, t); } yield return null; } rends = null; } } else { for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime) { float t2 = timer / 0.25f; base.transform.localPosition = new Vector3(0f, Mathf.SmoothStep(0f, -8f, t2), -50f); yield return null; } } UnityEngine.Object.Destroy(base.gameObject); yield break; } }