2021-12-28 07:38:55 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_Spaceball
|
2021-12-28 07:38:55 +00:00
|
|
|
{
|
|
|
|
public class Alien : MonoBehaviour
|
|
|
|
{
|
|
|
|
private Animator anim;
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
private double showBeat = 0;
|
2021-12-28 07:38:55 +00:00
|
|
|
private bool isShowing = false;
|
2023-05-28 18:48:41 +00:00
|
|
|
private bool isHiding = false;
|
2021-12-28 07:38:55 +00:00
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
const string IdleAnim = "AlienIdle";
|
|
|
|
const string SwingAnim = "AlienSwing";
|
|
|
|
const string ShowAnim = "AlienShow";
|
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void Awake()
|
2021-12-28 07:38:55 +00:00
|
|
|
{
|
|
|
|
anim = GetComponent<Animator>();
|
2023-01-25 15:29:31 +00:00
|
|
|
anim.Play(IdleAnim, 0, 0);
|
2021-12-28 07:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-05-28 18:48:41 +00:00
|
|
|
if (Conductor.instance.isPlaying && !isShowing && !isHiding)
|
2021-12-28 07:38:55 +00:00
|
|
|
{
|
2023-01-25 15:29:31 +00:00
|
|
|
anim.Play(SwingAnim, 0, Conductor.instance.GetLoopPositionFromBeat(0, 1f));
|
2021-12-28 07:38:55 +00:00
|
|
|
anim.speed = 0;
|
|
|
|
}
|
2023-05-28 18:48:41 +00:00
|
|
|
else if (!Conductor.instance.isPlaying && !isHiding)
|
2021-12-28 07:38:55 +00:00
|
|
|
{
|
2023-01-25 15:29:31 +00:00
|
|
|
anim.Play(IdleAnim, 0, 0);
|
2021-12-28 07:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isShowing)
|
|
|
|
{
|
2022-02-03 22:20:26 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(showBeat, 1f);
|
2023-05-28 18:48:41 +00:00
|
|
|
if (!isHiding) anim.Play(ShowAnim, 0, normalizedBeat);
|
2021-12-28 07:38:55 +00:00
|
|
|
anim.speed = 0;
|
|
|
|
|
|
|
|
if (normalizedBeat >= 2)
|
|
|
|
{
|
|
|
|
isShowing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void Show(double showBeat, bool hide)
|
2021-12-28 07:38:55 +00:00
|
|
|
{
|
|
|
|
isShowing = true;
|
|
|
|
this.showBeat = showBeat;
|
2023-05-28 18:48:41 +00:00
|
|
|
isHiding = hide;
|
|
|
|
if (hide) anim.Play("AlienHide", 0, 0);
|
2021-12-28 07:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|