다면 컨텐츠에서의 Fade in Fade out을 하고싶었다
Post processing의 color adjustment를 사용해 전체 화면자체에 post exposure 값을 조절한다
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System.Collections;
public class VolumeController : MonoBehaviour
{
[SerializeField] private Volume globalVolume; // 인스펙터에서 Global Volume 할당
private ColorAdjustments colorAdjustments;
[SerializeField] private float duration = 2f; // 변화하는 데 걸리는 시간 (초 단위)
void Start()
{
if (globalVolume.profile.TryGet(out colorAdjustments))
{
// 시작할 때 -20에서 0으로 올라가도록 실행
colorAdjustments.postExposure.value = -20f;
StartCoroutine(CoExposure(-20f, 0f));
}
else
{
Debug.LogWarning("Color Adjustments override가 Volume Profile에 없음.");
}
}
public IEnumerator CoExposure(float start, float end, bool isDouble = false)
{
float startValue = start;
float endValue = end;
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = Mathf.Clamp01(elapsed / duration);
colorAdjustments.postExposure.value = Mathf.Lerp(startValue, endValue, t);
yield return null;
}
if (isDouble)
{
StartCoroutine(CoExposure(-20f, 0f));
}
}
public void StartFadeOut()
{
StartCoroutine(CoExposure(0f, -20f));
}
public void StartWhiteFade()
{
StartCoroutine(CoFinishTimeline());
}
IEnumerator CoFinishTimeline()
{
yield return StartCoroutine(CoExposure(0f, -20f, true));
yield return StartCoroutine(CoRestartTimeline());
}
private IEnumerator CoRestartTimeline()
{
yield return new WaitForSeconds(2f);
}
}
728x90
반응형
'공부 > Unity' 카테고리의 다른 글
[Unity] exe 파일이 차단당했을때 (스마트 앱 컨트롤 차단) (0) | 2025.09.22 |
---|---|
[Unity] is using a shader without GPU deformation support. Switching the renderer over to CPU deformation. Shader 오류 (0) | 2025.09.15 |
[Unity] URP 3D 환경에서 2D 리깅 안 될때 (2D Animation, Skinning Editor) (0) | 2025.09.15 |
[Unity] 애니메이터 랜덤 딜레이 시간 (0) | 2025.09.01 |
[Unity] Shader URP 물 속 효과 주기 (화면 꿀렁이기) (2) | 2025.08.28 |