mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 21:37:40 +02:00
A lot of stuff (Read desc)
Beat action is now used to define one-off objects that is used by the beat but I don't wanna bother making a different script for. Example case: the "hit 3" sprite in Karate Man. Animation helpers for functions I don't wanna rewrite 100,000 times. General improvements for Karate Man, like prepare animation and some updates to game events.
This commit is contained in:
47
Assets/Scripts/Util/BeatAction.cs
Normal file
47
Assets/Scripts/Util/BeatAction.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RhythmHeavenMania.Util
|
||||
{
|
||||
public class BeatAction : MonoBehaviour
|
||||
{
|
||||
private int index;
|
||||
private List<Action> actions = new List<Action>();
|
||||
|
||||
public delegate void EventCallback();
|
||||
|
||||
public class Action
|
||||
{
|
||||
public float beat { get; set; }
|
||||
public EventCallback function { get; set; }
|
||||
|
||||
public Action(float beat, EventCallback function)
|
||||
{
|
||||
this.beat = beat;
|
||||
this.function = function;
|
||||
}
|
||||
}
|
||||
|
||||
public static void New(GameObject prefab, List<Action> actions)
|
||||
{
|
||||
BeatAction beatAction = prefab.AddComponent<BeatAction>();
|
||||
beatAction.actions = actions;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float songPositionInBeats = Conductor.instance.songPositionInBeats;
|
||||
|
||||
for (int i = 0; i < actions.Count; i++)
|
||||
{
|
||||
if (songPositionInBeats >= actions[i].beat && index == i)
|
||||
{
|
||||
actions[i].function.Invoke();
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user