From 2c8af0cea9042789a26fab7f7c1cff6cae74e64d Mon Sep 17 00:00:00 2001 From: rezazfn Date: Mon, 10 Feb 2025 16:12:57 +0800 Subject: [PATCH] game: trying to troubleshoot effects --- .../Scenes/Game/Global Volume Profile.asset | 2 +- Game/Assets/Scenes/House.unity | 166 ++++++++++++++++++ Game/Assets/Scripts/BedroomTask.cs | 24 ++- Game/Assets/Scripts/PostProcessingManager.cs | 60 +++++-- 4 files changed, 238 insertions(+), 14 deletions(-) diff --git a/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game/Global Volume Profile.asset b/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game/Global Volume Profile.asset index 620897a..50e0ab5 100644 --- a/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game/Global Volume Profile.asset +++ b/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game/Global Volume Profile.asset @@ -21,7 +21,7 @@ MonoBehaviour: m_Value: {x: 0.5, y: 0.5} intensity: m_OverrideState: 1 - m_Value: 0 + m_Value: 0.2 smoothness: m_OverrideState: 1 m_Value: 1 diff --git a/Game/Assets/Scenes/House.unity b/Game/Assets/Scenes/House.unity index cd84a67..b9d2fc2 100644 --- a/Game/Assets/Scenes/House.unity +++ b/Game/Assets/Scenes/House.unity @@ -13788,6 +13788,171 @@ Mesh: offset: 0 size: 0 path: +--- !u!1 &198323985 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 198323986} + - component: {fileID: 198323987} + m_Layer: 0 + m_Name: PostProcessingManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &198323986 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 198323985} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 77.96721, y: 20.96754, z: 1068.8622} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &198323987 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 198323985} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 46e96ab748a3a844f9137261de774bfe, type: 3} + m_Name: + m_EditorClassIdentifier: + volume: {fileID: 1297863892} + vignetteIntensity: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.5839262 + value: 0.006742792 + inSlope: -5.2464867 + outSlope: -5.2464867 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.060403872 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 1 + m_RotationOrder: 4 + chromaticAberrationIntensity: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.9981079 + value: 0.0039978027 + inSlope: -1.8971481 + outSlope: -1.8971481 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.08867113 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 1 + m_RotationOrder: 4 + motionBlurIntensity: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.9826355 + value: 0.0007019043 + inSlope: -2.3879576 + outSlope: -2.3879576 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.068186805 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + lensDistortionIntensity: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.80358887 + value: 0.011993408 + inSlope: -1.9551758 + outSlope: -1.9551758 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.05306956 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 1 + m_RotationOrder: 4 + colorAdjustmentsIntensity: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.8580322 + value: -0.0005722046 + inSlope: -1.7699907 + outSlope: -1.7699907 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.054151148 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 1 + m_RotationOrder: 4 --- !u!43 &200338106 Mesh: m_ObjectHideFlags: 0 @@ -150664,6 +150829,7 @@ SceneRoots: m_ObjectHideFlags: 0 m_Roots: - {fileID: 1297863893} + - {fileID: 198323986} - {fileID: 19713756} - {fileID: 960695709} - {fileID: 108605771} diff --git a/Game/Assets/Scripts/BedroomTask.cs b/Game/Assets/Scripts/BedroomTask.cs index 7af27fa..957be51 100644 --- a/Game/Assets/Scripts/BedroomTask.cs +++ b/Game/Assets/Scripts/BedroomTask.cs @@ -15,7 +15,8 @@ using UnityEngine.XR.Interaction.Toolkit; public class BedroomTask : MonoBehaviour { private GameManager gameManager; - + private PostProcessingManager postProcessingManager; + [Header("Task Requirement Values")] // To track how much trash has been collected so far public int trashCollected = 0; @@ -23,7 +24,6 @@ public class BedroomTask : MonoBehaviour // Defines how much trash is needed to collect in order to unlock the door public int trashRequired = 10; - // Defines the door [Header("Door to Unlock")] public GameObject door; @@ -202,6 +202,8 @@ public class BedroomTask : MonoBehaviour storyText.text = "!!!"; storyPanelUI.SetActive(true); + PostProcessingManager.Instance.StartEffect("Panic"); + // Play footsteps of parents walking away audioSource.PlayOneShot(footstepsSound); yield return new WaitForSeconds(footstepsSound.length); @@ -210,12 +212,18 @@ public class BedroomTask : MonoBehaviour audioSource.PlayOneShot(doorSlamSound); yield return new WaitForSeconds(doorSlamSound.length); + + PostProcessingManager.Instance.StopEffect(); + // Clear the "!!!" storyText.text = ""; // Unlocks the door after the clips and update the story UnlockDoor(); + // Add a small delay before updating the text to ensure everything shows properly + yield return new WaitForSeconds(0.5f); + storyText.text = "They finally left... just as soon as I finished cleaning. I can leave the room now."; StartCoroutine(HideMessageAfterSeconds(storyPanelUI, 10f)); } @@ -227,4 +235,14 @@ public class BedroomTask : MonoBehaviour yield return new WaitForSeconds(delay); uiElement.SetActive(false); } -} \ No newline at end of file + + public void ApplyHeadacheEffect() + { + PostProcessingManager.Instance?.TriggerEffect("Headache"); + } + + public void ApplyDizzinessEffect() + { + PostProcessingManager.Instance?.TriggerEffect("Dizziness"); + } +} diff --git a/Game/Assets/Scripts/PostProcessingManager.cs b/Game/Assets/Scripts/PostProcessingManager.cs index 4189138..c2ae8dd 100644 --- a/Game/Assets/Scripts/PostProcessingManager.cs +++ b/Game/Assets/Scripts/PostProcessingManager.cs @@ -12,6 +12,8 @@ using UnityEngine.Rendering.Universal; public class PostProcessingManager : MonoBehaviour { + public static PostProcessingManager Instance; + // Defines the Global Volume public Volume volume; @@ -42,6 +44,18 @@ public class PostProcessingManager : MonoBehaviour // Checks if effect is active or not private bool isEffectActive = false; + void Awake() + { + if (Instance == null) + { + Instance = this; + } + else + { + Destroy(gameObject); + } + } + // Start is called before the first frame update void Start() { @@ -78,7 +92,7 @@ public class PostProcessingManager : MonoBehaviour } // Function to start the effect - private void StartEffect(string effectName) + public void StartEffect(string effectName) { // The effect is active isEffectActive = true; @@ -88,29 +102,29 @@ public class PostProcessingManager : MonoBehaviour } // Function to stop the effect - private void StopEffect(string effectName) + public void StopEffect(string effectName) { // The effect is not active isEffectActive = false; // Reset effects to default - vignette.intensity.Override(0f); - chromaticAberration.intensity.Override(0f); - motionBlur.intensity.Override(0f); - lensDistortion.intensity.Override(0f); - colorAdjustments.postExposure.Override(0f); + if (vignette != null) vignette.intensity.Override(0f); + if (chromaticAberration != null) chromaticAberration.intensity.Override(0f); + if (motionBlur != null) motionBlur.intensity.Override(0f); + if (lensDistortion != null) lensDistortion.intensity.Override(0f); + if (colorAdjustments != null) colorAdjustments.postExposure.Override(0f); } // Applies effects over time based on the type private IEnumerator ApplyEffect(string effectName) { float time = 0f; - float timeToMax = 1f; + float duration = 1f; - while (time < timeToMax) + while (time < duration) { time += Time.deltaTime; - time = Mathf.Clamp01(time); + float t = Mathf.Clamp01(time / duration); // Values for headache effect if (effectName == "Headache") @@ -129,4 +143,30 @@ public class PostProcessingManager : MonoBehaviour yield return null; } } + + public void ApplyPanicEffect() + { + StartCoroutine(LoopPanicEffect()); + } + + private IEnumerator LoopPanicEffect() + { + float time = 0f; + float duration = 0.1f; + + while (isEffectActive) + { + time += Time.deltaTime; + float t = Mathf.PingPong(time / duration, 1f); // Looping the effect + + // Apply intensity for panic effect + vignette.intensity.Override(vignetteIntensity.Evaluate(t)); + chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(t)); + motionBlur.intensity.Override(motionBlurIntensity.Evaluate(t)); + lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(t)); + colorAdjustments.postExposure.Override(colorAdjustmentsIntensity.Evaluate(t)); + + yield return null; + } + } }