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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
using System;
using System.Runtime.InteropServices;
using UnityEngine;
public class CourseMinigame : Minigame
{
public CourseStarBehaviour StarPrefab;
public CourseStarBehaviour[] Stars;
public SpriteRenderer DotPrefab;
public Sprite DotLight;
public SpriteRenderer[] Dots;
public Collider2D Ship;
public CourseStarBehaviour Destination;
public Vector3[] PathPoints;
public int NumPoints;
public FloatRange XRange;
public FloatRange YRange;
public LineRenderer Path;
public Controller myController = new Controller();
public float lineTimer;
private CourseMinigame.UIntFloat Converter;
public AudioClip SetCourseSound;
public AudioClip SetCourseLastSound;
[StructLayout(LayoutKind.Explicit)]
private struct UIntFloat
{
[FieldOffset(0)]
public float FloatValue;
[FieldOffset(0)]
public int IntValue;
public float GetFloat(byte[] bytes)
{
this.IntValue = ((int)bytes[0] | (int)bytes[1] << 8 | (int)bytes[2] << 16 | (int)bytes[3] << 24);
return this.FloatValue;
}
public void GetBytes(float value, byte[] bytes)
{
this.FloatValue = value;
bytes[0] = (byte)(this.IntValue & 255);
bytes[1] = (byte)(this.IntValue >> 8 & 255);
bytes[2] = (byte)(this.IntValue >> 16 & 255);
bytes[3] = (byte)(this.IntValue >> 24 & 255);
}
}
public override void Begin(PlayerTask task)
{
base.Begin(task);
this.PathPoints = new Vector3[this.NumPoints];
this.Stars = new CourseStarBehaviour[this.NumPoints];
this.Dots = new SpriteRenderer[this.NumPoints];
for (int i = 0; i < this.PathPoints.Length; i++)
{
this.PathPoints[i].x = this.XRange.Lerp((float)i / ((float)this.PathPoints.Length - 1f));
do
{
this.PathPoints[i].y = this.YRange.Next();
}
while (i > 0 && Mathf.Abs(this.PathPoints[i - 1].y - this.PathPoints[i].y) < this.YRange.Width / 4f);
this.Dots[i] = UnityEngine.Object.Instantiate<SpriteRenderer>(this.DotPrefab, base.transform);
this.Dots[i].transform.localPosition = this.PathPoints[i];
if (i == 0)
{
this.Dots[i].sprite = this.DotLight;
}
else
{
if (i == 1)
{
this.Ship.transform.localPosition = this.PathPoints[0];
this.Ship.transform.eulerAngles = new Vector3(0f, 0f, Vector2.up.AngleSigned(this.PathPoints[1] - this.PathPoints[0]));
}
this.Stars[i] = UnityEngine.Object.Instantiate<CourseStarBehaviour>(this.StarPrefab, base.transform);
this.Stars[i].transform.localPosition = this.PathPoints[i];
if (i == this.PathPoints.Length - 1)
{
this.Destination.transform.localPosition = this.PathPoints[i];
}
}
}
this.Path.positionCount = this.PathPoints.Length;
this.Path.SetPositions(this.PathPoints);
}
public void FixedUpdate()
{
float num = this.Converter.GetFloat(this.MyNormTask.Data);
int num2 = (int)num;
Vector2 b = this.PathPoints[num2];
this.myController.Update();
DragState dragState = this.myController.CheckDrag(this.Ship, false);
if (dragState != DragState.NoTouch)
{
if (dragState == DragState.Dragging)
{
if (num < (float)(this.PathPoints.Length - 1))
{
Vector2 vector = this.PathPoints[num2 + 1] - b;
Vector2 a = new Vector2(1f, vector.y / vector.x);
Vector2 vector2 = base.transform.InverseTransformPoint(this.myController.DragPosition) - b;
if (vector2.x > 0f)
{
Vector2 vector3 = a * vector2.x;
if (Mathf.Abs(vector3.y - vector2.y) < 0.5f)
{
num = (float)num2 + Mathf.Min(1f, vector2.x / vector.x);
Vector3 localPosition = vector3 + b;
localPosition.z = -1f;
this.Ship.transform.localPosition = localPosition;
this.Ship.transform.localPosition = localPosition;
this.Ship.transform.eulerAngles = new Vector3(0f, 0f, Vector2.up.AngleSigned(vector));
}
else
{
this.myController.Reset();
}
}
}
else
{
Vector3 localPosition2 = this.PathPoints[this.PathPoints.Length - 1];
localPosition2.z = -1f;
this.Ship.transform.localPosition = localPosition2;
}
}
}
else if (num < (float)(this.PathPoints.Length - 1))
{
Vector2 vector4 = this.PathPoints[num2 + 1] - b;
Vector2 a2 = new Vector2(1f, vector4.y / vector4.x);
num = Mathf.Max((float)num2, Mathf.Lerp(num, (float)num2, Time.deltaTime * 5f));
Vector3 localPosition3 = a2 * (num - (float)num2) + b;
localPosition3.z = -1f;
this.Ship.transform.localPosition = localPosition3;
}
else
{
Vector3 localPosition4 = this.PathPoints[this.PathPoints.Length - 1];
localPosition4.z = -1f;
this.Ship.transform.localPosition = localPosition4;
}
if ((int)num > num2 && this.Stars[num2 + 1])
{
UnityEngine.Object.Destroy(this.Stars[num2 + 1].gameObject);
this.Dots[num2 + 1].sprite = this.DotLight;
if (num2 == this.PathPoints.Length - 2)
{
if (Constants.ShouldPlaySfx())
{
SoundManager.Instance.PlaySound(this.SetCourseLastSound, false, 1f).volume = 0.7f;
}
this.Destination.Speed *= 5f;
this.MyNormTask.NextStep();
base.StartCoroutine(base.CoStartClose(0.75f));
}
else if (Constants.ShouldPlaySfx())
{
SoundManager.Instance.PlaySound(this.SetCourseSound, false, 1f).volume = 0.7f;
}
}
this.Converter.GetBytes(num, this.MyNormTask.Data);
this.SetLineDivision(num);
}
private void SetLineDivision(float curVec)
{
int num = (int)curVec;
float num2 = 0f;
int num3 = 0;
while ((float)num3 <= curVec && num3 < this.PathPoints.Length - 1)
{
float num4 = Vector2.Distance(this.PathPoints[num3], this.PathPoints[num3 + 1]);
if (num3 == num)
{
num4 *= curVec - (float)num3;
}
num2 += num4;
num3++;
}
this.lineTimer -= Time.fixedDeltaTime;
Vector2 value = new Vector2(this.lineTimer, 0f);
this.Path.material.SetTextureOffset("_MainTex", value);
this.Path.material.SetTextureOffset("_AltTex", value);
this.Path.material.SetFloat("_Perc", num2 + this.lineTimer / 8f);
}
}
|