Elin Modding Docs Doc
Loading...
Searching...
No Matches
SpriteBasedLaser.cs
1using System;
2using DG.Tweening;
3using UnityEngine;
4
5// Token: 0x02000123 RID: 291
6public class SpriteBasedLaser : MonoBehaviour
7{
8 // Token: 0x14000001 RID: 1
9 // (add) Token: 0x060007DB RID: 2011 RVA: 0x00032AE8 File Offset: 0x00030CE8
10 // (remove) Token: 0x060007DC RID: 2012 RVA: 0x00032B20 File Offset: 0x00030D20
11 public event SpriteBasedLaser.LaserHitTriggerHandler OnLaserHitTriggered;
12
13 // Token: 0x060007DD RID: 2013 RVA: 0x00032B58 File Offset: 0x00030D58
14 public void Play(Vector3 to)
15 {
16 base.transform.position = base.transform.position.SetZ(0f);
17 Vector3 vector = to.SetZ(0f) + this.fix + new Vector3(0.2f, 0.2f, 0f).Random();
18 this.dest = vector;
19 this.dest2 = vector;
20 this.hitSparkEmission = this.hitSparkParticleSystem.emission;
21 this.gameObjectCached = base.gameObject;
22 if (this.laserLineRendererArc != null)
23 {
24 this.laserLineRendererArc.SetVertexCount(this.laserArcSegments);
25 }
26 this.startLaserLength = this.maxLaserLength;
27 if (this.laserOscillationPositionerScript != null)
28 {
29 this.laserOscillationPositionerScript.radius = this.oscillationThreshold;
30 }
31 this.Update();
32 this.Update();
33 this.trail.localScale = this.middleGoPiece.transform.localScale;
34 this.trail.rotation = this.middleGoPiece.transform.rotation;
35 this.trail.position = this.middleGoPiece.transform.position;
36 DOTweenAnimation[] array = this.anime;
37 for (int i = 0; i < array.Length; i++)
38 {
39 array[i].DOPlay();
40 }
41 }
42
43 // Token: 0x060007DE RID: 2014 RVA: 0x00032CAC File Offset: 0x00030EAC
44 private void OscillateLaserParts(float currentLaserDistance)
45 {
46 if (this.laserOscillationPositionerScript == null)
47 {
48 return;
49 }
50 this.lerpYValue = Mathf.Lerp(this.middleGoPiece.transform.localPosition.y, this.laserOscillationPositionerScript.randomPointInCircle.y, Time.deltaTime * this.oscillationSpeed);
51 if (this.startGoPiece != null && this.middleGoPiece != null)
52 {
53 Vector2 b = new Vector2(this.startGoPiece.transform.localPosition.x, this.laserOscillationPositionerScript.randomPointInCircle.y);
54 Vector2 v = Vector2.Lerp(this.startGoPiece.transform.localPosition, b, Time.deltaTime * this.oscillationSpeed);
55 this.startGoPiece.transform.localPosition = v;
56 Vector2 v2 = new Vector2(currentLaserDistance / 2f + this.startSpriteWidth / 4f, this.lerpYValue);
57 this.middleGoPiece.transform.localPosition = v2;
58 }
59 if (this.endGoPiece != null)
60 {
61 Vector2 v3 = new Vector2(currentLaserDistance + this.startSpriteWidth / 2f, this.lerpYValue);
62 this.endGoPiece.transform.localPosition = v3;
63 }
64 }
65
66 // Token: 0x060007DF RID: 2015 RVA: 0x00032E08 File Offset: 0x00031008
67 private void SetLaserArcVertices(float distancePoint, bool useHitPoint)
68 {
69 for (int i = 1; i < this.laserArcSegments; i++)
70 {
71 float y = Mathf.Clamp(Mathf.Sin((float)i + Time.time * UnityEngine.Random.Range(0.5f, 1.3f)), -this.laserArcMax + UnityEngine.Random.RandomRange(0f, this.laserArcMax * 0.5f), this.laserArcMax + UnityEngine.Random.RandomRange(0f, this.laserArcMax * 0.5f));
72 Vector2 v = new Vector2((float)i * 1.2f * this.arcNum2, y);
73 if (useHitPoint && i == this.laserArcSegments - 1)
74 {
75 this.laserLineRendererArc.SetPosition(i, new Vector2(distancePoint, 0f));
76 }
77 else
78 {
79 this.laserLineRendererArc.SetPosition(i, v);
80 }
81 }
82 }
83
84 // Token: 0x060007E0 RID: 2016 RVA: 0x00032EE0 File Offset: 0x000310E0
85 private void Update()
86 {
87 if (this.gameObjectCached != null)
88 {
89 this.middleGoPiece.transform.localScale = new Vector3(this.maxLaserLength - this.startSpriteWidth + 0.2f, this.middleGoPiece.transform.localScale.y, this.middleGoPiece.transform.localScale.z);
90 if (this.oscillateLaser)
91 {
92 this.OscillateLaserParts(this.maxLaserLength);
93 }
94 else
95 {
96 if (this.middleGoPiece != null)
97 {
98 this.middleGoPiece.transform.localPosition = new Vector2(this.maxLaserLength / 2f + this.startSpriteWidth / 4f, this.lerpYValue);
99 }
100 if (this.endGoPiece != null)
101 {
102 this.endGoPiece.transform.localPosition = new Vector3(this.maxLaserLength + this.startSpriteWidth / 2f, 0f, 0f) + this.fixTip;
103 }
104 }
105 if (this.laserRotationEnabled)
106 {
107 Vector3 vector = this.dest2 - this.gameObjectCached.transform.position;
108 this.laserAngle = Mathf.Atan2(vector.y, vector.x);
109 if (this.laserAngle < 0f)
110 {
111 this.laserAngle = 6.2831855f + this.laserAngle;
112 }
113 float angle = this.laserAngle * 57.29578f;
114 if (this.lerpLaserRotation)
115 {
116 base.transform.rotation = Quaternion.Slerp(base.transform.rotation, Quaternion.AngleAxis(angle, base.transform.forward), Time.deltaTime * this.turningRate);
117 }
118 else
119 {
120 base.transform.rotation = Quaternion.AngleAxis(angle, base.transform.forward);
121 }
122 }
123 this.maxLaserLength = Vector2.Distance(this.dest, base.transform.position) + this.startSpriteWidth / 4f + this.fix2.x;
124 if (this.hitSparkParticleSystem != null)
125 {
126 this.hitSparkParticleSystem.transform.position = this.dest;
127 this.hitSparkEmission.enabled = true;
128 }
129 if (this.useArc)
130 {
131 if (!this.laserLineRendererArc.enabled)
132 {
133 this.laserLineRendererArc.enabled = true;
134 }
135 this.SetLaserArcVertices(this.maxLaserLength, true);
136 this.SetLaserArcSegmentLength();
137 return;
138 }
139 if (this.laserLineRendererArc.enabled)
140 {
141 this.laserLineRendererArc.enabled = false;
142 }
143 }
144 }
145
146 // Token: 0x060007E1 RID: 2017 RVA: 0x00033180 File Offset: 0x00031380
147 private void SetLaserArcSegmentLength()
148 {
149 int vertexCount = Mathf.Abs((int)this.maxLaserLength) * (int)this.arcNum;
150 this.laserLineRendererArc.SetVertexCount(vertexCount);
151 this.laserArcSegments = vertexCount;
152 }
153
154 // Token: 0x040007EA RID: 2026
155 public Material mat;
156
157 // Token: 0x040007EB RID: 2027
158 public Vector3 dest;
159
160 // Token: 0x040007EC RID: 2028
161 public Vector3 fixTip;
162
163 // Token: 0x040007ED RID: 2029
164 public Vector3 dest2;
165
166 // Token: 0x040007EE RID: 2030
167 public Vector3 fix;
168
169 // Token: 0x040007EF RID: 2031
170 public Vector3 fix2;
171
172 // Token: 0x040007F0 RID: 2032
173 public float arcNum;
174
175 // Token: 0x040007F1 RID: 2033
176 public float arcNum2;
177
178 // Token: 0x040007F2 RID: 2034
179 public DOTweenAnimation[] anime;
180
181 // Token: 0x040007F3 RID: 2035
182 public LineRenderer laserLineRendererArc;
183
184 // Token: 0x040007F4 RID: 2036
185 public int laserArcSegments = 20;
186
187 // Token: 0x040007F5 RID: 2037
188 public RandomPositionMover laserOscillationPositionerScript;
189
190 // Token: 0x040007F6 RID: 2038
191 public bool oscillateLaser;
192
193 // Token: 0x040007F7 RID: 2039
194 public float maxLaserLength = 20f;
195
196 // Token: 0x040007F8 RID: 2040
197 public float oscillationSpeed = 1f;
198
199 // Token: 0x040007F9 RID: 2041
200 public GameObject targetGo;
201
202 // Token: 0x040007FA RID: 2042
203 public ParticleSystem hitSparkParticleSystem;
204
205 // Token: 0x040007FB RID: 2043
206 public float laserArcMax;
207
208 // Token: 0x040007FC RID: 2044
209 public float maxLaserRaycastDistance;
210
211 // Token: 0x040007FD RID: 2045
212 public bool laserRotationEnabled;
213
214 // Token: 0x040007FE RID: 2046
215 public bool lerpLaserRotation;
216
217 // Token: 0x040007FF RID: 2047
218 public float turningRate = 3f;
219
220 // Token: 0x04000800 RID: 2048
221 public float collisionTriggerInterval = 0.25f;
222
223 // Token: 0x04000801 RID: 2049
224 public LayerMask mask;
225
226 // Token: 0x04000803 RID: 2051
227 public bool useArc;
228
229 // Token: 0x04000804 RID: 2052
230 public float oscillationThreshold = 0.2f;
231
232 // Token: 0x04000805 RID: 2053
233 private GameObject gameObjectCached;
234
235 // Token: 0x04000806 RID: 2054
236 private float laserAngle;
237
238 // Token: 0x04000807 RID: 2055
239 private float lerpYValue;
240
241 // Token: 0x04000808 RID: 2056
242 private float startLaserLength;
243
244 // Token: 0x04000809 RID: 2057
245 public Transform trail;
246
247 // Token: 0x0400080A RID: 2058
248 public GameObject startGoPiece;
249
250 // Token: 0x0400080B RID: 2059
251 public GameObject middleGoPiece;
252
253 // Token: 0x0400080C RID: 2060
254 public GameObject endGoPiece;
255
256 // Token: 0x0400080D RID: 2061
257 private float startSpriteWidth;
258
259 // Token: 0x0400080E RID: 2062
260 private bool waitingForTriggerTime;
261
262 // Token: 0x0400080F RID: 2063
263 private ParticleSystem.EmissionModule hitSparkEmission;
264
265 // Token: 0x02000851 RID: 2129
266 // (Invoke) Token: 0x060039EE RID: 14830
267 public delegate void LaserHitTriggerHandler(RaycastHit2D hitInfo);
268}