diff options
Diffstat (limited to 'Client/Assembly-CSharp/LeafMinigame.cs')
-rw-r--r-- | Client/Assembly-CSharp/LeafMinigame.cs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/LeafMinigame.cs b/Client/Assembly-CSharp/LeafMinigame.cs new file mode 100644 index 0000000..17f4d18 --- /dev/null +++ b/Client/Assembly-CSharp/LeafMinigame.cs @@ -0,0 +1,104 @@ +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<LeafBehaviour>(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<Collider2D>(); + } + } + + 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<LeafBehaviour>(); + switch (this.myController.CheckDrag(collider2D, false)) + { + case DragState.TouchStart: + if (Constants.ShouldPlaySfx()) + { + SoundManager.Instance.PlaySound(this.LeaveSounds.Random<AudioClip>(), 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<SpriteRenderer>().sprite = null; + } + break; + } + } + } + } + + public void LeafDone(LeafBehaviour leaf) + { + if (Constants.ShouldPlaySfx()) + { + SoundManager.Instance.PlaySound(this.SuckSounds.Random<AudioClip>(), 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)); + } + } + } +} |