34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal; // Assuming URP. Change if using built-in or HDRP.
|
|
|
|
public class BrightnessController : MonoBehaviour
|
|
{
|
|
[SerializeField] private Volume postProcessVolume;
|
|
private ColorAdjustments colorAdjustments;
|
|
|
|
private void Start()
|
|
{
|
|
if (postProcessVolume != null && postProcessVolume.profile.TryGet(out colorAdjustments))
|
|
{
|
|
// Successfully found the ColorAdjustments effect
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("BrightnessController could not find a Volume with ColorAdjustments.", this);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the brightness.
|
|
/// </summary>
|
|
/// <param name="value">A value from 0 (dark) to 1 (bright).</param>
|
|
public void SetBrightness(float value)
|
|
{
|
|
if (colorAdjustments != null)
|
|
{
|
|
// We map the 0-1 slider value to a new exposure range, e.g., -1 to 1.4.
|
|
colorAdjustments.postExposure.value = Mathf.Lerp(-1f, 1.4f, value);
|
|
}
|
|
}
|
|
} |