game(scripts): standardise PostProcessingManager
This commit is contained in:
parent
f226e778f4
commit
9c945c535d
1 changed files with 81 additions and 102 deletions
|
@ -1,11 +1,10 @@
|
||||||
/*
|
/*
|
||||||
Author: Reza
|
* Author: Reza
|
||||||
Date: 7/2/25
|
* Date: 7/2/25
|
||||||
Description: Has all the post processing camera effects that replicate real symptoms like dizziness, fainting, panic, etc
|
* Description: Post-processing camera effects emulating various conditions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using UnityEngine.Rendering.Universal;
|
using UnityEngine.Rendering.Universal;
|
||||||
|
@ -17,13 +16,6 @@ public class PostProcessingManager : MonoBehaviour
|
||||||
// Defines the Global Volume
|
// Defines the Global Volume
|
||||||
public Volume volume;
|
public Volume volume;
|
||||||
|
|
||||||
// All the effect overrides
|
|
||||||
private Vignette vignette;
|
|
||||||
private ChromaticAberration chromaticAberration;
|
|
||||||
private MotionBlur motionBlur;
|
|
||||||
private LensDistortion lensDistortion;
|
|
||||||
private ColorAdjustments colorAdjustments;
|
|
||||||
|
|
||||||
[Header("Effect Intensities")]
|
[Header("Effect Intensities")]
|
||||||
// Editable override values in inspector
|
// Editable override values in inspector
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
@ -37,56 +29,56 @@ public class PostProcessingManager : MonoBehaviour
|
||||||
|
|
||||||
[SerializeField] public AnimationCurve colorAdjustmentsIntensity;
|
[SerializeField] public AnimationCurve colorAdjustmentsIntensity;
|
||||||
|
|
||||||
// Checks if effect is active or not
|
|
||||||
private bool isEffectActive = false;
|
|
||||||
|
|
||||||
// Defines Audio References
|
// Defines Audio References
|
||||||
[Header("Audio References")]
|
[Header("Audio References")] public AudioSource audioSource;
|
||||||
public AudioSource audioSource;
|
|
||||||
public AudioClip heartbeatSound;
|
public AudioClip heartbeatSound;
|
||||||
public AudioClip whisperSound;
|
public AudioClip whisperSound;
|
||||||
public AudioClip distortedWhisperSound;
|
public AudioClip distortedWhisperSound;
|
||||||
|
private ChromaticAberration _chromaticAberration;
|
||||||
|
private ColorAdjustments _colorAdjustments;
|
||||||
|
|
||||||
// Holds the current effect name to manage stopping and starting dynamically
|
// Holds the current effect name to manage stopping and starting dynamically
|
||||||
private string currentEffectName = "";
|
private string _currentEffectName = "";
|
||||||
|
|
||||||
void Awake()
|
// Checks if effect is active or not
|
||||||
|
private bool _isEffectActive;
|
||||||
|
private LensDistortion _lensDistortion;
|
||||||
|
private MotionBlur _motionBlur;
|
||||||
|
|
||||||
|
// All the effect overrides
|
||||||
|
private Vignette _vignette;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
|
||||||
Instance = this;
|
Instance = this;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
// Get references for effects
|
// Get references for effects
|
||||||
volume.profile.TryGet(out vignette);
|
volume.profile.TryGet(out _vignette);
|
||||||
volume.profile.TryGet(out chromaticAberration);
|
volume.profile.TryGet(out _chromaticAberration);
|
||||||
volume.profile.TryGet(out motionBlur);
|
volume.profile.TryGet(out _motionBlur);
|
||||||
volume.profile.TryGet(out lensDistortion);
|
volume.profile.TryGet(out _lensDistortion);
|
||||||
volume.profile.TryGet(out colorAdjustments);
|
volume.profile.TryGet(out _colorAdjustments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if an effect is currently active
|
// Checks if an effect is currently active
|
||||||
public bool IsEffectActive()
|
public bool IsEffectActive()
|
||||||
{
|
{
|
||||||
return isEffectActive;
|
return _isEffectActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to trigger effects dynamically based on the effect name passed
|
// Function to trigger effects dynamically based on the effect name passed
|
||||||
public void TriggerEffect(string effectName)
|
public void TriggerEffect(string effectName)
|
||||||
{
|
{
|
||||||
// If an effect is already active, stop the current one
|
// If an effect is already active, stop the current one
|
||||||
if (isEffectActive)
|
if (_isEffectActive) StopEffect(_currentEffectName);
|
||||||
{
|
|
||||||
StopEffect(currentEffectName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the new effect
|
// Start the new effect
|
||||||
StartEffect(effectName);
|
StartEffect(effectName);
|
||||||
|
@ -95,8 +87,8 @@ public class PostProcessingManager : MonoBehaviour
|
||||||
// Start a specific effect
|
// Start a specific effect
|
||||||
public void StartEffect(string effectName)
|
public void StartEffect(string effectName)
|
||||||
{
|
{
|
||||||
isEffectActive = true;
|
_isEffectActive = true;
|
||||||
currentEffectName = effectName;
|
_currentEffectName = effectName;
|
||||||
|
|
||||||
StartCoroutine(ApplyEffect(effectName));
|
StartCoroutine(ApplyEffect(effectName));
|
||||||
}
|
}
|
||||||
|
@ -104,96 +96,83 @@ public class PostProcessingManager : MonoBehaviour
|
||||||
// Stop the active effect
|
// Stop the active effect
|
||||||
public void StopEffect()
|
public void StopEffect()
|
||||||
{
|
{
|
||||||
if (isEffectActive)
|
if (_isEffectActive) StopEffect(_currentEffectName);
|
||||||
{
|
|
||||||
StopEffect(currentEffectName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop a specific effect
|
// Stop a specific effect
|
||||||
private void StopEffect(string effectName)
|
private void StopEffect(string effectName)
|
||||||
{
|
{
|
||||||
isEffectActive = false;
|
_isEffectActive = false;
|
||||||
currentEffectName = "";
|
_currentEffectName = "";
|
||||||
|
|
||||||
// Reset effects to default
|
// Reset effects to default
|
||||||
if (vignette != null) vignette.intensity.Override(0f);
|
if (_vignette) _vignette.intensity.Override(0f);
|
||||||
if (chromaticAberration != null) chromaticAberration.intensity.Override(0f);
|
if (_chromaticAberration) _chromaticAberration.intensity.Override(0f);
|
||||||
if (motionBlur != null) motionBlur.intensity.Override(0f);
|
if (_motionBlur) _motionBlur.intensity.Override(0f);
|
||||||
if (lensDistortion != null) lensDistortion.intensity.Override(0f);
|
if (_lensDistortion) _lensDistortion.intensity.Override(0f);
|
||||||
if (colorAdjustments != null) colorAdjustments.postExposure.Override(0f);
|
if (_colorAdjustments) _colorAdjustments.postExposure.Override(0f);
|
||||||
|
|
||||||
// Stop the audio
|
// Stop the audio
|
||||||
if (audioSource != null)
|
if (audioSource) audioSource.Stop();
|
||||||
{
|
|
||||||
audioSource.Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applies effects over time based on the effect name
|
// Applies effects over time based on the effect name
|
||||||
private IEnumerator ApplyEffect(string effectName)
|
private IEnumerator ApplyEffect(string effectName)
|
||||||
{
|
{
|
||||||
// Handle audio for the effect
|
switch (effectName)
|
||||||
if (effectName == "Panic")
|
|
||||||
{
|
{
|
||||||
audioSource.clip = heartbeatSound;
|
// Handle audio for the effect
|
||||||
audioSource.loop = true;
|
case "Panic":
|
||||||
audioSource.Play();
|
audioSource.clip = heartbeatSound;
|
||||||
}
|
audioSource.loop = true;
|
||||||
else if (effectName == "Headache")
|
audioSource.Play();
|
||||||
{
|
break;
|
||||||
audioSource.clip = whisperSound;
|
case "Headache":
|
||||||
audioSource.loop = true;
|
audioSource.clip = whisperSound;
|
||||||
audioSource.Play();
|
audioSource.loop = true;
|
||||||
}
|
audioSource.Play();
|
||||||
else if (effectName == "Dizziness")
|
break;
|
||||||
{
|
case "Dizziness":
|
||||||
audioSource.clip = distortedWhisperSound;
|
audioSource.clip = distortedWhisperSound;
|
||||||
audioSource.loop = true;
|
audioSource.loop = true;
|
||||||
audioSource.Play();
|
audioSource.Play();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply effects while the effect is active
|
// Apply effects while the effect is active
|
||||||
while (isEffectActive)
|
while (_isEffectActive)
|
||||||
{
|
{
|
||||||
// Visual effects for headache
|
switch (effectName)
|
||||||
if (effectName == "Headache")
|
|
||||||
{
|
{
|
||||||
vignette.intensity.Override(vignetteIntensity.Evaluate(Time.time));
|
// Visual effects for headache
|
||||||
chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(Time.time));
|
case "Headache":
|
||||||
}
|
_vignette.intensity.Override(vignetteIntensity.Evaluate(Time.time));
|
||||||
|
_chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(Time.time));
|
||||||
// Visual effects for dizziness
|
break;
|
||||||
if (effectName == "Dizziness")
|
// Visual effects for dizziness
|
||||||
{
|
case "Dizziness":
|
||||||
motionBlur.intensity.Override(motionBlurIntensity.Evaluate(Time.time));
|
_motionBlur.intensity.Override(motionBlurIntensity.Evaluate(Time.time));
|
||||||
lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(Time.time));
|
_lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(Time.time));
|
||||||
}
|
break;
|
||||||
|
// Visual effects for panic
|
||||||
// Visual effects for panic
|
case "Panic":
|
||||||
if (effectName == "Panic")
|
_motionBlur.intensity.Override(motionBlurIntensity.Evaluate(Time.time));
|
||||||
{
|
_lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(Time.time));
|
||||||
motionBlur.intensity.Override(motionBlurIntensity.Evaluate(Time.time));
|
_chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(Time.time));
|
||||||
lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(Time.time));
|
break;
|
||||||
chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(Time.time));
|
case "Worst":
|
||||||
}
|
_vignette.intensity.Override(vignetteIntensity.Evaluate(Time.time));
|
||||||
|
_motionBlur.intensity.Override(motionBlurIntensity.Evaluate(Time.time));
|
||||||
if (effectName == "Worst")
|
_lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(Time.time));
|
||||||
{
|
_chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(Time.time));
|
||||||
vignette.intensity.Override(vignetteIntensity.Evaluate(Time.time));
|
_colorAdjustments.postExposure.Override(colorAdjustmentsIntensity.Evaluate(Time.time * 0.8f));
|
||||||
motionBlur.intensity.Override(motionBlurIntensity.Evaluate(Time.time));
|
break;
|
||||||
lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(Time.time));
|
|
||||||
chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(Time.time));
|
|
||||||
colorAdjustments.postExposure.Override(colorAdjustmentsIntensity.Evaluate(Time.time * 0.8f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return 0;
|
yield return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop audio after the effect ends
|
// Stop audio after the effect ends
|
||||||
if (audioSource != null && audioSource.isPlaying)
|
if (audioSource && audioSource.isPlaying) audioSource.Stop();
|
||||||
{
|
|
||||||
audioSource.Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue