Forum rules - please read before posting.

Brightness settings in AC

Hey Chris,
I'm trying to implement a brightness option in the options menu that would allow players to increase or reduce the brightness of the game. Since AC doesn't have built-in brightness support, what is the best approach to implement it?

Comments

  • You'd first need a means to control the brightness through custom script, based on your chosen render pipeline. This isn't an AC topic, but you should be able to find plenty of resources for this online.

    Once you have a script that can sync the brightness with a float variable (i.e. 0 = most dark, 1 = most bright), you can link it to an AC Global Float variable that's linked to Options Data so that its value is saved per-Profile.

    A tutorial that covers this process can be found here. The key difference would be the custom script's Apply function, which would instead set the brightness instead of the text-scroll speed.

  • BikBik
    edited August 11

    Thank you, Chris.
    I created two scripts (with some help from AI): one is attached to the UI slider, and the other is attached to every scene in the game. They seem to be working well. I’m sharing the scripts here in case other members want to use them.

    1) Attach this script to your scene, then drag the Global Light 2D object into the Global Light field.

    using UnityEngine;
    using UnityEngine.Rendering.Universal; // For Light2D
    
    public class BrightnessController : MonoBehaviour
    {
        public Light2D globalLight;
        public static BrightnessController instance;
    
        private const string BrightnessKey = "BrightnessValue";
    
        private void Awake()
        {
            instance = this;
        }
    
        private void Start()
        {
            float savedBrightness = PlayerPrefs.GetFloat(BrightnessKey, 0.5f);
            ApplyBrightness(savedBrightness);
        }
    
        public void ApplyBrightness(float value)
        {
            if (globalLight != null)
            {
                globalLight.intensity = value;
            }
            PlayerPrefs.SetFloat(BrightnessKey, value);
        }
    }
    

    2) Attach this script to your Brightness slider:

    using UnityEngine;
    using UnityEngine.UI;
    
    public class BrightnessSlider : MonoBehaviour
    {
        private Slider slider;
        private const string BrightnessKey = "BrightnessValue";
    
        private void Start()
        {
            slider = GetComponent<Slider>();
    
            float savedBrightness = PlayerPrefs.GetFloat(BrightnessKey, 0.5f);
            slider.value = savedBrightness;
    
            slider.onValueChanged.AddListener(OnSliderChanged);
        }
    
        private void OnSliderChanged(float value)
        {
            if (BrightnessController.instance != null)
            {
                BrightnessController.instance.ApplyBrightness(value);
            }
        }
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.