mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-10 11:45:09 +00:00
Added a list to keep track of all the scheduled inputs of a minigame
...Along with an Util function to return the closest scheduled input
This commit is contained in:
parent
13a2417f37
commit
6384d28295
2 changed files with 43 additions and 3 deletions
|
@ -22,12 +22,14 @@ namespace HeavenStudio.Games
|
|||
}
|
||||
|
||||
|
||||
public List<PlayerActionEvent> scheduledInputs = new List<PlayerActionEvent>();
|
||||
|
||||
/**
|
||||
* Schedule an Input for a later time in the minigame. Executes the methods put in parameters
|
||||
*
|
||||
* float startBeat : When the scheduling started (In beats)
|
||||
* float timer : How many beats later should the input be recorded
|
||||
* InputType inputType : The type of the input that's expected (Press, release, A, B, Directions..)
|
||||
* float timer : How many beats later should the input be expected
|
||||
* InputType inputType : The type of the input that's expected (Press, release, A, B, Directions..) (Check InputType class for a list)
|
||||
* ActionEventCallbackState OnHit : Method to run if the Input has been Hit
|
||||
* ActionEventCallback OnMiss : Method to run if the Input has been Missed
|
||||
* ActionEventCallback OnBlank : Method to run whenever there's an Input while this is Scheduled (Shouldn't be used too much)
|
||||
|
@ -52,17 +54,50 @@ namespace HeavenStudio.Games
|
|||
evt.OnMiss = OnMiss;
|
||||
evt.OnBlank = OnBlank;
|
||||
|
||||
evt.OnDestroy = RemoveScheduledInput;
|
||||
|
||||
evt.canHit = true;
|
||||
evt.enabled = true;
|
||||
|
||||
evt.transform.parent = this.transform.parent;
|
||||
|
||||
//Instantiate(evtObj);
|
||||
evtObj.SetActive(true);
|
||||
|
||||
scheduledInputs.Add(evt);
|
||||
|
||||
return evt;
|
||||
}
|
||||
|
||||
public void RemoveScheduledInput(PlayerActionEvent evt)
|
||||
{
|
||||
scheduledInputs.Remove(evt);
|
||||
}
|
||||
|
||||
//Get the scheduled input that should happen the **Soonest**
|
||||
//Can return null if there's no scheduled inputs
|
||||
public PlayerActionEvent GetClosestScheduledInput()
|
||||
{
|
||||
PlayerActionEvent closest = null;
|
||||
|
||||
foreach(PlayerActionEvent toCompare in scheduledInputs)
|
||||
{
|
||||
if(closest == null)
|
||||
{
|
||||
closest = toCompare;
|
||||
} else
|
||||
{
|
||||
float t1 = closest.startBeat + closest.timer;
|
||||
float t2 = toCompare.startBeat + toCompare.timer;
|
||||
|
||||
Debug.Log("t1=" + t1 + " -- t2=" + t2);
|
||||
|
||||
if (t2 < t1) closest = toCompare;
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
// hopefully these will fix the lowbpm problem
|
||||
public static float EarlyTime()
|
||||
{
|
||||
|
|
|
@ -14,10 +14,14 @@ namespace HeavenStudio.Games
|
|||
public delegate void ActionEventCallback();
|
||||
public delegate void ActionEventCallbackState(float state);
|
||||
|
||||
public delegate void ActionEventCallbackSelf(PlayerActionEvent evt);
|
||||
|
||||
public ActionEventCallbackState OnHit; //Function to trigger when an input has been done perfectly
|
||||
public ActionEventCallback OnMiss; //Function to trigger when an input has been missed
|
||||
public ActionEventCallback OnBlank; //Function to trigger when an input has been recorded while this is pending
|
||||
|
||||
public ActionEventCallbackSelf OnDestroy; //Function to trigger whenever this event gets destroyed. /!\ Shouldn't be used for a minigame! Use OnMiss instead /!\
|
||||
|
||||
public float startBeat;
|
||||
public float timer;
|
||||
|
||||
|
@ -154,6 +158,7 @@ namespace HeavenStudio.Games
|
|||
|
||||
public void CleanUp()
|
||||
{
|
||||
OnDestroy(this);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue