summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/CrystalBehaviour.cs
blob: ebb7b2bb57b9d207aeb023b6dc3f7e0f6354159f (plain)
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
using System;
using System.Collections;
using UnityEngine;

public class CrystalBehaviour : MonoBehaviour
{
	public CrystalBehaviour Above;

	public CrystalBehaviour Below;

	public CrystalBehaviour.Parentness ParentSide;

	public SpriteRenderer Renderer;

	public BoxCollider2D Collider;

	public FloatRange Padding;

	private const float Speed = 15f;

	private const float FloatMag = 0.05f;

	private const float FloatSpeed = 0.35f;

	public enum Parentness
	{
		None,
		Above,
		Below
	}

	private void Update()
	{
		Vector3 position = base.transform.position;
		Vector3 vector;
		if (this.ParentSide == CrystalBehaviour.Parentness.Above)
		{
			if (!this.Above)
			{
				return;
			}
			vector = this.Above.transform.position - new Vector3(0f, this.Above.Padding.min + this.Padding.max, 0f);
		}
		else
		{
			if (this.ParentSide != CrystalBehaviour.Parentness.Below)
			{
				return;
			}
			if (!this.Below)
			{
				return;
			}
			vector = this.Below.transform.position + new Vector3(0f, this.Below.Padding.max + this.Padding.min, 0f);
		}
		float num = Time.time / 0.35f;
		vector.x += (Mathf.PerlinNoise(num, position.z * 20f) * 2f - 1f) * 0.05f;
		vector.y += (Mathf.PerlinNoise(position.z * 20f, num) * 2f - 1f) * 0.05f;
		vector.z = position.z;
		position.x = Mathf.SmoothStep(position.x, vector.x, Time.deltaTime * 15f);
		position.y = Mathf.SmoothStep(position.y, vector.y, Time.deltaTime * 15f);
		base.transform.position = position;
	}

	public void FlashUp(float delay = 0f)
	{
		base.StopAllCoroutines();
		base.StartCoroutine(CrystalBehaviour.Flash(this, delay));
		if (this.Above)
		{
			this.Above.FlashUp(delay + 0.1f);
		}
	}

	public void FlashDown(float delay = 0f)
	{
		base.StopAllCoroutines();
		base.StartCoroutine(CrystalBehaviour.Flash(this, delay));
		if (this.Below)
		{
			this.Below.FlashDown(delay + 0.1f);
		}
	}

	private static IEnumerator Flash(CrystalBehaviour c, float delay)
	{
		for (float time = 0f; time < delay; time += Time.deltaTime)
		{
			yield return null;
		}
		Color col = Color.clear;
		for (float time = 0f; time < 0.1f; time += Time.deltaTime)
		{
			float t = time / 0.1f;
			col.r = (col.g = (col.b = Mathf.Lerp(0f, 1f, t)));
			c.Renderer.material.SetColor("_AddColor", col);
			yield return null;
		}
		for (float time = 0f; time < 0.1f; time += Time.deltaTime)
		{
			float t2 = time / 0.1f;
			col.r = (col.g = (col.b = Mathf.Lerp(1f, 0f, t2)));
			c.Renderer.material.SetColor("_AddColor", col);
			yield return null;
		}
		col.r = (col.g = (col.b = 0f));
		c.Renderer.material.SetColor("_AddColor", col);
		yield break;
	}
}