Cleanup + new Shedule methods

This commit is contained in:
Pengu123 2022-05-06 22:05:19 +02:00
parent 34e29efae8
commit 286b778676
3 changed files with 46 additions and 25 deletions

View file

@ -75,24 +75,20 @@ namespace HeavenStudio.Games
this.audienceReacting = audienceReacting; this.audienceReacting = audienceReacting;
coin = ScheduleInput(beat, 6f, InputType.STANDARD_DOWN, CatchSuccess, CatchMiss, CatchEmpty); coin = ScheduleInput(beat, 6f, InputType.STANDARD_DOWN, CatchSuccess, CatchMiss, CatchEmpty);
//coin.perfectOnly = true;
} }
public void CatchSuccess(float state) public void CatchSuccess(PlayerActionEvent caller, float state)
{ {
if (state != 0)
{
CatchMiss();
return;
}
Jukebox.PlayOneShotGame("coinToss/catch"); Jukebox.PlayOneShotGame("coinToss/catch");
if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/applause"); if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/applause");
handAnimator.Play("Catch_success", 0, 0); handAnimator.Play("Catch_success", 0, 0);
Debug.Log(state);
isThrowing = false; isThrowing = false;
} }
public void CatchMiss() public void CatchMiss(PlayerActionEvent caller)
{ {
Jukebox.PlayOneShotGame("coinToss/miss"); Jukebox.PlayOneShotGame("coinToss/miss");
if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/disappointed"); if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/disappointed");
@ -101,7 +97,7 @@ namespace HeavenStudio.Games
isThrowing = false; isThrowing = false;
} }
public void CatchEmpty() public void CatchEmpty(PlayerActionEvent caller)
{ {
handAnimator.Play("Catch_empty", 0, 0); handAnimator.Play("Catch_empty", 0, 0);
isThrowing = false; isThrowing = false;

View file

@ -6,7 +6,7 @@ namespace HeavenStudio.Games
{ {
public class Minigame : MonoBehaviour public class Minigame : MonoBehaviour
{ {
public static float earlyTime = 0.84f, perfectTime = 0.91f, lateTime = 1.09f, endTime = 1.15f; public static float earlyTime = 0.90f, perfectTime = 0.93f, lateTime = 1.06f, endTime = 1.10f;
public List<Minigame.Eligible> EligibleHits = new List<Minigame.Eligible>(); public List<Minigame.Eligible> EligibleHits = new List<Minigame.Eligible>();
[System.Serializable] [System.Serializable]
@ -68,6 +68,32 @@ namespace HeavenStudio.Games
return evt; return evt;
} }
public PlayerActionEvent ScheduleAutoplayInput(float startBeat,
float timer,
InputType inputType,
PlayerActionEvent.ActionEventCallbackState OnHit,
PlayerActionEvent.ActionEventCallback OnMiss,
PlayerActionEvent.ActionEventCallback OnBlank)
{
PlayerActionEvent evt = ScheduleInput(startBeat, timer, inputType, OnHit, OnMiss, OnBlank);
evt.autoplayOnly = true;
return evt;
}
public PlayerActionEvent ScheduleUserInput(float startBeat,
float timer,
InputType inputType,
PlayerActionEvent.ActionEventCallbackState OnHit,
PlayerActionEvent.ActionEventCallback OnMiss,
PlayerActionEvent.ActionEventCallback OnBlank)
{
PlayerActionEvent evt = ScheduleInput(startBeat, timer, inputType, OnHit, OnMiss, OnBlank);
evt.noAutoplay = true;
return evt;
}
//Clean up method used whenever a PlayerActionEvent has finished //Clean up method used whenever a PlayerActionEvent has finished
public void RemoveScheduledInput(PlayerActionEvent evt) public void RemoveScheduledInput(PlayerActionEvent evt)
{ {

View file

@ -11,30 +11,28 @@ namespace HeavenStudio.Games
public class PlayerActionEvent : PlayerActionObject public class PlayerActionEvent : PlayerActionObject
{ {
public delegate void ActionEventCallback(); public delegate void ActionEventCallback(PlayerActionEvent caller);
public delegate void ActionEventCallbackState(float state); public delegate void ActionEventCallbackState(PlayerActionEvent caller, float state);
public delegate void ActionEventCallbackSelf(PlayerActionEvent evt);
public ActionEventCallbackState OnHit; //Function to trigger when an input has been done perfectly 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 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 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 ActionEventCallback OnDestroy; //Function to trigger whenever this event gets destroyed. /!\ Shouldn't be used for a minigame! Use OnMiss instead /!\
public float startBeat; public float startBeat;
public float timer; public float timer;
public bool canHit = true; //Indicates if you can still hit the cue or not. If set to false, it'll guarantee a miss public bool canHit = true; //Indicates if you can still hit the cue or not. If set to false, it'll guarantee a miss
public bool enabled = true; //Indicates if the PlayerActionEvent is enabled. If set to false, it'll not trigger any events and destroy itself AFTER the event public bool enabled = true; //Indicates if the PlayerActionEvent is enabled. If set to false, it'll not trigger any events and destroy itself AFTER it's not relevant anymore
public bool autoplayOnly = false; //Indicates if the input event only triggers when it's autoplay. If set to true, NO Miss or Blank events will be triggered when you're not autoplaying. public bool autoplayOnly = false; //Indicates if the input event only triggers when it's autoplay. If set to true, NO Miss or Blank events will be triggered when you're not autoplaying.
public bool noAutoplay = false; //Indicates if this PlayerActionEvent is recognized by the autoplay. /!\ Overrides autoPlayOnly /!\ public bool noAutoplay = false; //Indicates if this PlayerActionEvent is recognized by the autoplay. /!\ Overrides autoPlayOnly /!\
// I don't know why we would ever need the noAutoplay setting, but we never know! public InputType inputType; //The type of input. Check the InputType class to see a list of all of them
public InputType inputType; public bool perfectOnly = false; //Indicates that the input only recognize perfect inputs.
public void setHitCallback(ActionEventCallbackState OnHit) public void setHitCallback(ActionEventCallbackState OnHit)
{ {
@ -64,6 +62,7 @@ namespace HeavenStudio.Games
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat,timer); float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat,timer);
StateCheck(normalizedBeat); StateCheck(normalizedBeat);
if (normalizedBeat > Minigame.LateTime()) Miss(); if (normalizedBeat > Minigame.LateTime()) Miss();
@ -71,13 +70,14 @@ namespace HeavenStudio.Games
{ {
if (state.perfect) if (state.perfect)
{ {
Debug.Log(normalizedBeat);
Hit(0f); Hit(0f);
} }
else if (state.early) else if (state.early && !perfectOnly)
{ {
Hit(-1f); Hit(-1f);
} }
else if (state.late) else if (state.late && !perfectOnly)
{ {
Hit(1f); Hit(1f);
} }
@ -133,13 +133,12 @@ namespace HeavenStudio.Games
{ {
if(canHit) if(canHit)
{ {
OnHit(state); OnHit(this, state);
CleanUp(); CleanUp();
} else } else
{ {
OnBlank(); Blank();
} }
} }
} }
@ -148,7 +147,7 @@ namespace HeavenStudio.Games
{ {
if (OnMiss != null && enabled && !autoplayOnly) if (OnMiss != null && enabled && !autoplayOnly)
{ {
OnMiss(); OnMiss(this);
} }
CleanUp(); CleanUp();
@ -158,7 +157,7 @@ namespace HeavenStudio.Games
{ {
if(OnBlank != null && enabled && !autoplayOnly) if(OnBlank != null && enabled && !autoplayOnly)
{ {
OnBlank(); OnBlank(this);
} }
} }