using System;
using UnityEngine;

// Token: 0x020000E5 RID: 229
[ExecuteInEditMode]
[RequireComponent(typeof(LineRenderer))]
public class LineWave : MonoBehaviour
{
	// Token: 0x0600150D RID: 5389 RVA: 0x00196008 File Offset: 0x00194208
	private void Awake()
	{
		this.lrComp = base.GetComponent<LineRenderer>();
		this.lrComp.useWorldSpace = false;
		this.lrComp.material = this.traceMaterial;
	}

	// Token: 0x0600150E RID: 5390 RVA: 0x00196034 File Offset: 0x00194234
	private void LateUpdate()
	{
		this.lrComp.startWidth = this.traceWidth;
		this.lrComp.endWidth = this.traceWidth;
		if (this.warpRandom <= 0f)
		{
			this.warpRandom = 0f;
		}
		if (this.size <= 2)
		{
			this.size = 2;
		}
		int num = this.size - 1;
		this.lrComp.positionCount = this.size;
		this.lengh /= base.transform.localScale.x;
		if (this.targetOptional)
		{
			this.origin = LineWave.Origins.Start;
			Vector3 position = this.targetOptional.transform.position;
			if (this.targetOptional.layer == 6)
			{
				position.y += 2f;
			}
			else
			{
				position.y -= 1f;
			}
			this.lengh = (base.transform.position - position).magnitude;
			base.transform.LookAt(position);
			base.transform.Rotate(this.altRotation, -90f, 0f);
			if (this.targetOptional && this.lengh > 60f)
			{
				this.lengh = 60f;
			}
		}
		if (this.traceMaterial == this.redMaterial && this.lrComp.material != this.redMaterial)
		{
			this.lrComp.material = this.redMaterial;
		}
		if (this.traceMaterial == this.greenMaterial && this.lrComp.material != this.greenMaterial)
		{
			this.lrComp.material = this.greenMaterial;
		}
		if (this.traceMaterial == this.blueMaterial && this.lrComp.material != this.blueMaterial)
		{
			this.lrComp.material = this.blueMaterial;
		}
		if (this.ampByFreq)
		{
			this.ampT = Mathf.Sin(this.freq * -1f * 3.1415927f);
		}
		else
		{
			this.ampT = 1f;
		}
		this.ampT *= this.amp;
		if (this.warp && this.warpInvert)
		{
			this.ampT /= 2f;
		}
		for (int i = 0; i < this.size; i++)
		{
			this.angle = 6.2831855f / (float)num * (float)i * this.freq * -1f;
			if (this.centered)
			{
				this.angle -= this.freq * -1f * 3.1415927f;
				if (this.centCrest)
				{
					this.angle -= 1.5707964f;
				}
			}
			else
			{
				this.centCrest = false;
			}
			this.walkShift -= (double)(this.walkAuto / (float)num * Time.deltaTime);
			this.angle += (float)this.walkShift - this.walkManual;
			this.sinAngle = Mathf.Sin(this.angle);
			if (this.spiral)
			{
				this.sinAngleZ = Mathf.Cos(this.angle);
			}
			else
			{
				this.sinAngleZ = 0f;
			}
			if (this.origin == LineWave.Origins.Start)
			{
				this.start = 0f;
			}
			else
			{
				this.start = this.lengh / 2f;
			}
			if (this.warp)
			{
				this.warpT = (float)(num - i);
				this.warpT /= (float)num;
				this.warpT = Mathf.Sin(3.1415927f * this.warpT * (this.warpRandom + 1f));
				if (this.warpInvert)
				{
					this.warpT = ((this.warpT == 0f) ? 1E+09f : (1f / this.warpT));
				}
				this.lrComp.SetPosition(i, new Vector3(this.lengh / (float)num * (float)i - this.start, this.sinAngle * this.ampT * this.warpT, this.sinAngleZ * this.ampT * this.warpT));
			}
			else
			{
				this.lrComp.SetPosition(i, new Vector3(this.lengh / (float)num * (float)i - this.start, this.sinAngle * this.ampT, this.sinAngleZ * this.ampT));
				this.warpInvert = false;
			}
			if (i == 1)
			{
				this.posVtx2 = new Vector3(this.lengh / (float)num * (float)i - this.start, this.sinAngle * this.ampT * this.warpT, this.sinAngleZ * this.ampT * this.warpT);
			}
			if (i == this.size - 2)
			{
				this.posVtxSizeMinusOne = new Vector3(this.lengh / (float)num * (float)i - this.start, this.sinAngle * this.ampT * this.warpT, this.sinAngleZ * this.ampT * this.warpT);
			}
		}
		if (this.warpInvert)
		{
			this.lrComp.SetPosition(0, this.posVtx2);
			this.lrComp.SetPosition(this.size - 1, this.posVtxSizeMinusOne);
		}
	}

	// Token: 0x040024AB RID: 9387
	private float ampT;

	// Token: 0x040024AC RID: 9388
	public Material traceMaterial;

	// Token: 0x040024AD RID: 9389
	public Material redMaterial;

	// Token: 0x040024AE RID: 9390
	public Material greenMaterial;

	// Token: 0x040024AF RID: 9391
	public Material blueMaterial;

	// Token: 0x040024B0 RID: 9392
	public float traceWidth = 0.3f;

	// Token: 0x040024B1 RID: 9393
	public GameObject targetOptional;

	// Token: 0x040024B2 RID: 9394
	public float altRotation;

	// Token: 0x040024B3 RID: 9395
	public LineWave.Origins origin;

	// Token: 0x040024B4 RID: 9396
	public int size = 300;

	// Token: 0x040024B5 RID: 9397
	public float lengh = 10f;

	// Token: 0x040024B6 RID: 9398
	public float freq = 2.5f;

	// Token: 0x040024B7 RID: 9399
	public float amp = 1f;

	// Token: 0x040024B8 RID: 9400
	public bool ampByFreq;

	// Token: 0x040024B9 RID: 9401
	public bool centered = true;

	// Token: 0x040024BA RID: 9402
	public bool centCrest = true;

	// Token: 0x040024BB RID: 9403
	public bool warp = true;

	// Token: 0x040024BC RID: 9404
	public bool warpInvert;

	// Token: 0x040024BD RID: 9405
	public float warpRandom;

	// Token: 0x040024BE RID: 9406
	public float walkManual;

	// Token: 0x040024BF RID: 9407
	public float walkAuto;

	// Token: 0x040024C0 RID: 9408
	public bool spiral;

	// Token: 0x040024C1 RID: 9409
	private float start;

	// Token: 0x040024C2 RID: 9410
	private float warpT;

	// Token: 0x040024C3 RID: 9411
	private float angle;

	// Token: 0x040024C4 RID: 9412
	private float sinAngle;

	// Token: 0x040024C5 RID: 9413
	private float sinAngleZ;

	// Token: 0x040024C6 RID: 9414
	private double walkShift;

	// Token: 0x040024C7 RID: 9415
	private Vector3 posVtx2;

	// Token: 0x040024C8 RID: 9416
	private Vector3 posVtxSizeMinusOne;

	// Token: 0x040024C9 RID: 9417
	private LineRenderer lrComp;

	// Token: 0x02000263 RID: 611
	public enum Origins
	{
		// Token: 0x040034A3 RID: 13475
		Start,
		// Token: 0x040034A4 RID: 13476
		Middle
	}
}
