From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- CodeAnimation.cs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CodeAnimation.cs (limited to 'CodeAnimation.cs') diff --git a/CodeAnimation.cs b/CodeAnimation.cs new file mode 100644 index 0000000..a4d6244 --- /dev/null +++ b/CodeAnimation.cs @@ -0,0 +1,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(); + } + } +} -- cgit v1.1-26-g67d0