diff options
| author | chai <215380520@qq.com> | 2023-11-02 11:51:31 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2023-11-02 11:51:31 +0800 |
| commit | 7f493f682503f5186308de7b8f74b5b49233cfe4 (patch) | |
| tree | 8a91e2056bc79788ee4735dce88b8d516ba12beb /GameCode/UnitCommandRadiusAnimation.cs | |
+init
Diffstat (limited to 'GameCode/UnitCommandRadiusAnimation.cs')
| -rw-r--r-- | GameCode/UnitCommandRadiusAnimation.cs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/GameCode/UnitCommandRadiusAnimation.cs b/GameCode/UnitCommandRadiusAnimation.cs new file mode 100644 index 0000000..9549100 --- /dev/null +++ b/GameCode/UnitCommandRadiusAnimation.cs @@ -0,0 +1,69 @@ +using System.Collections; +using UnityEngine; + +public class UnitCommandRadiusAnimation : MonoBehaviour +{ + public AnimationCurve animationCurve; + + public AnimationCurve hideCurve; + + public float animationTime; + + public float hideTime = 0.25f; + + private bool active; + + public bool Active => active; + + private void Start() + { + if (!active) + { + base.gameObject.SetActive(value: false); + } + } + + public void Activate() + { + active = true; + StopAllCoroutines(); + base.gameObject.SetActive(value: true); + StartCoroutine(AnimateShow()); + } + + public void Deactivate() + { + active = false; + if (base.gameObject.activeSelf) + { + StopAllCoroutines(); + StartCoroutine(AnimateHide()); + } + } + + private IEnumerator AnimateShow() + { + float timer = 0f; + while (timer <= animationTime) + { + timer += Time.deltaTime; + base.transform.localScale = Vector3.one * animationCurve.Evaluate(Mathf.InverseLerp(0f, animationTime, timer)); + yield return null; + } + base.transform.localScale = Vector3.one; + } + + private IEnumerator AnimateHide() + { + Debug.Log("START ANIMATION"); + float timer = 0f; + while (timer <= hideTime) + { + timer += Time.deltaTime; + base.transform.localScale = Vector3.one * hideCurve.Evaluate(Mathf.InverseLerp(0f, hideTime, timer)); + yield return null; + } + base.transform.localScale = Vector3.zero; + base.gameObject.SetActive(value: false); + } +} |
