using System.Collections; using BlueWater.Utility; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; namespace BlueWater { public enum RendererFeatureName { None = 0, GrayscaleRenderPassFeature } public class PostProcessingManager : Singleton { private UniversalRenderPipelineAsset _currentRenderPipeline; private ScriptableRendererData _currentRenderData; private Volume _currentVolume; private Coroutine _lowHpVignetteCoroutine; protected override void OnAwake() { Initialize(); } protected override void OnApplicationQuit() { ToggleRendererFeature(RendererFeatureName.GrayscaleRenderPassFeature, false); } private void Initialize() { _currentRenderPipeline = (UniversalRenderPipelineAsset)GraphicsSettings.currentRenderPipeline; _currentRenderData = _currentRenderPipeline.rendererDataList[0]; _currentVolume = GetComponent(); } public void ToggleRendererFeature(RendererFeatureName featureName, bool value) { foreach (var element in _currentRenderData.rendererFeatures) { if (!string.Equals(element.name, featureName.ToString())) continue; element.SetActive(value); return; } Debug.Log($"{featureName}과 일치하는 기능이 없습니다."); } public void ToggleEffect(bool value) where T : VolumeComponent { if (!_currentVolume) return; var effect = GetEffect(); if (!effect) { print(typeof(T) + "효과가 없습니다."); return; } effect.active = value; } private T GetEffect() where T : VolumeComponent { if (!_currentVolume) return null; _currentVolume.profile.TryGet(out T effect); return effect; } public void LowHpVignette() { Utils.StartUniqueCoroutine(this, ref _lowHpVignetteCoroutine, LowHpVignetteCoroutine()); } public void DefaultHpVignette() { Utils.EndUniqueCoroutine(this, ref _lowHpVignetteCoroutine); ToggleEffect(false); } private IEnumerator LowHpVignetteCoroutine() { var startValue = 0.2f; var endValue = 0.3f; var time = 0f; var vignette = GetEffect(); vignette.intensity.value = startValue; vignette.active = true; while (true) { time += Time.deltaTime * 2f; vignette.intensity.value = Mathf.Lerp(startValue, endValue, time); if (time >= 1f) { (startValue, endValue) = (endValue, startValue); time = 0f; } yield return null; } } } }