68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
public class VignetteApplier : MonoBehaviour
|
|
{
|
|
public float intensity = 0.75f;
|
|
public float duration = 0.5f;
|
|
public Volume volume = null;
|
|
|
|
public LocomotionProvider locomotionProvider;
|
|
private Vignette vignette = null;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
if (volume.profile.TryGet(out Vignette vignette))
|
|
{
|
|
this.vignette = vignette;
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
locomotionProvider.beginLocomotion += FadeIn;
|
|
locomotionProvider.endLocomotion += FadeOut;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
locomotionProvider.beginLocomotion -= FadeIn;
|
|
locomotionProvider.endLocomotion -= FadeOut;
|
|
}
|
|
|
|
public void FadeIn(LocomotionSystem locomotion)
|
|
{
|
|
StartCoroutine(Fade(0, intensity));
|
|
}
|
|
public void FadeOut(LocomotionSystem locomotion)
|
|
{
|
|
StartCoroutine(Fade(intensity, 0));
|
|
}
|
|
|
|
private IEnumerator Fade(float startValue, float endValue)
|
|
{
|
|
float elapsedTime = 0.0f;
|
|
|
|
while (elapsedTime <= duration)
|
|
{
|
|
float blend = elapsedTime / duration;
|
|
elapsedTime += Time.deltaTime;
|
|
|
|
float intensity = Mathf.Lerp(startValue, endValue, blend);
|
|
Debug.Log(intensity);
|
|
ApplyValue(intensity);
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
private void ApplyValue(float value)
|
|
{
|
|
vignette.intensity.Override(value);
|
|
}
|
|
}
|