2022-01-21 07:09:32 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Util
|
2022-01-21 07:09:32 +00:00
|
|
|
{
|
|
|
|
public class BeatAction : MonoBehaviour
|
|
|
|
{
|
|
|
|
private int index;
|
|
|
|
private List<Action> actions = new List<Action>();
|
|
|
|
|
|
|
|
public delegate void EventCallback();
|
|
|
|
|
|
|
|
public class Action
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
public double beat { get; set; }
|
2022-01-21 07:09:32 +00:00
|
|
|
public EventCallback function { get; set; }
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
public Action(double beat, EventCallback function)
|
2022-01-21 07:09:32 +00:00
|
|
|
{
|
|
|
|
this.beat = beat;
|
|
|
|
this.function = function;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
public static BeatAction New(GameObject prefab, List<Action> actions)
|
2022-01-21 07:09:32 +00:00
|
|
|
{
|
|
|
|
BeatAction beatAction = prefab.AddComponent<BeatAction>();
|
|
|
|
beatAction.actions = actions;
|
2023-01-15 04:33:37 +00:00
|
|
|
|
|
|
|
return beatAction;
|
2022-01-21 07:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-01-15 04:33:37 +00:00
|
|
|
double songPositionInBeats = Conductor.instance.songPositionInBeatsAsDouble;
|
2022-01-21 07:09:32 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < actions.Count; i++)
|
|
|
|
{
|
|
|
|
if (songPositionInBeats >= actions[i].beat && index == i)
|
|
|
|
{
|
|
|
|
actions[i].function.Invoke();
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-15 04:33:37 +00:00
|
|
|
|
|
|
|
public void Delete()
|
|
|
|
{
|
|
|
|
Destroy(this);
|
|
|
|
}
|
2022-01-21 07:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|