Add DamagePostProcess component for enhanced visual feedback on damage; implement vignette effect and adjust flash color settings
This commit is contained in:
@@ -10,7 +10,6 @@ namespace Systems
|
||||
private static readonly int MarkerFlashColor = Shader.PropertyToID("_FlashColor");
|
||||
private static readonly int MarkerFlashAmount = Shader.PropertyToID("_FlashAmount");
|
||||
private Material material;
|
||||
private Coroutine damageFlashCoroutine;
|
||||
|
||||
[SerializeField] private float flashDuration;
|
||||
[ColorUsage(true, true)][SerializeField] private Color flashColor = Color.white;
|
||||
@@ -38,7 +37,7 @@ namespace Systems
|
||||
|
||||
private void OnHit()
|
||||
{
|
||||
damageFlashCoroutine = StartCoroutine(Flash());
|
||||
StartCoroutine(Flash());
|
||||
}
|
||||
|
||||
private IEnumerator Flash()
|
||||
|
||||
66
Assets/Scripts/Systems/DamagePostProcess.cs
Normal file
66
Assets/Scripts/Systems/DamagePostProcess.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Collections;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class DamagePostProcess : MonoBehaviour
|
||||
{
|
||||
private float ogVignetteIntensity;
|
||||
private Coroutine runningEffect;
|
||||
|
||||
[SerializeField, Scene] private Volume globalVolume;
|
||||
[SerializeField, Self] private Health health;
|
||||
[SerializeField] private float postProcessDuration = 0.5f;
|
||||
|
||||
[SerializeField] private float vignetteHitIntensity = 0.5f;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
health.OnTakeDamage += OnHit;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
health.OnTakeDamage -= OnHit;
|
||||
}
|
||||
|
||||
private void OnHit()
|
||||
{
|
||||
if (runningEffect != null) StopCoroutine(runningEffect);
|
||||
|
||||
runningEffect = StartCoroutine(ApplyPostProcessEffect());
|
||||
}
|
||||
|
||||
private IEnumerator ApplyPostProcessEffect()
|
||||
{
|
||||
if (!globalVolume) yield break;
|
||||
|
||||
if (!globalVolume.profile.TryGet<Vignette>(out var vignette))
|
||||
yield break;
|
||||
|
||||
ogVignetteIntensity = vignette.intensity.value;
|
||||
globalVolume.profile.TryGet<ChromaticAberration>(out var chromaticAberration);
|
||||
|
||||
vignette.intensity.value = vignetteHitIntensity;
|
||||
if (chromaticAberration) chromaticAberration.active = true;
|
||||
|
||||
yield return new WaitForSeconds(postProcessDuration);
|
||||
|
||||
float fade = 0f, fadeDuration = 0.25f;
|
||||
while (fade < fadeDuration)
|
||||
{
|
||||
fade += Time.deltaTime;
|
||||
vignette.intensity.value = Mathf.Lerp(vignetteHitIntensity, ogVignetteIntensity, fade / fadeDuration);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
vignette.intensity.value = ogVignetteIntensity;
|
||||
if (chromaticAberration) chromaticAberration.active = false;
|
||||
|
||||
runningEffect = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Systems/DamagePostProcess.cs.meta
Normal file
3
Assets/Scripts/Systems/DamagePostProcess.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dd1de1bc65a4912a543ebc7230f4ae6
|
||||
timeCreated: 1752337882
|
||||
Reference in New Issue
Block a user