Last active
February 9, 2018 06:50
-
-
Save TakaakiIchijo/69eefdc44183f4ddea035a7fee8ef0ac to your computer and use it in GitHub Desktop.
UnityのAudioMixerはDecibelでボリュームを設定するので0f~1.0fのLinear値に変換してSetしたりGetしたりする関数
This file contains hidden or 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
public AudioMixer mixer; | |
public void SetLinearVolumeToMixerGroup(string mixerGroupName, float linearVolume) | |
{ | |
float decibel = 20.0f * Mathf.Log10(linearVolume); | |
if (float.IsNegativeInfinity(decibel)) | |
{ | |
decibel = -96f; | |
} | |
mixer.SetFloat(mixerGroupName, decibel); | |
} | |
public float GetLinearVolumeFromMixerGroup(string mixerGroupName) | |
{ | |
float decibel; | |
mixer.GetFloat(mixerGroupName, out decibel); | |
return Mathf.Pow(10f, decibel / 20f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ありがとうございます。無音にしたいときは-96dbを与えるようにしました。