Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
SpriteBasedLaser.cs
Go to the documentation of this file.
1using System;
2using DG.Tweening;
3using UnityEngine;
4
5public class SpriteBasedLaser : MonoBehaviour
6{
7 public delegate void LaserHitTriggerHandler(RaycastHit2D hitInfo);
8
9 public Material mat;
10
11 public Vector3 dest;
12
13 public Vector3 fixTip;
14
15 public Vector3 dest2;
16
17 public Vector3 fix;
18
19 public Vector3 fix2;
20
21 public float arcNum;
22
23 public float arcNum2;
24
25 public DOTweenAnimation[] anime;
26
27 public LineRenderer laserLineRendererArc;
28
29 public int laserArcSegments = 20;
30
32
33 public bool oscillateLaser;
34
35 public float maxLaserLength = 20f;
36
37 public float oscillationSpeed = 1f;
38
39 public GameObject targetGo;
40
41 public ParticleSystem hitSparkParticleSystem;
42
43 public float laserArcMax;
44
46
48
49 public bool lerpLaserRotation;
50
51 public float turningRate = 3f;
52
53 public float collisionTriggerInterval = 0.25f;
54
55 public LayerMask mask;
56
57 public bool useArc;
58
59 public float oscillationThreshold = 0.2f;
60
61 private GameObject gameObjectCached;
62
63 private float laserAngle;
64
65 private float lerpYValue;
66
67 private float startLaserLength;
68
69 public Transform trail;
70
71 public GameObject startGoPiece;
72
73 public GameObject middleGoPiece;
74
75 public GameObject endGoPiece;
76
77 private float startSpriteWidth;
78
80
81 private ParticleSystem.EmissionModule hitSparkEmission;
82
84
85 public void Play(Vector3 to)
86 {
87 base.transform.position = base.transform.position.SetZ(0f);
88 dest2 = (dest = to.SetZ(0f) + fix + new Vector3(0.2f, 0.2f, 0f).Random());
90 gameObjectCached = base.gameObject;
91 if (laserLineRendererArc != null)
92 {
94 }
97 {
98 laserOscillationPositionerScript.radius = oscillationThreshold;
99 }
100 Update();
101 Update();
102 trail.localScale = middleGoPiece.transform.localScale;
103 trail.rotation = middleGoPiece.transform.rotation;
104 trail.position = middleGoPiece.transform.position;
105 DOTweenAnimation[] array = anime;
106 for (int i = 0; i < array.Length; i++)
107 {
108 array[i].DOPlay();
109 }
110 }
111
112 private void OscillateLaserParts(float currentLaserDistance)
113 {
115 {
116 lerpYValue = Mathf.Lerp(middleGoPiece.transform.localPosition.y, laserOscillationPositionerScript.randomPointInCircle.y, Time.deltaTime * oscillationSpeed);
117 if (startGoPiece != null && middleGoPiece != null)
118 {
119 Vector2 vector = Vector2.Lerp(b: new Vector2(startGoPiece.transform.localPosition.x, laserOscillationPositionerScript.randomPointInCircle.y), a: startGoPiece.transform.localPosition, t: Time.deltaTime * oscillationSpeed);
120 startGoPiece.transform.localPosition = vector;
121 Vector2 vector2 = new Vector2(currentLaserDistance / 2f + startSpriteWidth / 4f, lerpYValue);
122 middleGoPiece.transform.localPosition = vector2;
123 }
124 if (endGoPiece != null)
125 {
126 Vector2 vector3 = new Vector2(currentLaserDistance + startSpriteWidth / 2f, lerpYValue);
127 endGoPiece.transform.localPosition = vector3;
128 }
129 }
130 }
131
132 private void SetLaserArcVertices(float distancePoint, bool useHitPoint)
133 {
134 for (int i = 1; i < laserArcSegments; i++)
135 {
136 float y = Mathf.Clamp(Mathf.Sin((float)i + Time.time * UnityEngine.Random.Range(0.5f, 1.3f)), 0f - laserArcMax + UnityEngine.Random.RandomRange(0f, laserArcMax * 0.5f), laserArcMax + UnityEngine.Random.RandomRange(0f, laserArcMax * 0.5f));
137 Vector2 vector = new Vector2((float)i * 1.2f * arcNum2, y);
138 if (useHitPoint && i == laserArcSegments - 1)
139 {
140 laserLineRendererArc.SetPosition(i, new Vector2(distancePoint, 0f));
141 }
142 else
143 {
144 laserLineRendererArc.SetPosition(i, vector);
145 }
146 }
147 }
148
149 private void Update()
150 {
151 if (!(gameObjectCached != null))
152 {
153 return;
154 }
155 middleGoPiece.transform.localScale = new Vector3(maxLaserLength - startSpriteWidth + 0.2f, middleGoPiece.transform.localScale.y, middleGoPiece.transform.localScale.z);
156 if (oscillateLaser)
157 {
159 }
160 else
161 {
162 if (middleGoPiece != null)
163 {
164 middleGoPiece.transform.localPosition = new Vector2(maxLaserLength / 2f + startSpriteWidth / 4f, lerpYValue);
165 }
166 if (endGoPiece != null)
167 {
168 endGoPiece.transform.localPosition = new Vector3(maxLaserLength + startSpriteWidth / 2f, 0f, 0f) + fixTip;
169 }
170 }
172 {
173 Vector3 vector = dest2 - gameObjectCached.transform.position;
174 laserAngle = Mathf.Atan2(vector.y, vector.x);
175 if (laserAngle < 0f)
176 {
177 laserAngle = MathF.PI * 2f + laserAngle;
178 }
179 float angle = laserAngle * 57.29578f;
181 {
182 base.transform.rotation = Quaternion.Slerp(base.transform.rotation, Quaternion.AngleAxis(angle, base.transform.forward), Time.deltaTime * turningRate);
183 }
184 else
185 {
186 base.transform.rotation = Quaternion.AngleAxis(angle, base.transform.forward);
187 }
188 }
189 maxLaserLength = Vector2.Distance(dest, base.transform.position) + startSpriteWidth / 4f + fix2.x;
190 if (hitSparkParticleSystem != null)
191 {
192 hitSparkParticleSystem.transform.position = dest;
193 hitSparkEmission.enabled = true;
194 }
195 if (useArc)
196 {
197 if (!laserLineRendererArc.enabled)
198 {
199 laserLineRendererArc.enabled = true;
200 }
201 SetLaserArcVertices(maxLaserLength, useHitPoint: true);
203 }
204 else if (laserLineRendererArc.enabled)
205 {
206 laserLineRendererArc.enabled = false;
207 }
208 }
209
211 {
212 int vertexCount = Mathf.Abs((int)maxLaserLength) * (int)arcNum;
213 laserLineRendererArc.SetVertexCount(vertexCount);
214 laserArcSegments = vertexCount;
215 }
216}
void SetLaserArcVertices(float distancePoint, bool useHitPoint)
void OscillateLaserParts(float currentLaserDistance)
ParticleSystem hitSparkParticleSystem
void Play(Vector3 to)
void SetLaserArcSegmentLength()
float collisionTriggerInterval
DOTweenAnimation[] anime
GameObject endGoPiece
LineRenderer laserLineRendererArc
GameObject gameObjectCached
GameObject startGoPiece
GameObject middleGoPiece
LaserHitTriggerHandler OnLaserHitTriggered
delegate void LaserHitTriggerHandler(RaycastHit2D hitInfo)
ParticleSystem.EmissionModule hitSparkEmission
RandomPositionMover laserOscillationPositionerScript