Esempio n. 1
0
    /// <summary>
    /// ボリュームの取得
    /// </summary>
    /// <param name="soundCategory">サウンドカテゴリ</param>
    /// <returns>ボリューム (0-1)</returns>
    public float GetVolume(SoundCategory soundCategory)
    {
        string volumeName = null;

        switch (soundCategory)
        {
        case SoundCategory.Master: volumeName = MasterVolumeName; break;

        case SoundCategory.Bgm: volumeName = BgmVolumeName; break;

        case SoundCategory.Se: volumeName = SeVolumeName; break;

        case SoundCategory.Voice: volumeName = VoiceVolumeName; break;

        default: Debug.LogWarning($"Invalid SoundCategory. [soundCategory={soundCategory}]"); break;
        }

        if (!string.IsNullOrEmpty(volumeName))
        {
            audioMixer.GetFloat(volumeName, out float dbVolume);
            float volume = SoundUtil.CalcGetDbToVolume(dbVolume);
            return(volume);
        }
        else
        {
            return(0.0f);
        }
    }