2023-03-11 04:51:22 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
using HeavenStudio.Games;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Common
|
|
|
|
{
|
|
|
|
public class SkillStarManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
public enum StarState
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
In,
|
|
|
|
Collected,
|
|
|
|
Out
|
|
|
|
}
|
|
|
|
public static SkillStarManager instance { get; private set; }
|
|
|
|
[SerializeField] private Animator starAnim;
|
|
|
|
[SerializeField] private ParticleSystem starParticle;
|
|
|
|
|
2024-04-10 05:05:47 +00:00
|
|
|
public double StarTargetTime { get { return cond.GetUnSwungBeat(starStart + starLength); } }
|
2023-03-11 04:51:22 +00:00
|
|
|
public bool IsEligible { get; private set; }
|
2023-05-07 20:33:15 +00:00
|
|
|
public bool IsCollected { get { return state == StarState.Collected; } }
|
2023-03-11 04:51:22 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
double starStart = double.MaxValue;
|
2023-03-11 04:51:22 +00:00
|
|
|
float starLength = float.MaxValue;
|
|
|
|
StarState state = StarState.None;
|
|
|
|
Conductor cond;
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
2023-05-07 20:33:15 +00:00
|
|
|
public void Start()
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
|
|
|
cond = Conductor.instance;
|
2023-05-07 20:33:15 +00:00
|
|
|
instance = this;
|
2023-03-11 04:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (cond.songPositionInBeatsAsDouble > starStart && state == StarState.In)
|
|
|
|
{
|
2024-04-10 05:05:47 +00:00
|
|
|
double offset = cond.SecsToBeats(Minigame.AceEarlyTime() - 1, cond.GetBpmAtBeat(StarTargetTime));
|
|
|
|
if (cond.unswungSongPositionInBeatsAsDouble <= StarTargetTime + offset)
|
2023-03-11 04:51:22 +00:00
|
|
|
starAnim.DoScaledAnimation("StarIn", starStart, starLength + (float)offset);
|
|
|
|
else
|
|
|
|
starAnim.Play("StarIn", -1, 1f);
|
2024-04-10 05:05:47 +00:00
|
|
|
|
|
|
|
offset = cond.SecsToBeats(Minigame.AceLateTime() - 1, cond.GetBpmAtBeat(StarTargetTime));
|
|
|
|
if (cond.unswungSongPositionInBeatsAsDouble > StarTargetTime + offset)
|
2023-03-11 04:51:22 +00:00
|
|
|
KillStar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DoStarPreview()
|
|
|
|
{
|
|
|
|
if (starAnim == null) return;
|
|
|
|
starAnim.Play("StarJust", -1, 0.5f);
|
|
|
|
starAnim.speed = 0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetStarPreview()
|
|
|
|
{
|
|
|
|
if (starAnim == null) return;
|
|
|
|
starAnim.Play("NoPose", -1, 0f);
|
|
|
|
starAnim.speed = 1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
IsEligible = false;
|
|
|
|
cond = Conductor.instance;
|
|
|
|
state = StarState.None;
|
|
|
|
starAnim.Play("NoPose", -1, 0f);
|
|
|
|
starAnim.speed = 1f;
|
2023-06-10 19:13:29 +00:00
|
|
|
starStart = double.MaxValue;
|
2023-03-11 04:51:22 +00:00
|
|
|
starLength = float.MaxValue;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void DoStarIn(double beat, float length)
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
|
|
|
if (!OverlaysManager.OverlaysEnabled) return;
|
|
|
|
IsEligible = true;
|
|
|
|
state = StarState.In;
|
|
|
|
starStart = beat;
|
|
|
|
starLength = length;
|
|
|
|
|
|
|
|
TimingAccuracyDisplay.instance.StartStarFlash();
|
2024-04-10 05:05:47 +00:00
|
|
|
|
2023-03-11 04:51:22 +00:00
|
|
|
starAnim.DoScaledAnimation("StarIn", beat, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DoStarJust()
|
|
|
|
{
|
2024-04-10 05:05:47 +00:00
|
|
|
if (state == StarState.In &&
|
|
|
|
cond.unswungSongPositionInBeatsAsDouble >= StarTargetTime + cond.SecsToBeats(Minigame.AceEarlyTime() - 1, cond.GetBpmAtBeat(StarTargetTime)) &&
|
|
|
|
cond.unswungSongPositionInBeatsAsDouble <= StarTargetTime + cond.SecsToBeats(Minigame.AceLateTime() - 1, cond.GetBpmAtBeat(StarTargetTime))
|
2023-03-11 04:51:22 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
state = StarState.Collected;
|
|
|
|
starAnim.Play("StarJust", -1, 0f);
|
|
|
|
starParticle.Play();
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("skillStar");
|
2023-03-11 04:51:22 +00:00
|
|
|
|
|
|
|
TimingAccuracyDisplay.instance.StopStarFlash();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void KillStar()
|
|
|
|
{
|
2024-04-10 05:05:47 +00:00
|
|
|
if (state == StarState.In && cond.songPositionInBeatsAsDouble >= starStart + (starLength * 0.5f) || !cond.isPlaying)
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
|
|
|
IsEligible = false;
|
|
|
|
state = StarState.Out;
|
|
|
|
starAnim.Play("NoPose", -1, 0f);
|
|
|
|
|
|
|
|
TimingAccuracyDisplay.instance.StopStarFlash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|