From 8ef8b304c06d9b46a030ef56f4772589f34255d8 Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 19:03:14 -0400 Subject: [PATCH 1/4] Cleared nullable warnings --- Assets/Scripts/AIEntity.cs | 4 ++-- Assets/Scripts/Arena.cs | 6 +++--- Assets/Scripts/PlayerMovement.cs | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/AIEntity.cs b/Assets/Scripts/AIEntity.cs index 60040a7..3bf8eb3 100644 --- a/Assets/Scripts/AIEntity.cs +++ b/Assets/Scripts/AIEntity.cs @@ -5,9 +5,9 @@ using UnityEngine.Serialization; public class AIEntity : Entity { - [SerializeField] protected AudioSource attackSource; + [SerializeField] protected AudioSource attackSource = null!; - [SerializeField] protected AudioClip[] attackSounds; + [SerializeField] protected AudioClip[] attackSounds = null!; [FormerlySerializedAs("stats")] [SerializeField] diff --git a/Assets/Scripts/Arena.cs b/Assets/Scripts/Arena.cs index 970d559..ea15a5f 100644 --- a/Assets/Scripts/Arena.cs +++ b/Assets/Scripts/Arena.cs @@ -45,9 +45,9 @@ public class Arena : MonoBehaviour { SafeZone safeZone = null!; [field: SerializeField] int currWaveSize = 0; - [SerializeField] AudioSource waveSource; - [SerializeField] AudioClip[] waveSounds; - [HideInInspector] public SoundManager soundManager; + [SerializeField] AudioSource waveSource = null!; + [SerializeField] AudioClip[] waveSounds = null!; + [HideInInspector] public SoundManager soundManager = null!; void Awake() { diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 75ebd08..b8d6d93 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -21,13 +21,13 @@ public class PlayerMovement : MonoBehaviour { VampireEntity vampireEntity = null!; Animator animator = null!; public bool facingRight { get; private set; } = true; - [HideInInspector] public ScreenShaker screenShaker; + [HideInInspector] public ScreenShaker screenShaker = null!; - [SerializeField] AudioSource jumpSource; - [SerializeField] AudioClip[] jumpSounds; - [SerializeField] AudioSource landSource; - [SerializeField] AudioClip[] landSounds; - [HideInInspector] public SoundManager soundManager; + [SerializeField] AudioSource jumpSource = null!; + [SerializeField] AudioClip[] jumpSounds = null!; + [SerializeField] AudioSource landSource = null!; + [SerializeField] AudioClip[] landSounds = null!; + [HideInInspector] public SoundManager soundManager = null!; bool lastJumpButton; From 5ed2045b305fb13175365ebc1d5646c8d5bf8f02 Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 19:53:43 -0400 Subject: [PATCH 2/4] Added rumble on screen shake and suck --- Assets/Prefabs/Vampire.prefab | 3 +++ Assets/Scripts/BloodSucker.cs | 2 ++ Assets/Scripts/GameFlowManager.cs | 4 ++-- Assets/Scripts/PlayerMovement.cs | 1 + Assets/Scripts/ScreenShaker.cs | 28 +++++++++++++++++++++++----- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Assets/Prefabs/Vampire.prefab b/Assets/Prefabs/Vampire.prefab index 097df04..9311899 100644 --- a/Assets/Prefabs/Vampire.prefab +++ b/Assets/Prefabs/Vampire.prefab @@ -58,6 +58,7 @@ MonoBehaviour: gameFlowManager: {fileID: 0} stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} globalCamera: {fileID: 0} + screenShaker: {fileID: 0} jumpSource: {fileID: 7164870411903264125} jumpSounds: - {fileID: 8300000, guid: 2f93dc5371f10744ba49e29576e8a6a7, type: 3} @@ -104,6 +105,7 @@ MonoBehaviour: - {fileID: 8300000, guid: 4e2519f9a65bd484d95111774c762843, type: 3} playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} playerMovement: {fileID: 0} + screenShaker: {fileID: 0} --- !u!114 &1967503440015794769 MonoBehaviour: m_ObjectHideFlags: 0 @@ -145,6 +147,7 @@ MonoBehaviour: suckSource: {fileID: 3555231741827846396} suckSounds: - {fileID: 8300000, guid: c12a57d990960ce44bc7cf4d5f63d32b, type: 3} + screenShaker: {fileID: 0} soundManager: {fileID: 0} --- !u!114 &1214567908930553477 MonoBehaviour: diff --git a/Assets/Scripts/BloodSucker.cs b/Assets/Scripts/BloodSucker.cs index 7743ff2..7bdb843 100644 --- a/Assets/Scripts/BloodSucker.cs +++ b/Assets/Scripts/BloodSucker.cs @@ -121,10 +121,12 @@ public class BloodSucker : MonoBehaviour { bloodParticles.Play(); currentTarget.OnSuck(true); soundManager.PlaySound(suckingSource, suckingSounds, randomPitch: true, createTempSourceIfBusy: false); + screenShaker.StartHeldRumble(); } else { bloodParticles.Stop(true, ParticleSystemStopBehavior.StopEmitting); if(!(currentTarget is null))currentTarget.OnSuck(false); soundManager.StopSound(suckingSource); + screenShaker.StopHeldRumble(); } } diff --git a/Assets/Scripts/GameFlowManager.cs b/Assets/Scripts/GameFlowManager.cs index e9b999b..da14040 100644 --- a/Assets/Scripts/GameFlowManager.cs +++ b/Assets/Scripts/GameFlowManager.cs @@ -181,12 +181,12 @@ public class GameFlowManager : MonoBehaviour { gameFlowManager.SetPauseLevel(PauseLevel.PreventActions); } + public override void LeaveState() => gameFlowManager.startTxt.transform.parent.gameObject.SetActive(false); + public override BaseState? UpdateState(){ gameFlowManager.FadeStartTxt(); return null; } - - public override void LeaveState() => gameFlowManager.startTxt.transform.parent.gameObject.SetActive(false); } public class GameplayFlowState : GameFlowState { diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index b8d6d93..933b0c3 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -42,6 +42,7 @@ public class PlayerMovement : MonoBehaviour { currentState = new ImmobileMovementState(this); soundManager = FindObjectOfType(); screenShaker = FindObjectOfType(); + } void Start() { diff --git a/Assets/Scripts/ScreenShaker.cs b/Assets/Scripts/ScreenShaker.cs index 0febaf3..a84d72b 100644 --- a/Assets/Scripts/ScreenShaker.cs +++ b/Assets/Scripts/ScreenShaker.cs @@ -2,29 +2,47 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine; +using UnityEngine.InputSystem; public class ScreenShaker : MonoBehaviour { - CinemachineVirtualCamera cam; CinemachineBasicMultiChannelPerlin noise; + Coroutine coroutine; + bool rumbleHeld; void Awake() { cam = GetComponent(); noise = cam.GetCinemachineComponent(); } - public void Shake(float magnitude = 1f, float duration = 0.2f) { - StartCoroutine(ShakeCoroutine(magnitude, duration)); + public void Shake(float magnitude = 1f, float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f, float duration = 0.2f) { + if (coroutine is {}) + StopCoroutine(coroutine); + + coroutine = StartCoroutine(ShakeCoroutine(magnitude, rumbleLowFreq, rumbleHighFreq, duration)); } - IEnumerator ShakeCoroutine(float magnitude, float duration) { + public void StartHeldRumble(float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f) { + rumbleHeld = true; + Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); + } + + public void StopHeldRumble() { + rumbleHeld = false; + Gamepad.current.ResetHaptics(); + } + + IEnumerator ShakeCoroutine(float magnitude, float rumbleLowFreq, float rumbleHighFreq, float duration) { noise.m_AmplitudeGain = magnitude; noise.m_FrequencyGain = 10f; + Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); - yield return new WaitForSeconds(duration); + yield return new WaitForSecondsRealtime(duration); noise.m_AmplitudeGain = 0f; noise.m_FrequencyGain = 1f; + if (!rumbleHeld) + Gamepad.current.ResetHaptics(); } } From f4ee5d0de18a9021d34edcb6e189ef5e2be8666a Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 20:06:24 -0400 Subject: [PATCH 3/4] Can get attack rumble while sucking? --- Assets/Scripts/ScreenShaker.cs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/ScreenShaker.cs b/Assets/Scripts/ScreenShaker.cs index a84d72b..188e698 100644 --- a/Assets/Scripts/ScreenShaker.cs +++ b/Assets/Scripts/ScreenShaker.cs @@ -1,14 +1,14 @@ +#nullable enable using System.Collections; -using System.Collections.Generic; using UnityEngine; using Cinemachine; using UnityEngine.InputSystem; public class ScreenShaker : MonoBehaviour { - CinemachineVirtualCamera cam; - CinemachineBasicMultiChannelPerlin noise; - Coroutine coroutine; - bool rumbleHeld; + CinemachineVirtualCamera cam = null!; + CinemachineBasicMultiChannelPerlin noise = null!; + Coroutine? coroutine; + (float, float)? heldRumble; void Awake() { cam = GetComponent(); @@ -23,26 +23,27 @@ public class ScreenShaker : MonoBehaviour { } public void StartHeldRumble(float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f) { - rumbleHeld = true; + heldRumble = (rumbleLowFreq, rumbleHighFreq); Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); } public void StopHeldRumble() { - rumbleHeld = false; + heldRumble = null; Gamepad.current.ResetHaptics(); } IEnumerator ShakeCoroutine(float magnitude, float rumbleLowFreq, float rumbleHighFreq, float duration) { noise.m_AmplitudeGain = magnitude; noise.m_FrequencyGain = 10f; - Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); + Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); yield return new WaitForSecondsRealtime(duration); noise.m_AmplitudeGain = 0f; noise.m_FrequencyGain = 1f; - if (!rumbleHeld) - Gamepad.current.ResetHaptics(); + if (heldRumble != null) + Gamepad.current.SetMotorSpeeds(heldRumble.Value.Item1, heldRumble.Value.Item2); + else + Gamepad.current.ResetHaptics(); } - } From 8e0d1874dc8a7e351227fe9b9b3248b3dfed83f6 Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 20:09:07 -0400 Subject: [PATCH 4/4] Don't screen shake when throwing minion --- Assets/Scripts/AIEntity.cs | 4 ++-- Assets/Scripts/Entity.cs | 2 +- Assets/Scripts/MinionThrower.cs | 2 +- Assets/Scripts/PlayerMovement.cs | 2 +- Assets/Scripts/VampireEntity.cs | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/AIEntity.cs b/Assets/Scripts/AIEntity.cs index 3bf8eb3..8539882 100644 --- a/Assets/Scripts/AIEntity.cs +++ b/Assets/Scripts/AIEntity.cs @@ -78,12 +78,12 @@ public class AIEntity : Entity { return enemies.HasFlag(other.entityType) && other.IsAlive(); } - override public bool TakeDamage(float amount, Entity other, bool sound=true) { + override public bool TakeDamage(float amount, Entity other, bool sound = true, bool intentional = false) { //TODO Should we warn if target is null here? if (target != null && target.GetComponent() is { }) target = other.transform; - return base.TakeDamage(amount, other, sound); + return base.TakeDamage(amount, other, sound, intentional); } #region Flip diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 9067f12..1480d39 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -93,7 +93,7 @@ public class Entity : MonoBehaviour { } //Apply damage to the entity, returns true if it is still alive - public virtual bool TakeDamage(float amount, Entity other, bool sound = true) { + public virtual bool TakeDamage(float amount, Entity other, bool sound = true, bool intentional = false) { Health -= amount; healthBar.SetHealthFraction(Health / initialHealth); diff --git a/Assets/Scripts/MinionThrower.cs b/Assets/Scripts/MinionThrower.cs index aaf0dc7..76fc4c7 100644 --- a/Assets/Scripts/MinionThrower.cs +++ b/Assets/Scripts/MinionThrower.cs @@ -81,7 +81,7 @@ public class MinionThrower : MonoBehaviour { if (minionHealthCost >= vampireEntity.Health) { return; } - vampireEntity.TakeDamage(minionHealthCost, vampireEntity); + vampireEntity.TakeDamage(minionHealthCost, vampireEntity, intentional: true); currentCooldownTimer = playerStats.currentInitialCooldown; diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 933b0c3..9168fc4 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -196,7 +196,7 @@ public class PlayerMovement : MonoBehaviour { // playerMovement.animator.SetBool("Jumping", true); playerMovement.animator.Play("Player_Jump"); playerMovement.soundManager.PlaySound(playerMovement.jumpSource, playerMovement.jumpSounds, randomPitch: true, createTempSourceIfBusy: true); - playerMovement.screenShaker.Shake(); + playerMovement.screenShaker.Shake(rumbleLowFreq:0f, rumbleHighFreq:0f); } public override void LeaveState() { // playerMovement.animator.SetBool("Jumping", false); diff --git a/Assets/Scripts/VampireEntity.cs b/Assets/Scripts/VampireEntity.cs index 81355e6..85aae01 100644 --- a/Assets/Scripts/VampireEntity.cs +++ b/Assets/Scripts/VampireEntity.cs @@ -30,12 +30,12 @@ public class VampireEntity : Entity { TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this, sound: false); } - public override bool TakeDamage(float amount, Entity other, bool sound = true) { - if (sound) { + public override bool TakeDamage(float amount, Entity other, bool sound = true, bool intentional = false) { + if (sound && !intentional) { screenShaker.Shake(); } - return base.TakeDamage(amount, other, sound); + return base.TakeDamage(amount, other, sound, intentional); } public bool IsInSafeZone() => playerMovement.IsInSafeZone;