From 286b7786766b51e15dfb764a7d4a61e173f89d12 Mon Sep 17 00:00:00 2001 From: Pengu123 Date: Fri, 6 May 2022 22:05:19 +0200 Subject: [PATCH] Cleanup + new Shedule methods --- Assets/Scripts/Games/CoinToss/CoinToss.cs | 14 ++++------- Assets/Scripts/Games/Minigame.cs | 28 +++++++++++++++++++++- Assets/Scripts/Games/PlayerActionEvent.cs | 29 +++++++++++------------ 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/Assets/Scripts/Games/CoinToss/CoinToss.cs b/Assets/Scripts/Games/CoinToss/CoinToss.cs index e88d5ec8..0dd35d96 100644 --- a/Assets/Scripts/Games/CoinToss/CoinToss.cs +++ b/Assets/Scripts/Games/CoinToss/CoinToss.cs @@ -75,24 +75,20 @@ namespace HeavenStudio.Games this.audienceReacting = audienceReacting; 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"); if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/applause"); handAnimator.Play("Catch_success", 0, 0); + Debug.Log(state); isThrowing = false; } - public void CatchMiss() + public void CatchMiss(PlayerActionEvent caller) { Jukebox.PlayOneShotGame("coinToss/miss"); if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/disappointed"); @@ -101,7 +97,7 @@ namespace HeavenStudio.Games isThrowing = false; } - public void CatchEmpty() + public void CatchEmpty(PlayerActionEvent caller) { handAnimator.Play("Catch_empty", 0, 0); isThrowing = false; diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index 8a6fe250..444dc7af 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -6,7 +6,7 @@ namespace HeavenStudio.Games { 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 EligibleHits = new List(); [System.Serializable] @@ -68,6 +68,32 @@ namespace HeavenStudio.Games 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 public void RemoveScheduledInput(PlayerActionEvent evt) { diff --git a/Assets/Scripts/Games/PlayerActionEvent.cs b/Assets/Scripts/Games/PlayerActionEvent.cs index 4b3b4bcc..e7b2702b 100644 --- a/Assets/Scripts/Games/PlayerActionEvent.cs +++ b/Assets/Scripts/Games/PlayerActionEvent.cs @@ -11,30 +11,28 @@ namespace HeavenStudio.Games public class PlayerActionEvent : PlayerActionObject { - public delegate void ActionEventCallback(); - public delegate void ActionEventCallbackState(float state); - - public delegate void ActionEventCallbackSelf(PlayerActionEvent evt); + public delegate void ActionEventCallback(PlayerActionEvent caller); + public delegate void ActionEventCallbackState(PlayerActionEvent caller, float state); 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 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 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 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 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) { @@ -64,6 +62,7 @@ namespace HeavenStudio.Games float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat,timer); StateCheck(normalizedBeat); + if (normalizedBeat > Minigame.LateTime()) Miss(); @@ -71,13 +70,14 @@ namespace HeavenStudio.Games { if (state.perfect) { + Debug.Log(normalizedBeat); Hit(0f); } - else if (state.early) + else if (state.early && !perfectOnly) { Hit(-1f); } - else if (state.late) + else if (state.late && !perfectOnly) { Hit(1f); } @@ -133,13 +133,12 @@ namespace HeavenStudio.Games { if(canHit) { - OnHit(state); + OnHit(this, state); CleanUp(); } else { - OnBlank(); + Blank(); } - } } @@ -148,7 +147,7 @@ namespace HeavenStudio.Games { if (OnMiss != null && enabled && !autoplayOnly) { - OnMiss(); + OnMiss(this); } CleanUp(); @@ -158,7 +157,7 @@ namespace HeavenStudio.Games { if(OnBlank != null && enabled && !autoplayOnly) { - OnBlank(); + OnBlank(this); } }