commit d1b3adc002c5e157e1a36eed72b3bb6b75b99884 parent 22ac4ed11ee7304b963f3469f304bd64179013ae Author: PlutoTank <qwolkensperg@gmail.com> Date: Sat, 18 Apr 2020 23:24:59 -0400 better triggers Diffstat:
29 files changed, 69 insertions(+), 168 deletions(-)
diff --git a/Assets/Samples/2D Animation/3.1.1/Samples/.sample.json b/Assets/Samples/2D Animation/3.1.1/Samples/.sample.json @@ -1,5 +0,0 @@ -{ - "displayName": "2D Animation Samples", - "interactiveImport": "true", - "description": "Various examples demonstrating the usage of 2D Animation tools for different outcomes.", -} diff --git a/Assets/Samples/Input System/1.0.0-preview.4/InputDeviceTester/.sample.json b/Assets/Samples/Input System/1.0.0-preview.4/InputDeviceTester/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "InputDeviceTester", - "description": "A scene containing UI to visualize the controls on various supported input devices." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.4/InputDeviceTester/.sample.json.meta b/Assets/Samples/Input System/1.0.0-preview.4/InputDeviceTester/.sample.json.meta @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3d9c0d91f50349d29637153ddec7f1d9 -timeCreated: 1565354374- \ No newline at end of file diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Custom Binding Composite/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Custom Binding Composite/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Custom Binding Composite", - "description": "Shows how to implement a custom composite binding." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/EditorWindow Demo/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/EditorWindow Demo/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "EditorWindow Demo", - "description": "A simple example of how to use the input system from within EditorWindow code." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Gamepad Mouse Cursor/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Gamepad Mouse Cursor/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Gamepad Mouse Cursor", - "description": "An example that shows how to use the gamepad for driving a mouse cursor for use with UIs." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/In-Game Hints/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/In-Game Hints/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "In-Game Hints", - "description": "Demonstrates how to create in-game hints in the UI which reflect current bindings and active control schemes." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Input Recorder/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Input Recorder/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Input Recorder", - "description": "Shows how to capture and replay input events. Also useful by itself to debug input event sequences." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/InputDeviceTester/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/InputDeviceTester/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "InputDeviceTester", - "description": "A scene containing UI to visualize the controls on various supported input devices." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/InputDeviceTester/.sample.json.meta b/Assets/Samples/Input System/1.0.0-preview.6/InputDeviceTester/.sample.json.meta @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3d9c0d91f50349d29637153ddec7f1d9 -timeCreated: 1565354374- \ No newline at end of file diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Rebinding UI/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Rebinding UI/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Rebinding UI", - "description": "An example UI component that demonstrates how to create UI for rebinding actions." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Simple Demo/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Simple Demo/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Simple Demo", - "description": "A walkthrough of a simple character controller that demonstrates several techniques for working with the input system. See the README.md file in the sample for details." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Simple Demo/.sample.json.meta b/Assets/Samples/Input System/1.0.0-preview.6/Simple Demo/.sample.json.meta @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3d9c0d91f50349d29637153ddec7f1d9 -timeCreated: 1565354374- \ No newline at end of file diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Simple Multiplayer/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Simple Multiplayer/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Simple Multiplayer", - "description": "Demonstrates how to set up a simple local multiplayer scenario." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Tanks Demo/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Tanks Demo/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Tanks Demo", - "description": "The Unity Tanks demo game, converted to using the Input System package, and with a custom input binding screen. This sample is not actually part of the package, but needs to be downloaded." -} diff --git a/Assets/Samples/Input System/1.0.0-preview.6/Visualizers/.sample.json b/Assets/Samples/Input System/1.0.0-preview.6/Visualizers/.sample.json @@ -1,4 +0,0 @@ -{ - "displayName": "Visualizers", - "description": "Several example visualizations of input controls/devices and input actions." -} diff --git a/Assets/Scripts/Slimecing/Abilities/Ability.cs b/Assets/Scripts/Slimecing/Abilities/Ability.cs @@ -9,29 +9,29 @@ namespace Slimecing.Abilities public abstract class Ability : ScriptableObject { [SerializeField] protected string abilityName = "REPLACE ABILITY NAME"; - [SerializeField] private string abilityDescription = "REPLACE ABILITY DESCRIPTION"; [SerializeField] protected float abilityCooldown = 1f; [SerializeField] protected AudioClip abilitySound; - [SerializeField] private Trigger abilityTrigger = null; - public virtual void CheckActivation(AbilityUser aUser, TriggerPackage abilityTriggerPackage) + [SerializeField] private Trigger abilityTrigger; + + public Trigger currentAbilityTrigger { get; set; } + + public virtual void CheckActivation(AbilityUser aUser, TriggerState state) { - if (!abilityTriggerPackage.user.Equals(aUser.gameObject)) return; - if (AbilityTrigger == null) return; - if (abilityTriggerPackage.triggerState != TriggerState.Performed) return; - AbilityTrigger.currentTriggerState = TriggerState.Canceled; + if (currentAbilityTrigger == null) return; + if (state != TriggerState.Performed) return; + currentAbilityTrigger.currentTriggerState = TriggerState.Canceled; StartAbility(aUser); } - public Trigger AbilityTrigger { get => abilityTrigger; set => abilityTrigger = value; } - public abstract void Use(AbilityUser aUser); public virtual void Initialize(AbilityUser aUser) { - abilityTrigger.EnableTrigger(aUser.gameObject); + currentAbilityTrigger = Instantiate(abilityTrigger); + currentAbilityTrigger.EnableTrigger(aUser.gameObject); if (abilitySound == null) abilitySound = AudioClip.Create("void", 1, 1, 1000, false); - abilityTrigger.TriggerStateChange += ctx => CheckActivation(aUser, ctx); + currentAbilityTrigger.TriggerStateChange += ctx => CheckActivation(aUser, ctx); } public void StartAbility(AbilityUser aUser) @@ -74,7 +74,7 @@ namespace Slimecing.Abilities private void EndAbility() { - AbilityTrigger.currentTriggerState = TriggerState.Canceled; + currentAbilityTrigger.currentTriggerState = TriggerState.Canceled; } } } diff --git a/Assets/Scripts/Slimecing/Abilities/AbilityPackage.cs b/Assets/Scripts/Slimecing/Abilities/AbilityPackage.cs @@ -1,3 +1,4 @@ +using UnityEngine; using Slimecing.Characters; namespace Slimecing.Abilities { @@ -5,7 +6,7 @@ namespace Slimecing.Abilities { public class AbilityPackage { public Ability ability; - [UnityEngine.HideInInspector] public bool initialized = false; + [HideInInspector] public bool initialized; public AbilityPackage(Ability ability) { diff --git a/Assets/Scripts/Slimecing/Abilities/UseAbilities/JumpAbility.cs b/Assets/Scripts/Slimecing/Abilities/UseAbilities/JumpAbility.cs @@ -49,11 +49,10 @@ namespace Slimecing.Abilities.UseAbilities } } - public override void CheckActivation(AbilityUser aUser, TriggerPackage abilityTriggerPackage) + public override void CheckActivation(AbilityUser aUser, TriggerState state) { - if (AbilityTrigger == null) return; - if (!abilityTriggerPackage.user.Equals(aUser.gameObject)) return; - switch (abilityTriggerPackage.triggerState) + if (currentAbilityTrigger == null) return; + switch (state) { case TriggerState.Started: StartAbility(aUser); diff --git a/Assets/Scripts/Slimecing/Characters/AbilityUser.cs b/Assets/Scripts/Slimecing/Characters/AbilityUser.cs @@ -41,6 +41,11 @@ namespace Slimecing.Characters } } } + + foreach (var ability in useableAbilities) + { + + } } private void Update() { diff --git a/Assets/Scripts/Slimecing/Swords/DropBehaviour/DropBehaviours/RigidbodyDropLogic.cs b/Assets/Scripts/Slimecing/Swords/DropBehaviour/DropBehaviours/RigidbodyDropLogic.cs @@ -4,23 +4,23 @@ namespace Slimecing.Swords.DropBehaviour.DropBehaviours { public class RigidbodyDropLogic : DropLogic { - [SerializeField] private Rigidbody rigidbody; + [SerializeField] private Rigidbody rb; public override void Drop() { - if (rigidbody.isKinematic) + if (rb.isKinematic) { - rigidbody.isKinematic = false; + rb.isKinematic = false; } - if (!rigidbody.useGravity) + if (!rb.useGravity) { - rigidbody.useGravity = true; + rb.useGravity = true; } - rigidbody.constraints = RigidbodyConstraints.None; + rb.constraints = RigidbodyConstraints.None; - rigidbody.velocity = Vector3.zero; + rb.velocity = Vector3.zero; } } } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs @@ -1,6 +1,4 @@ -using System; -using Slimecing.Dependency; -using Slimecing.Triggers; +using Slimecing.Triggers; using UnityEngine; using UnityEngine.InputSystem; @@ -11,7 +9,7 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts { [SerializeField] private Trigger orbitalInputTrigger; - private Trigger _operatingOrbitalInputTrigger; + private Trigger operatingOrbitalInputTrigger { get; set; } public override OrbitalLogic GetOrbital() { @@ -20,9 +18,9 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts public override void Initialize(Orbital orbital) { - _operatingOrbitalInputTrigger = Instantiate(orbitalInputTrigger); + operatingOrbitalInputTrigger = Instantiate(orbitalInputTrigger); GetInput(orbital, Vector2.up); - _operatingOrbitalInputTrigger.EnableTrigger(orbital.ownerObject); + operatingOrbitalInputTrigger.EnableTrigger(orbital.ownerObject); } public override void Tick(Orbital orbital) @@ -62,10 +60,10 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts public void TickUpdate(Orbital orbital) { - InputAction action = _operatingOrbitalInputTrigger.ReadCurrentValue<InputAction>(); + InputAction action = operatingOrbitalInputTrigger.ReadCurrentValue<InputAction>(); if (action == null) return; if (!action.triggered) return; - if (action.activeControl.device.name.Equals("Mouse")) + if (action.activeControl != null && action.activeControl?.device.name == "Mouse") { if (UnityEngine.Camera.main != null) { diff --git a/Assets/Scripts/Slimecing/Triggers/Trigger.cs b/Assets/Scripts/Slimecing/Triggers/Trigger.cs @@ -7,7 +7,7 @@ namespace Slimecing.Triggers { public TriggerState currentTriggerState { get; set; } - public event Action<TriggerPackage> TriggerStateChange; + public event Action<TriggerState> TriggerStateChange; public abstract void EnableTrigger(GameObject target); protected static T CheckRequestedValue<T>(object obj) @@ -20,9 +20,9 @@ namespace Slimecing.Triggers return result; } public virtual T ReadCurrentValue<T>() => CheckRequestedValue<T>(currentTriggerState); - protected virtual void OnTriggerStateChange(TriggerPackage itp) + protected virtual void OnTriggerStateChange(TriggerState state) { - TriggerStateChange?.Invoke(itp); + TriggerStateChange?.Invoke(state); } } } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerInput.cs b/Assets/Scripts/Slimecing/Triggers/TriggerInput.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; using UnityEngine.InputSystem; namespace Slimecing.Triggers @@ -6,40 +7,35 @@ namespace Slimecing.Triggers public abstract class TriggerInput : Trigger { [SerializeField] private InputActionReference inputActionReference; - - public InputAction.CallbackContext inputContext { get; set; } - public InputActionReference currentActionReference { get => inputActionReference; set => inputActionReference = value; } - - public PlayerInput currentPlayerInput { get; private set; } - + public InputAction action { get; set; } public override void EnableTrigger(GameObject target) { - currentPlayerInput = target.GetComponent<PlayerInput>(); + PlayerInput currentPlayerInput = target.GetComponent<PlayerInput>(); if (currentPlayerInput == null) return; - foreach (var action in currentPlayerInput.actions) + foreach (var a in currentPlayerInput.actions) { - if (!currentActionReference.action.name.Equals(action.name)) continue; - action.started += ctx => TriggerStarted(target, ctx); - action.performed += ctx => TriggerPerformed(target, ctx); - action.canceled += ctx => TriggerCanceled(target, ctx); - action.Enable(); + if (!currentActionReference.action.name.Equals(a.name)) continue; + a.started += ctx => TriggerStarted(); + a.performed += ctx => TriggerPerformed(); + a.canceled += ctx => TriggerCanceled(); + a.Enable(); } } public void OnDisable() { - if (currentPlayerInput == null) return; - foreach (var action in currentPlayerInput.user.actions) - { - if (!inputActionReference.action.name.Equals(action.name)) continue; - action.Disable(); - } + action?.Disable(); } - protected abstract void TriggerStarted(GameObject player, InputAction.CallbackContext ctx); - protected abstract void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx); - protected abstract void TriggerCanceled(GameObject player,InputAction.CallbackContext ctx); + public override T ReadCurrentValue<T>() + { + return (T) Convert.ChangeType(action, typeof(T)); + } + + protected abstract void TriggerStarted(); + protected abstract void TriggerPerformed(); + protected abstract void TriggerCanceled(); } } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/HoldButtonInputTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/HoldButtonInputTrigger.cs @@ -1,30 +1,23 @@ using UnityEngine; -using UnityEngine.InputSystem; namespace Slimecing.Triggers.TriggerLogic { [CreateAssetMenu(fileName = "HoldButtonInputTrigger", menuName = "Triggers/InputTriggers/HoldButtonInputTrigger")] public class HoldButtonInputTrigger : TriggerInput { - protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx) + protected override void TriggerStarted() { - currentTriggerState = TriggerState.Started; - inputContext = ctx; - OnTriggerStateChange(new TriggerPackage(TriggerState.Started, player, ctx)); + OnTriggerStateChange(TriggerState.Started); } - protected override void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx) + protected override void TriggerPerformed() { - currentTriggerState = TriggerState.Performed; - inputContext = ctx; - OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); + OnTriggerStateChange(TriggerState.Performed); } - protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx) + protected override void TriggerCanceled() { - currentTriggerState = TriggerState.Canceled; - inputContext = ctx; - OnTriggerStateChange(new TriggerPackage(TriggerState.Canceled, player, ctx)); + OnTriggerStateChange(TriggerState.Canceled); } } } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/SimpleButtonInputTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/SimpleButtonInputTrigger.cs @@ -1,25 +1,20 @@ using UnityEngine; -using UnityEngine.InputSystem; namespace Slimecing.Triggers.TriggerLogic { [CreateAssetMenu(fileName = "SimpleButtonInputTrigger", menuName = "Triggers/InputTriggers/SimpleButtonInputTrigger")] public class SimpleButtonInputTrigger : TriggerInput { - protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx) + protected override void TriggerStarted() { - currentTriggerState = TriggerState.Performed; - inputContext = ctx; - OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); + OnTriggerStateChange(TriggerState.Performed); } - protected override void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx) { } + protected override void TriggerPerformed() { } - protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx) + protected override void TriggerCanceled() { - currentTriggerState = TriggerState.Canceled; - inputContext = ctx; - OnTriggerStateChange(new TriggerPackage(TriggerState.Canceled, player, ctx)); + OnTriggerStateChange(TriggerState.Canceled); } } } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/TimerTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/TimerTrigger.cs @@ -38,8 +38,7 @@ namespace Slimecing.Triggers.TriggerLogic private void TriggerPerformed(GameObject target) { - currentTriggerState = TriggerState.Performed; - OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, target)); + OnTriggerStateChange(TriggerState.Performed); } } } diff --git a/ProjectSettings/BurstAotSettings_StandaloneWindows.json b/ProjectSettings/BurstAotSettings_StandaloneWindows.json @@ -1,11 +0,0 @@ -{ - "MonoBehaviour": { - "m_Enabled": true, - "m_EditorHideFlags": 0, - "m_Name": "", - "m_EditorClassIdentifier": "Unity.Burst.Editor:Unity.Burst.Editor:BurstPlatformAotSettings", - "DisableOptimisations": false, - "DisableSafetyChecks": true, - "DisableBurstCompilation": false - } -}- \ No newline at end of file diff --git a/ProjectSettings/Packages/com.unity.settings-manager/Settings.json b/ProjectSettings/Packages/com.unity.settings-manager/Settings.json @@ -1,7 +0,0 @@ -{ - "m_Name": "Settings", - "m_Path": "ProjectSettings/Packages/com.unity.settings-manager/Settings.json", - "m_Dictionary": { - "m_DictionaryValues": [] - } -}- \ No newline at end of file