game: trying to troubleshoot effects

This commit is contained in:
rezazfn 2025-02-10 16:12:57 +08:00
parent f188d0a636
commit 2c8af0cea9
4 changed files with 238 additions and 14 deletions

View file

@ -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

View file

@ -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}

View file

@ -15,6 +15,7 @@ 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
@ -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);
}
public void ApplyHeadacheEffect()
{
PostProcessingManager.Instance?.TriggerEffect("Headache");
}
public void ApplyDizzinessEffect()
{
PostProcessingManager.Instance?.TriggerEffect("Dizziness");
}
}

View file

@ -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;
}
}
}