blob: 17f4d1818f011a9542ccfa9a8769372329952e4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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));
}
}
}
}
|