using System.Collections; using BlueWater.Utility; using Sirenix.OdinInspector; 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; // LowHpVignette [Title("LowHpVignette")] [SerializeField] private bool _isLerpIntensity = true; [SerializeField] private float _startIntensity = 0.15f; [SerializeField, ShowIf("@_isLerpIntensity")] private float _endIntensity = 0.2f; [SerializeField, ShowIf("@_isLerpIntensity")] private float _lerpTime = 1f; 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 vignette = GetEffect(); vignette.intensity.value = _startIntensity; vignette.active = true; if (!_isLerpIntensity) yield break; var elapsedTime = 0f; var addTime = Time.deltaTime; while (true) { vignette.intensity.value = Mathf.Lerp(_startIntensity, _endIntensity, elapsedTime / _lerpTime); if (elapsedTime > _lerpTime) { addTime = -Time.deltaTime; } else if (elapsedTime < 0) { addTime = Time.deltaTime; } elapsedTime += addTime; yield return null; } } [Button("게임 실행 중 체력 깎기")] private void SetLowHp() { GameManager.Instance.CurrentCombatPlayer.SetCurrentHealthPoint(1); } } }