summaryrefslogtreecommitdiff
path: root/CodeAnimation.cs
blob: a4d6244026ae7105def3e484e5f44ac8ce312081 (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
using System.Collections;
using UnityEngine;

public class CodeAnimation : MonoBehaviour
{
	public bool x = true;

	public bool y = true;

	public bool z = true;

	public AnimationCurve curve;

	public bool loop;

	public bool playOnAwake;

	private void Start()
	{
		if (playOnAwake)
		{
			Play();
		}
	}

	private void Update()
	{
	}

	public void Play()
	{
		StartCoroutine(PlayAnimation());
	}

	private IEnumerator PlayAnimation()
	{
		float t = 0f;
		float lastFrameValue = curve.Evaluate(0f);
		while (t < curve.keys[curve.length - 1].time)
		{
			t += Time.deltaTime;
			float deltaValue = curve.Evaluate(t) - lastFrameValue;
			lastFrameValue = curve.Evaluate(t);
			if (x)
			{
				base.transform.localScale = new Vector3(base.transform.localScale.x + deltaValue, base.transform.localScale.y, base.transform.localScale.z);
			}
			if (y)
			{
				base.transform.localScale = new Vector3(base.transform.localScale.x, base.transform.localScale.y + deltaValue, base.transform.localScale.z);
			}
			if (z)
			{
				base.transform.localScale = new Vector3(base.transform.localScale.x, base.transform.localScale.y, base.transform.localScale.z + deltaValue);
			}
			yield return null;
		}
		if (loop)
		{
			Play();
		}
	}
}