using System; using PowerTools; using UnityEngine; public class LeafMinigame : Minigame { public LeafBehaviour LeafPrefab; public Vector2Range ValidArea; public SpriteAnim[] Arrows; public AnimationClip[] Inactive; public AnimationClip[] Active; public AnimationClip[] Complete; private Collider2D[] Leaves; public AudioClip[] LeaveSounds; public AudioClip[] SuckSounds; private Controller myController = new Controller(); public override void Begin(PlayerTask task) { base.Begin(task); this.Leaves = new Collider2D[this.MyNormTask.MaxStep - this.MyNormTask.taskStep]; for (int i = 0; i < this.Leaves.Length; i++) { LeafBehaviour leafBehaviour = UnityEngine.Object.Instantiate(this.LeafPrefab); leafBehaviour.transform.SetParent(base.transform); leafBehaviour.Parent = this; Vector3 localPosition = this.ValidArea.Next(); localPosition.z = -1f; leafBehaviour.transform.localPosition = localPosition; this.Leaves[i] = leafBehaviour.GetComponent(); } } public void FixedUpdate() { this.myController.Update(); for (int i = 0; i < this.Leaves.Length; i++) { Collider2D collider2D = this.Leaves[i]; if (collider2D) { LeafBehaviour component = collider2D.GetComponent(); switch (this.myController.CheckDrag(collider2D, false)) { case DragState.TouchStart: if (Constants.ShouldPlaySfx()) { SoundManager.Instance.PlaySound(this.LeaveSounds.Random(), false, 1f); } for (int j = 0; j < this.Arrows.Length; j++) { this.Arrows[j].Play(this.Active[j], 1f); } component.Held = true; break; case DragState.Dragging: { Vector2 vector = this.myController.DragPosition - component.body.position; component.body.velocity = vector.normalized * Mathf.Min(3f, vector.magnitude * 3f); break; } case DragState.Released: component.Held = false; for (int k = 0; k < this.Arrows.Length; k++) { this.Arrows[k].Play(this.Inactive[k], 1f); this.Arrows[k].GetComponent().sprite = null; } break; } } } } public void LeafDone(LeafBehaviour leaf) { if (Constants.ShouldPlaySfx()) { SoundManager.Instance.PlaySound(this.SuckSounds.Random(), false, 1f); } UnityEngine.Object.Destroy(leaf.gameObject); if (this.MyNormTask) { this.MyNormTask.NextStep(); if (this.MyNormTask.IsComplete) { for (int i = 0; i < this.Arrows.Length; i++) { this.Arrows[i].Play(this.Complete[i], 1f); } base.StartCoroutine(base.CoStartClose(0.75f)); } } } }