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

public class FingerBehaviour : MonoBehaviour
{
	public SpriteRenderer Finger;

	public SpriteRenderer Click;

	public float liftedAngle = -20f;

	public static class Quadratic
	{
		public static float InOut(float k)
		{
			if (k < 0f)
			{
				k = 0f;
			}
			if (k > 1f)
			{
				k = 1f;
			}
			if ((k *= 2f) < 1f)
			{
				return 0.5f * k * k;
			}
			return -0.5f * ((k -= 1f) * (k - 2f) - 1f);
		}
	}

	public IEnumerator DoClick(float duration)
	{
		for (float time = 0f; time < duration; time += Time.deltaTime)
		{
			float num = time / duration;
			if (num < 0.4f)
			{
				float num2 = num / 0.4f;
				num2 = num2 * 2f - 1f;
				if (num2 < 0f)
				{
					float fingerAngle = Mathf.Lerp(this.liftedAngle, this.liftedAngle * 2f, 1f + Mathf.Abs(num2));
					this.SetFingerAngle(fingerAngle);
				}
				else
				{
					float fingerAngle2 = Mathf.Lerp(this.liftedAngle * 2f, 0f, num2);
					this.SetFingerAngle(fingerAngle2);
				}
			}
			else if (num < 0.7f)
			{
				this.ClickOn();
			}
			else
			{
				float t = (num - 0.7f) / 0.3f;
				this.Click.enabled = false;
				float fingerAngle3 = Mathf.Lerp(0f, this.liftedAngle, t);
				this.SetFingerAngle(fingerAngle3);
			}
			yield return null;
		}
		this.ClickOff();
		yield break;
	}

	private void SetFingerAngle(float angle)
	{
		this.Finger.transform.localRotation = Quaternion.Euler(0f, 0f, angle);
	}

	public void ClickOff()
	{
		this.Click.enabled = false;
		this.SetFingerAngle(this.liftedAngle);
	}

	public void ClickOn()
	{
		this.Click.enabled = true;
		this.SetFingerAngle(0f);
	}

	public IEnumerator MoveTo(Vector2 target, float duration)
	{
		Vector3 startPos = base.transform.position;
		Vector3 targetPos = target;
		targetPos.z = startPos.z;
		for (float time = 0f; time < duration; time += Time.deltaTime)
		{
			float t = time / duration;
			base.transform.position = Vector3.Lerp(startPos, targetPos, t);
			yield return null;
		}
		base.transform.position = targetPos;
		yield break;
	}
}