feat: add config sound setting.
This commit is contained in:
@@ -69,3 +69,4 @@ MonoBehaviour:
|
||||
- title: Config 6
|
||||
fShow: 100
|
||||
fHide: 115
|
||||
audioMixer: {fileID: 24100000, guid: 9c6a7598ca0dfcd4fa51470ebbdd7549, type: 2}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
@@ -13,10 +14,11 @@ namespace BrewMonster
|
||||
[SerializeField] private List<ViewDistance> viewDistanceCfg;
|
||||
[SerializeField] private List<ViewDistance> viewDistanceNPCCfg;
|
||||
[SerializeField] private List<ViewDistance> viewDistanceEPCfg;
|
||||
|
||||
[SerializeField] private AudioMixer audioMixer;
|
||||
public List<ViewDistance> GetViewDistanceCfg { get => viewDistanceCfg;}
|
||||
public List<ViewDistance> GetViewDistanceNPCCfg { get => viewDistanceNPCCfg;}
|
||||
public List<ViewDistance> GetViewDistanceEPCfg { get => viewDistanceEPCfg;}
|
||||
public AudioMixer GetAudioMixer { get => audioMixer;}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -49,6 +49,18 @@ namespace BrewMonster.Network
|
||||
private readonly static string keySettingActiveShadow = "_keySettingActiveShadow";
|
||||
private readonly static string keySettingActiveFullResolution = "_keySettingActiveFullResolution";
|
||||
private readonly static string keySettingActiveFog = "_keySettingActiveFog";
|
||||
|
||||
private readonly static string keySettingVolumeSoundMaster = "_keySettingVolumeSoundMaster";
|
||||
private readonly static string keySettingVolumeSoundSFX = "_keySettingVolumeSoundSFX";
|
||||
private readonly static string keySettingVolumeBgrMusic = "_keySettingVolumeBgrMusic";
|
||||
private readonly static string keySettingSoundMaster = "_keySettingSoundMaster";
|
||||
private readonly static string keySettingSoundSFX = "_keySettingSoundSFX";
|
||||
private readonly static string keySettingBgrMusic = "_keySettingBgrMusic";
|
||||
|
||||
private readonly static string keyMaster = "Master";
|
||||
private readonly static string keyMusic = "Music";
|
||||
private readonly static string keySFX = "SFX";
|
||||
|
||||
private static ViewDistance m_viewDistance;
|
||||
private static ViewDistance m_viewDistanceNPC;
|
||||
private static ViewDistance m_viewDistanceEP;
|
||||
@@ -693,6 +705,103 @@ namespace BrewMonster.Network
|
||||
int index = PlayerPrefs.GetInt(keySettingActiveFog, defaultValue: 1);
|
||||
return index == 1;
|
||||
}
|
||||
|
||||
public static void SetActiveSoundMaster(bool value)
|
||||
{
|
||||
PlayerPrefs.SetInt(keySettingSoundMaster, value ? 1 : 0);
|
||||
if (value)
|
||||
{
|
||||
float index = PlayerPrefs.GetInt(keySettingVolumeSoundMaster, defaultValue: 6);
|
||||
float dB = Mathf.Log10(index / 6) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keyMaster, dB);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dB = Mathf.Log10(0.0001f) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keyMaster, dB);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetActiveSoundMaster()
|
||||
{
|
||||
return PlayerPrefs.GetInt(keySettingSoundMaster, 1) == 1;
|
||||
}
|
||||
|
||||
public static void SetVolumeSoundMaster(int value)
|
||||
{
|
||||
bool isActive = GetActiveSoundMaster();
|
||||
PlayerPrefs.SetInt(keySettingVolumeSoundMaster, value);
|
||||
if (isActive)
|
||||
{
|
||||
float dB = Mathf.Log10(value / 6) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keyMaster, dB);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetActiveSoundSFX(bool value)
|
||||
{
|
||||
PlayerPrefs.SetInt(keySettingSoundSFX, value ? 1 : 0);
|
||||
if (value)
|
||||
{
|
||||
float index = PlayerPrefs.GetInt(keySettingVolumeSoundSFX, defaultValue: 6);
|
||||
float dB = Mathf.Log10(index / 6) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keySFX, dB);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dB = Mathf.Log10(0.0001f) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keySFX, dB);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetActiveSoundSFX()
|
||||
{
|
||||
return PlayerPrefs.GetInt(keySettingSoundSFX, 1) == 1;
|
||||
}
|
||||
|
||||
public static void SetVolumeSoundSFX(int value)
|
||||
{
|
||||
bool isActive = GetActiveSoundMaster() && GetActiveSoundSFX();
|
||||
PlayerPrefs.SetInt(keySettingVolumeSoundMaster, value);
|
||||
if (isActive)
|
||||
{
|
||||
float dB = Mathf.Log10(value / 6) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keySFX, dB);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetActiveSoundMusic(bool value)
|
||||
{
|
||||
PlayerPrefs.SetInt(keySettingBgrMusic, value ? 1 : 0);
|
||||
if (value)
|
||||
{
|
||||
float index = PlayerPrefs.GetInt(keySettingVolumeBgrMusic, defaultValue: 6);
|
||||
float dB = Mathf.Log10(index / 6) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keyMusic, dB);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dB = Mathf.Log10(0.0001f) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keyMusic, dB);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetActiveBgrMusic()
|
||||
{
|
||||
return PlayerPrefs.GetInt(keySettingBgrMusic, 1) == 1;
|
||||
}
|
||||
|
||||
public static void SetVolumeBgrMusic(int value)
|
||||
{
|
||||
bool isActive = GetActiveSoundMaster() && GetActiveBgrMusic();
|
||||
PlayerPrefs.SetInt(keySettingVolumeSoundMaster, value);
|
||||
if (isActive)
|
||||
{
|
||||
float dB = Mathf.Log10(value / 6) * 20; // setting sound is 6
|
||||
GameRunConfigSO.GetAudioMixer.SetFloat(keyMusic, dB);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user