11 public event SpriteBasedLaser.LaserHitTriggerHandler OnLaserHitTriggered;
14 public void Play(Vector3 to)
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();
20 this.hitSparkEmission = this.hitSparkParticleSystem.emission;
21 this.gameObjectCached = base.gameObject;
22 if (this.laserLineRendererArc !=
null)
24 this.laserLineRendererArc.SetVertexCount(this.laserArcSegments);
26 this.startLaserLength = this.maxLaserLength;
27 if (this.laserOscillationPositionerScript !=
null)
29 this.laserOscillationPositionerScript.radius = this.oscillationThreshold;
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++)
44 private void OscillateLaserParts(
float currentLaserDistance)
46 if (this.laserOscillationPositionerScript ==
null)
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)
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;
59 if (this.endGoPiece !=
null)
61 Vector2 v3 =
new Vector2(currentLaserDistance + this.startSpriteWidth / 2f, this.lerpYValue);
62 this.endGoPiece.transform.localPosition = v3;
67 private void SetLaserArcVertices(
float distancePoint,
bool useHitPoint)
69 for (
int i = 1; i < this.laserArcSegments; i++)
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)
75 this.laserLineRendererArc.SetPosition(i,
new Vector2(distancePoint, 0f));
79 this.laserLineRendererArc.SetPosition(i, v);
87 if (this.gameObjectCached !=
null)
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)
92 this.OscillateLaserParts(this.maxLaserLength);
96 if (this.middleGoPiece !=
null)
98 this.middleGoPiece.transform.localPosition =
new Vector2(this.maxLaserLength / 2f + this.startSpriteWidth / 4f, this.lerpYValue);
100 if (this.endGoPiece !=
null)
102 this.endGoPiece.transform.localPosition =
new Vector3(this.maxLaserLength + this.startSpriteWidth / 2f, 0f, 0f) + this.fixTip;
105 if (this.laserRotationEnabled)
107 Vector3 vector = this.dest2 - this.gameObjectCached.transform.position;
108 this.laserAngle = Mathf.Atan2(vector.y, vector.x);
109 if (this.laserAngle < 0f)
111 this.laserAngle = 6.2831855f + this.laserAngle;
113 float angle = this.laserAngle * 57.29578f;
114 if (this.lerpLaserRotation)
116 base.transform.rotation = Quaternion.Slerp(base.transform.rotation, Quaternion.AngleAxis(angle, base.transform.forward), Time.deltaTime *
this.turningRate);
120 base.transform.rotation = Quaternion.AngleAxis(angle, base.transform.forward);
123 this.maxLaserLength = Vector2.Distance(this.dest, base.transform.position) + this.startSpriteWidth / 4f + this.fix2.x;
124 if (this.hitSparkParticleSystem !=
null)
126 this.hitSparkParticleSystem.transform.position = this.dest;
127 this.hitSparkEmission.enabled =
true;
131 if (!this.laserLineRendererArc.enabled)
133 this.laserLineRendererArc.enabled =
true;
135 this.SetLaserArcVertices(this.maxLaserLength,
true);
136 this.SetLaserArcSegmentLength();
139 if (this.laserLineRendererArc.enabled)
141 this.laserLineRendererArc.enabled =
false;
147 private void SetLaserArcSegmentLength()
149 int vertexCount = Mathf.Abs((
int)this.maxLaserLength) * (int)this.arcNum;
150 this.laserLineRendererArc.SetVertexCount(vertexCount);
151 this.laserArcSegments = vertexCount;
161 public Vector3 fixTip;
164 public Vector3 dest2;
176 public float arcNum2;
179 public DOTweenAnimation[] anime;
182 public LineRenderer laserLineRendererArc;
185 public int laserArcSegments = 20;
191 public bool oscillateLaser;
194 public float maxLaserLength = 20f;
197 public float oscillationSpeed = 1f;
200 public GameObject targetGo;
203 public ParticleSystem hitSparkParticleSystem;
206 public float laserArcMax;
209 public float maxLaserRaycastDistance;
212 public bool laserRotationEnabled;
215 public bool lerpLaserRotation;
218 public float turningRate = 3f;
221 public float collisionTriggerInterval = 0.25f;
224 public LayerMask mask;
230 public float oscillationThreshold = 0.2f;
233 private GameObject gameObjectCached;
236 private float laserAngle;
239 private float lerpYValue;
242 private float startLaserLength;
245 public Transform trail;
248 public GameObject startGoPiece;
251 public GameObject middleGoPiece;
254 public GameObject endGoPiece;
257 private float startSpriteWidth;
260 private bool waitingForTriggerTime;
263 private ParticleSystem.EmissionModule hitSparkEmission;
267 public delegate
void LaserHitTriggerHandler(RaycastHit2D hitInfo);