mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-14 05:35:08 +00:00
330c538947
* update blue bear to use PlayerActionEvent * update built to scale DS to use PlayerActionEvent * update clappy trio to use PlayerActionEvent * update crop stomp to use PlayerActionEvent * update drumming practice to use PlayerActionEvent * update fork lifter to use PlayerActionEvent * update minigame icons * update wizard waltz' icon
54 lines
No EOL
1.3 KiB
C#
54 lines
No EOL
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace HeavenStudio.Util
|
|
{
|
|
public class BeatAction : MonoBehaviour
|
|
{
|
|
private int index;
|
|
private List<Action> actions = new List<Action>();
|
|
|
|
public delegate void EventCallback();
|
|
|
|
public class Action
|
|
{
|
|
public double beat { get; set; }
|
|
public EventCallback function { get; set; }
|
|
|
|
public Action(double beat, EventCallback function)
|
|
{
|
|
this.beat = beat;
|
|
this.function = function;
|
|
}
|
|
}
|
|
|
|
public static BeatAction New(GameObject prefab, List<Action> actions)
|
|
{
|
|
BeatAction beatAction = prefab.AddComponent<BeatAction>();
|
|
beatAction.actions = actions;
|
|
|
|
return beatAction;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
double songPositionInBeats = Conductor.instance.songPositionInBeatsAsDouble;
|
|
|
|
for (int i = 0; i < actions.Count; i++)
|
|
{
|
|
if (songPositionInBeats >= actions[i].beat && index == i)
|
|
{
|
|
actions[i].function.Invoke();
|
|
index++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Delete()
|
|
{
|
|
Destroy(this);
|
|
}
|
|
}
|
|
|
|
} |