ScheduleInput Method added, tests awaiting

This commit is contained in:
Pengu123
2022-05-03 22:36:55 +02:00
parent e1d3d2e0ac
commit f41d9d9cf0
8 changed files with 237 additions and 152 deletions

View File

@ -1,63 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_CoinToss
{
public class Coin : PlayerActionObject
{
public float startBeat;
public bool audienceReacting;
void Awake()
{
PlayerActionInit(this.gameObject, startBeat);
}
public override void OnAce()
{
Hit();
}
void Update()
{
//Make sure there's no overlapping coin cues.
if (CoinToss.instance.current_coin != this.gameObject) Destroy(this.gameObject);
if (Conductor.instance.GetPositionFromBeat(startBeat, 1f) >= 6.3f)
MissCoin();
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, 6f);
StateCheck(normalizedBeat);
if (PlayerInput.Pressed())
{
if (state.perfect)
{
Hit();
} else
{
CoinToss.instance.Catch_Empty();
}
}
}
public void Hit()
{
if(CoinToss.instance.isThrowing)
{
CoinToss.instance.Catch_Success(audienceReacting);
Destroy(this.gameObject);
}
}
public void MissCoin()
{
CoinToss.instance.Catch_Miss(audienceReacting);
Destroy(this.gameObject);
}
}
}

View File

@ -25,7 +25,7 @@ namespace HeavenStudio.Games.Loaders
namespace HeavenStudio.Games
{
using Scripts_CoinToss;
//using Scripts_CoinToss;
public class CoinToss : Minigame
{
@ -37,77 +37,76 @@ namespace HeavenStudio.Games
public static CoinToss instance { get; set; }
public Boolean isThrowing;
public GameObject coin_cue;
public GameObject current_coin;
public bool audienceReacting;
[Header("Animators")]
public Animator handAnimator;
public PlayerActionEvent coin;
private void Awake()
{
instance = this;
isThrowing = false;
current_coin = null;
coin = null;
}
private void Update()
{
//pass
//nothing
}
private void LateUpdate()
{
//pass
//nothing
}
public void TossCoin(float beat, bool audienceReacting)
{
if (coin != null) return;
//Play sound and animations
Jukebox.PlayOneShotGame("coinToss/throw");
handAnimator.Play("Throw", 0, 0);
//Game state says the hand is throwing the coin
isThrowing = true;
//Delete the current coin to clean up overlapping instances
if(current_coin != null)
this.audienceReacting = audienceReacting;
coin = ScheduleInput(beat, 6f, InputType.STANDARD_DOWN, CatchSuccess, CatchMiss, CatchEmpty);
}
public void CatchSuccess(int state)
{
if (state != 1)
{
Destroy(current_coin);
current_coin = null;
CatchMiss();
return;
}
//Create a new coin to throw
GameObject coin = Instantiate(coin_cue);
coin.SetActive(true);
Coin c = coin.GetComponent<Coin>();
c.startBeat = beat;
c.audienceReacting = audienceReacting;
current_coin = coin;
}
public void Catch_Success(bool audienceReacting)
{
Jukebox.PlayOneShotGame("coinToss/catch");
if(audienceReacting) Jukebox.PlayOneShotGame("coinToss/applause");
if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/applause");
handAnimator.Play("Catch_success", 0, 0);
isThrowing = false;
isThrowing = false;
}
public void Catch_Miss(bool audienceReacting)
public void CatchMiss()
{
Jukebox.PlayOneShotGame("coinToss/miss");
if(audienceReacting) Jukebox.PlayOneShotGame("coinToss/disappointed");
if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/disappointed");
handAnimator.Play("Pickup", 0, 0);
isThrowing = false;
}
public void Catch_Empty()
public void CatchEmpty()
{
handAnimator.Play("Catch_empty", 0, 0);
isThrowing = false;
coin.CanHit(false);
}
}
}

View File

@ -21,6 +21,48 @@ namespace HeavenStudio.Games
public float createBeat;
}
/**
* 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..)
* 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)
*/
public PlayerActionEvent ScheduleInput(float startBeat,
float timer,
InputType inputType,
PlayerActionEvent.ActionEventCallbackState OnHit,
PlayerActionEvent.ActionEventCallback OnMiss,
PlayerActionEvent.ActionEventCallback OnBlank)
{
GameObject evtObj = new GameObject("ActionEvent" + (startBeat+timer));
evtObj.AddComponent<PlayerActionEvent>();
PlayerActionEvent evt = evtObj.GetComponent<PlayerActionEvent>();
evt.startBeat = startBeat;
evt.timer = timer;
evt.inputType = inputType;
evt.OnHit = OnHit;
evt.OnMiss = OnMiss;
evt.OnBlank = OnBlank;
evt.canHit = true;
evt.enabled = true;
evt.transform.parent = this.transform.parent;
//Instantiate(evtObj);
evtObj.SetActive(true);
return evt;
}
// hopefully these will fix the lowbpm problem
public static float EarlyTime()
{

View File

@ -0,0 +1,138 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using HeavenStudio.Util;
using Starpelly;
namespace HeavenStudio.Games
{
public class PlayerActionEvent : PlayerActionObject
{
public delegate void ActionEventCallback();
public delegate void ActionEventCallbackState(int 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 float startBeat;
public float timer;
public bool canHit = true;
public bool enabled = true;
public InputType inputType;
public void setHitCallback(ActionEventCallbackState OnHit)
{
this.OnHit = OnHit;
}
public void setMissCallback(ActionEventCallback OnMiss)
{
this.OnMiss = OnMiss;
}
public void Enable() { enabled = true; }
public void Disable() { enabled = false; }
public void CanHit(bool canHit)
{
this.canHit = canHit;
}
public void Update()
{
if(!Conductor.instance.NotStopped()){CleanUp();} // If the song is stopped entirely in the editor, destroy itself as we don't want duplicates
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat,timer);
StateCheck(normalizedBeat);
if (normalizedBeat > Minigame.LateTime()) Miss();
if (IsCorrectInput())
{
if (state.perfect)
{
Hit(1);
}
else if (state.early)
{
Hit(0);
}
else if (state.late)
{
Hit(2);
}
else
{
Blank();
}
}
}
public bool IsCorrectInput()
{
return (
(PlayerInput.Pressed() && inputType == InputType.STANDARD_DOWN) ||
(PlayerInput.AltPressed() && inputType == InputType.STANDARD_ALT_DOWN) ||
(PlayerInput.GetAnyDirectionDown() && inputType == InputType.DIRECTION_DOWN) ||
(PlayerInput.PressedUp() && inputType == InputType.STANDARD_UP) ||
(PlayerInput.AltPressedUp() && inputType == InputType.STANDARD_ALT_UP) ||
(PlayerInput.GetAnyDirectionUp() && inputType == InputType.DIRECTION_UP)
);
}
//For the Autoplay
public override void OnAce()
{
Hit(1);
}
//The state parameter is either 0 -> Early, 1 -> Perfect, 2 -> Late
public void Hit(int state)
{
if (OnHit != null && enabled)
{
if(canHit)
{
OnHit(state);
CleanUp();
} else
{
OnBlank();
}
}
}
public void Miss()
{
if (OnMiss != null && enabled)
{
OnMiss();
CleanUp();
}
}
public void Blank()
{
if(OnBlank != null && enabled)
{
OnBlank();
}
}
public void CleanUp()
{
Destroy(this.gameObject);
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: df09de01a35532c42b315b9b076cf88b
guid: f2119e14dfba60f4abe4d2410a5e1b1b
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HeavenStudio
{
public enum InputType : int {
STANDARD_DOWN = 0,
STANDARD_ALT_DOWN = 1,
DIRECTION_DOWN = 2,
STANDARD_UP = 3,
STANDARD_ALT_UP = 4,
DIRECTION_UP = 5
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 25e3511c55cd2f540abe014bf39e626b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: