uop-libraries/CreativeResponse2022

[Options] Audio and SFX toggles do not display the correct state

Closed this issue ยท 10 comments

Options Page

Audio and SFX toggles do not display the correct state

Tasks

  • Have options toggles display correct state

Notes

Simplest is probably reading the current volume from the audio mixer and using that to set the toggle's state. I just personally haven't had time to do this.

FYI, the mixer uses a slightly different format for volume than an audio source. Instead of float 0 (volume off) to 1 (full volume) it uses float -80 (volume off) to 0 (default level).

I managed to adjust the script so that the current state of the button is preserved OnDestroy() and DontDestroyOnLoad setting the switch itself inactive so that it cannot be interacted with upon entering other scenes.

Though the behaviors work as intended such that when switching scene if the button says On while music is actually Off, pressing the button again does not suddenly turn audio on; we still run into the issue of the visual aspect not being preserved.

I will have to look further into this because Audio Mixers unfortunately do not have a simple method to get their current volume.

The variables for the Audio and SFX mixer channels should have their volumes as an exposed variable, that's how I've been setting them.

AudioMixer.GetFloat("MusicMasterVol") and AudioMixer.GetFloat("SFXMasterVol") should return the current values.

I'll take a look at this in a few minutes.

I had tried to use the GetFloat function at first, though it actually takes in 2 parameters with one being the name and the other being the out float value. Unity's documentation on this function isn't really the best.

Ok I have managed a way to preserve the visual behavior of the button, but now the audio itself does not carry over to reflect that
visual change. I will push what I have onto my branch if you would like to take a look at it @CCrawfordUOP.

Sounds good, yeah I'll take a look.

I'm thinking of adding another boolean variable to save the previous state of the music such that the boolean check (audioState for example) can also reflect that change because I noticed that when I was debugging I was able to preserve the .isOn behavior from the switch when changing scenes but not the boolean value of the check itself.

I think I've narrowed it down to a weird interaction with the ModenUI asset pack messing with the toggle's default state, though I don't know exactly what part is causing it.

I have a proof of concept implementation that works using a toggle from the default Unity UI objects on the cube-testing branch if you want to take a look.

Honestly thinking about it, what do we really lose deciding to go for the default Unity UI over the Modern pack?

There is nothing to lose other than the aesthetic ripple the buttons have present throughout the app. If it works by using the default button, go for it.

Fixed in cube-testing branch.