From ee0cd1bcd8923441460dc23a461d0cc8e89ffbb4 Mon Sep 17 00:00:00 2001 From: minenice55 Date: Mon, 18 Sep 2023 17:41:11 -0400 Subject: [PATCH] blue bear InputAction --- Assets/Scripts/Games/BlueBear/BlueBear.cs | 75 ++++++++++++++++--- Assets/Scripts/Games/BlueBear/Treat.cs | 15 ++-- Assets/Scripts/Games/Minigame.cs | 4 + .../InputSystem/ControllerTypes/InputMouse.cs | 12 +-- 4 files changed, 84 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Games/BlueBear/BlueBear.cs b/Assets/Scripts/Games/BlueBear/BlueBear.cs index 96537091a..3f4fb0ed2 100644 --- a/Assets/Scripts/Games/BlueBear/BlueBear.cs +++ b/Assets/Scripts/Games/BlueBear/BlueBear.cs @@ -1,6 +1,7 @@ using DG.Tweening; using NaughtyBezierCurves; using HeavenStudio.Util; +using HeavenStudio.InputSystem; using System; using System.Collections.Generic; using UnityEngine; @@ -10,17 +11,18 @@ namespace HeavenStudio.Games.Loaders using static Minigames; public static class CtrBearLoader { - public static Minigame AddGame(EventCaller eventCaller) { + public static Minigame AddGame(EventCaller eventCaller) + { return new Minigame("blueBear", "Blue Bear", "b4e6f6", false, false, new List() { new GameAction("donut", "Donut") { - function = delegate { BlueBear.instance.SpawnTreat(eventCaller.currentEntity.beat, false); }, + function = delegate { BlueBear.instance.SpawnTreat(eventCaller.currentEntity.beat, false); }, defaultLength = 3, }, new GameAction("cake", "Cake") { - function = delegate { BlueBear.instance.SpawnTreat(eventCaller.currentEntity.beat, true); }, + function = delegate { BlueBear.instance.SpawnTreat(eventCaller.currentEntity.beat, true); }, defaultLength = 4, }, new GameAction("setEmotion", "Set Emotion") @@ -49,9 +51,9 @@ namespace HeavenStudio.Games.Loaders } } }, - new List() {"ctr", "normal"}, + new List() { "ctr", "normal" }, "ctrbear", "en", - new List() {} + new List() { } ); } } @@ -110,6 +112,61 @@ namespace HeavenStudio.Games public static BlueBear instance; + const int IALeft = 0; + const int IARight = 1; + protected static bool IA_PadLeft(out double dt) + { + return PlayerInput.GetPadDown(InputController.ActionsPad.Up, out dt) + || PlayerInput.GetPadDown(InputController.ActionsPad.Down, out dt) + || PlayerInput.GetPadDown(InputController.ActionsPad.Left, out dt) + || PlayerInput.GetPadDown(InputController.ActionsPad.Right, out dt); + } + protected static bool IA_BatonLeft(out double dt) + { + return PlayerInput.GetBatonDown(InputController.ActionsBaton.West, out dt); + } + protected static bool IA_TouchLeft(out double dt) + { + bool want = PlayerInput.GetTouchDown(InputController.ActionsTouch.Left, out dt); + bool simul = false; + // if (!want) + // { + // simul = PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt) + // && instance.IsExpectingInputNow(InputAction_Left.inputLockCategory) + // && instance.IsExpectingInputNow(InputAction_Right.inputLockCategory); + // } + return want || simul; + } + + protected static bool IA_PadRight(out double dt) + { + return PlayerInput.GetPadDown(InputController.ActionsPad.East, out dt); + } + protected static bool IA_BatonRight(out double dt) + { + return PlayerInput.GetBatonDown(InputController.ActionsBaton.East, out dt); + } + protected static bool IA_TouchRight(out double dt) + { + bool want = PlayerInput.GetTouchDown(InputController.ActionsTouch.Right, out dt); + bool simul = false; + // if (!want) + // { + // simul = PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt) + // && instance.IsExpectingInputNow(InputAction_Right.inputLockCategory) + // && instance.IsExpectingInputNow(InputAction_Left.inputLockCategory); + // } + return want || simul; + } + + public static PlayerInput.InputAction InputAction_Left = + new("BlueBearLeft", new int[] { IALeft, IALeft, IALeft }, + IA_PadLeft, IA_TouchLeft, IA_BatonLeft); + + public static PlayerInput.InputAction InputAction_Right = + new("BlueBearRight", new int[] { IARight, IARight, IARight }, + IA_PadRight, IA_TouchRight, IA_BatonRight); + void OnDestroy() { if (Conductor.instance.isPlaying || Conductor.instance.isPaused) return; @@ -132,16 +189,16 @@ namespace HeavenStudio.Games { headAndBodyAnim.SetBool("ShouldOpenMouth", foodHolder.childCount != 0); - if (PlayerInput.GetAnyDirectionDown() && !IsExpectingInputNow(InputType.DIRECTION_DOWN)) + if (PlayerInput.GetIsAction(InputAction_Left, out _) && !IsExpectingInputNow(InputAction_Left.inputLockCategory)) { Bite(true); } - else if (PlayerInput.Pressed() && !IsExpectingInputNow(InputType.STANDARD_DOWN)) + else if (PlayerInput.GetIsAction(InputAction_Right, out _) && !IsExpectingInputNow(InputAction_Right.inputLockCategory)) { Bite(false); } - var cond = Conductor.instance; + Conductor cond = Conductor.instance; if (cond.isPlaying && !cond.isPaused) { @@ -274,7 +331,7 @@ namespace HeavenStudio.Games { var objectToSpawn = isCake ? cakeBase : donutBase; var newTreat = GameObject.Instantiate(objectToSpawn, foodHolder); - + var treatComp = newTreat.GetComponent(); treatComp.startBeat = beat; treatComp.curve = isCake ? cakeCurve : donutCurve; diff --git a/Assets/Scripts/Games/BlueBear/Treat.cs b/Assets/Scripts/Games/BlueBear/Treat.cs index b85f21006..dcc981892 100644 --- a/Assets/Scripts/Games/BlueBear/Treat.cs +++ b/Assets/Scripts/Games/BlueBear/Treat.cs @@ -21,7 +21,7 @@ namespace HeavenStudio.Games.Scripts_BlueBear [NonSerialized] public BezierCurve3D curve; private BlueBear game; - + private void Awake() { game = BlueBear.instance; @@ -30,7 +30,7 @@ namespace HeavenStudio.Games.Scripts_BlueBear private void Start() { flyBeats = isCake ? 3f : 2f; - game.ScheduleInput(startBeat, flyBeats, isCake ? InputType.DIRECTION_DOWN : InputType.STANDARD_DOWN, Just, Out, Out); + game.ScheduleInput(startBeat, flyBeats, isCake ? BlueBear.InputAction_Left : BlueBear.InputAction_Right, Just, Out, Out); } private void Update() @@ -45,7 +45,7 @@ namespace HeavenStudio.Games.Scripts_BlueBear if (flyPos > 1f) { - GameObject.Destroy(gameObject); + Destroy(gameObject); return; } @@ -76,7 +76,8 @@ namespace HeavenStudio.Games.Scripts_BlueBear private void Just(PlayerActionEvent caller, float state) { - if (state >= 1f || state <= -1f) { //todo: proper near miss feedback + if (state >= 1f || state <= -1f) + { //todo: proper near miss feedback if (isCake) { game.headAndBodyAnim.Play("BiteL", 0, 0); @@ -85,14 +86,14 @@ namespace HeavenStudio.Games.Scripts_BlueBear { game.headAndBodyAnim.Play("BiteR", 0, 0); } - return; + return; } EatFood(); } - private void Miss(PlayerActionEvent caller) {} + private void Miss(PlayerActionEvent caller) { } - private void Out(PlayerActionEvent caller) {} + private void Out(PlayerActionEvent caller) { } void SpawnCrumbs() { diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index e9011877a..1d36475d2 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -5,6 +5,7 @@ using UnityEngine; using HeavenStudio.Util; using HeavenStudio.Common; using HeavenStudio.InputSystem; +using System; namespace HeavenStudio.Games { @@ -171,6 +172,7 @@ namespace HeavenStudio.Games /// Method to run if the Input has been Missed /// Method to run whenever there's an Input while this is Scheduled (Shouldn't be used too much) /// + [Obsolete("Use Input Action ScheduleInput instead")] public PlayerActionEvent ScheduleInput( double startBeat, double timer, @@ -209,6 +211,7 @@ namespace HeavenStudio.Games return evt; } + [Obsolete("Use Input Action ScheduleInput instead")] public PlayerActionEvent ScheduleAutoplayInput(double startBeat, double timer, InputType inputType, @@ -221,6 +224,7 @@ namespace HeavenStudio.Games return evt; } + [Obsolete("Use Input Action ScheduleInput instead")] public PlayerActionEvent ScheduleUserInput(double startBeat, double timer, InputType inputType, diff --git a/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs b/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs index d023242b6..a9f9972d5 100644 --- a/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs +++ b/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs @@ -234,14 +234,14 @@ namespace HeavenStudio.InputSystem case 0: return bt; case 1: - if (bt && rawPointerPos.x <= screenBounds.x * 0.5f) + if (bt && rawPointerPos.x <= ScreenBounds.x * 0.5f) { lastDownPointerPos = rawPointerPos; return true; } return false; case 2: - if (bt && rawPointerPos.x >= screenBounds.x * 0.5f) + if (bt && rawPointerPos.x >= ScreenBounds.x * 0.5f) { lastDownPointerPos = rawPointerPos; return true; @@ -264,7 +264,7 @@ namespace HeavenStudio.InputSystem case 0: return bt; case 1: - if (bt && rawPointerPos.x <= screenBounds.x * 0.5f) + if (bt && rawPointerPos.x <= ScreenBounds.x * 0.5f) { lastDownPointerPos = rawPointerPos; startPointerPos = rawPointerPos; @@ -272,7 +272,7 @@ namespace HeavenStudio.InputSystem } return false; case 2: - if (bt && rawPointerPos.x >= screenBounds.x * 0.5f) + if (bt && rawPointerPos.x >= ScreenBounds.x * 0.5f) { lastDownPointerPos = rawPointerPos; startPointerPos = rawPointerPos; @@ -296,14 +296,14 @@ namespace HeavenStudio.InputSystem case 0: return bt; case 1: - if (bt && rawPointerPos.x <= screenBounds.x * 0.5f) + if (bt && rawPointerPos.x <= ScreenBounds.x * 0.5f) { lastUpPointerPos = rawPointerPos; return true; } return false; case 2: - if (bt && rawPointerPos.x >= screenBounds.x * 0.5f) + if (bt && rawPointerPos.x >= ScreenBounds.x * 0.5f) { lastUpPointerPos = rawPointerPos; return true;