mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-10 03:35:10 +00:00
ScheduleInput Method added, tests awaiting
This commit is contained in:
parent
0c14a082ac
commit
d41eaac105
8 changed files with 237 additions and 152 deletions
|
@ -82,63 +82,6 @@ SpriteRenderer:
|
|||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!1 &2284767481152605812
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5807365695538841574}
|
||||
- component: {fileID: 5502145621422939277}
|
||||
m_Layer: 0
|
||||
m_Name: Coin_Cue
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
--- !u!4 &5807365695538841574
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2284767481152605812}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0.80453336, y: -2.6470656, z: -1.8526075}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 8906338938816874952}
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &5502145621422939277
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2284767481152605812}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: df09de01a35532c42b315b9b076cf88b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
inList: 0
|
||||
lastState: 0
|
||||
state:
|
||||
gameObject: {fileID: 0}
|
||||
early: 0
|
||||
perfect: 0
|
||||
late: 0
|
||||
createBeat: 0
|
||||
eligibleHitsList: []
|
||||
aceTimes: 0
|
||||
isEligible: 0
|
||||
triggersAutoplay: 1
|
||||
startBeat: 0
|
||||
audienceReacting: 0
|
||||
--- !u!1 &4255918877615705356
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -665,7 +608,6 @@ Transform:
|
|||
- {fileID: 5417053695332528972}
|
||||
- {fileID: 7982481497042899067}
|
||||
- {fileID: 3170172331476655201}
|
||||
- {fileID: 5807365695538841574}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
@ -684,8 +626,7 @@ MonoBehaviour:
|
|||
EligibleHits: []
|
||||
firstEnable: 0
|
||||
isThrowing: 0
|
||||
coin_cue: {fileID: 2284767481152605812}
|
||||
current_coin: {fileID: 0}
|
||||
audienceReacting: 0
|
||||
handAnimator: {fileID: 6887173419118620922}
|
||||
--- !u!1 &9176706498249536598
|
||||
GameObject:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
138
Assets/Scripts/Games/PlayerActionEvent.cs
Normal file
138
Assets/Scripts/Games/PlayerActionEvent.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: df09de01a35532c42b315b9b076cf88b
|
||||
guid: f2119e14dfba60f4abe4d2410a5e1b1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
17
Assets/Scripts/InputType.cs
Normal file
17
Assets/Scripts/InputType.cs
Normal 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
|
||||
}
|
||||
}
|
11
Assets/Scripts/InputType.cs.meta
Normal file
11
Assets/Scripts/InputType.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 25e3511c55cd2f540abe014bf39e626b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue