game(scripts): making a postprocessingmanager to handle all effects + edits
This commit is contained in:
parent
28c2579865
commit
09d296149d
5 changed files with 194 additions and 75 deletions
|
@ -2,7 +2,9 @@
|
||||||
Author: Wai Lam
|
Author: Wai Lam
|
||||||
Date: 27/1/25
|
Date: 27/1/25
|
||||||
Description: Bathroom interaction
|
Description: Bathroom interaction
|
||||||
*/using System.Collections;
|
*/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
@ -12,79 +14,8 @@ using UnityEngine.XR.Interaction.Toolkit.Interactors;
|
||||||
|
|
||||||
public class BrushTeeth : MonoBehaviour
|
public class BrushTeeth : MonoBehaviour
|
||||||
{
|
{
|
||||||
// public Slider progressBar; // Reference to the Slider (progress bar)
|
public PostProcessingManager postProcessingManager;
|
||||||
// public float progressTime = 5f; // Time for the progress bar to complete
|
|
||||||
// private UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable grabInteractable;
|
|
||||||
// private float timer = 0f;
|
|
||||||
// private bool isGrabbing = false;
|
|
||||||
//
|
|
||||||
// void Start()
|
|
||||||
// {
|
|
||||||
// grabInteractable = GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
|
||||||
//
|
|
||||||
// if (grabInteractable == null)
|
|
||||||
// {
|
|
||||||
// Debug.LogError("XRGrabInteractable component not found on the object!");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Ensure the progress bar is hidden initially
|
|
||||||
// progressBar.gameObject.SetActive(false);
|
|
||||||
//
|
|
||||||
// // Subscribe to grab and release events
|
|
||||||
// grabInteractable.selectEntered.AddListener(OnGrab);
|
|
||||||
// grabInteractable.selectExited.AddListener(OnRelease);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void Update()
|
|
||||||
// {
|
|
||||||
// if (isGrabbing)
|
|
||||||
// {
|
|
||||||
// timer += Time.deltaTime;
|
|
||||||
// progressBar.value = timer / progressTime;
|
|
||||||
//
|
|
||||||
// if (timer >= progressTime)
|
|
||||||
// {
|
|
||||||
// CompleteProgress();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void OnGrab(SelectEnterEventArgs args)
|
|
||||||
// {
|
|
||||||
// // Show and reset the progress bar
|
|
||||||
// progressBar.gameObject.SetActive(true);
|
|
||||||
// progressBar.value = 0f;
|
|
||||||
// timer = 0f;
|
|
||||||
// isGrabbing = true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void OnRelease(SelectExitEventArgs args)
|
|
||||||
// {
|
|
||||||
// // Hide the progress bar and stop the timer
|
|
||||||
// progressBar.gameObject.SetActive(false);
|
|
||||||
// isGrabbing = false;
|
|
||||||
// timer = 0f;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void CompleteProgress()
|
|
||||||
// {
|
|
||||||
// // Hide the progress bar and perform any additional actions when complete
|
|
||||||
// progressBar.gameObject.SetActive(false);
|
|
||||||
// isGrabbing = false;
|
|
||||||
//
|
|
||||||
// Debug.Log("Progress completed!");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void OnDestroy()
|
|
||||||
// {
|
|
||||||
// // Unsubscribe from events to avoid memory leaks
|
|
||||||
// if (grabInteractable != null)
|
|
||||||
// {
|
|
||||||
// grabInteractable.selectEntered.RemoveListener(OnGrab);
|
|
||||||
// grabInteractable.selectExited.RemoveListener(OnRelease);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
public Slider progressBar; // Reference to the Slider (progress bar)
|
public Slider progressBar; // Reference to the Slider (progress bar)
|
||||||
public float progressTime = 5f; // Time for the progress bar to complete
|
public float progressTime = 5f; // Time for the progress bar to complete
|
||||||
private XRGrabInteractable grabInteractable;
|
private XRGrabInteractable grabInteractable;
|
||||||
|
|
132
Game/Assets/Scripts/PostProcessingManager.cs
Normal file
132
Game/Assets/Scripts/PostProcessingManager.cs
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/*
|
||||||
|
Author: Reza
|
||||||
|
Date: 7/2/25
|
||||||
|
Description: Has all the post processing camera effects that replicate real symptoms like dizziness, fainting, panic, etc
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
using UnityEngine.Rendering.Universal;
|
||||||
|
|
||||||
|
public class PostProcessingManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Defines the Global 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")]
|
||||||
|
// Editable override values in inspector
|
||||||
|
[SerializeField]
|
||||||
|
public AnimationCurve vignetteIntensity;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public AnimationCurve chromaticAberrationIntensity;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public AnimationCurve motionBlurIntensity;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public AnimationCurve lensDistortionIntensity;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public AnimationCurve colorAdjustmentsIntensity;
|
||||||
|
|
||||||
|
// Checks if effect is active or not
|
||||||
|
private bool isEffectActive = false;
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
// Get references for effects
|
||||||
|
volume.profile.TryGet(out vignette);
|
||||||
|
volume.profile.TryGet(out chromaticAberration);
|
||||||
|
volume.profile.TryGet(out motionBlur);
|
||||||
|
volume.profile.TryGet(out lensDistortion);
|
||||||
|
volume.profile.TryGet(out colorAdjustments);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to start effects if there is none currently, and stop current effects to start next ones
|
||||||
|
public void TriggerEffect(string effectName)
|
||||||
|
{
|
||||||
|
// If an effect is already active
|
||||||
|
if (isEffectActive)
|
||||||
|
{
|
||||||
|
// Stop the effect
|
||||||
|
StopEffect(effectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no active effects
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Start the effect
|
||||||
|
StartEffect(effectName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to start the effect
|
||||||
|
private void StartEffect(string effectName)
|
||||||
|
{
|
||||||
|
// The effect is active
|
||||||
|
isEffectActive = true;
|
||||||
|
|
||||||
|
// Calls coroutine to apply the effect
|
||||||
|
StartCoroutine(ApplyEffect(effectName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to stop the effect
|
||||||
|
private 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Applies effects over time based on the type
|
||||||
|
private IEnumerator ApplyEffect(string effectName)
|
||||||
|
{
|
||||||
|
float time = 0f;
|
||||||
|
float timeToMax = 1f;
|
||||||
|
|
||||||
|
while (time < timeToMax)
|
||||||
|
{
|
||||||
|
time += Time.deltaTime;
|
||||||
|
time = Mathf.Clamp01(time);
|
||||||
|
|
||||||
|
// Values for headache effect
|
||||||
|
if (effectName == "Headache")
|
||||||
|
{
|
||||||
|
vignette.intensity.Override(vignetteIntensity.Evaluate(time));
|
||||||
|
chromaticAberration.intensity.Override(chromaticAberrationIntensity.Evaluate(time));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Values for dizziness effect
|
||||||
|
else if (effectName == "Dizziness")
|
||||||
|
{
|
||||||
|
motionBlur.intensity.Override(motionBlurIntensity.Evaluate(time));
|
||||||
|
lensDistortion.intensity.Override(lensDistortionIntensity.Evaluate(time));
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Game/Assets/Scripts/PostProcessingManager.cs.meta
Normal file
11
Game/Assets/Scripts/PostProcessingManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 46e96ab748a3a844f9137261de774bfe
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
34
Game/Assets/Scripts/VignetteBreathing.cs
Normal file
34
Game/Assets/Scripts/VignetteBreathing.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
using UnityEngine.Rendering.Universal;
|
||||||
|
|
||||||
|
public class VignetteBreathing : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
public Volume postProcessingVolume;
|
||||||
|
|
||||||
|
private Vignette vignette;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public AnimationCurve intensityCurve; // Assign in Inspector
|
||||||
|
public float cycleDuration = 3f; // Time for one full cycle
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
if (postProcessingVolume.profile.TryGet(out vignette))
|
||||||
|
{
|
||||||
|
Debug.Log("Vignette found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (vignette != null)
|
||||||
|
{
|
||||||
|
float t = (Time.time % cycleDuration) / cycleDuration; // Loop 0-1 over time
|
||||||
|
vignette.intensity.Override(intensityCurve.Evaluate(t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Game/Assets/Scripts/VignetteBreathing.cs.meta
Normal file
11
Game/Assets/Scripts/VignetteBreathing.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4e25f510b8cc01f4e8a29b3995d1bde9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Add table
Reference in a new issue