Created
March 12, 2021 06:06
-
-
Save tk009999/dd52f1b56ed7c79a08dd129dddb22e86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace UnityEngine.Audio | |
{ | |
public static class AudioExtensions | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="mixer"></param> | |
/// <param name="exposedName">The name of 'The Exposed to Script' variable</param> | |
/// <param name="value">value must be between 0 and 1</param> | |
public static void SetVolume(this AudioMixer mixer, string exposedName, float value) | |
{ | |
mixer.SetFloat(exposedName, Mathf.Lerp(-80.0f, 0.0f, Mathf.Clamp01(value))); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="mixer"></param> | |
/// <param name="exposedName">The name of 'The Exposed to Script' variable</param> | |
/// <returns></returns> | |
public static float GetVolume(this AudioMixer mixer, string exposedName) | |
{ | |
if (mixer.GetFloat(exposedName, out float volume)) | |
{ | |
return Mathf.InverseLerp(-80.0f, 0.0f, volume); | |
} | |
return 0f; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment