99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
|
using Thousandto.Core.Asset;
|
|||
|
using Thousandto.Core.Support;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace Thousandto.Code.Logic
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 声音配置
|
|||
|
/// </summary>
|
|||
|
public class SoundSetting : SettingProcessBase
|
|||
|
{
|
|||
|
|
|||
|
#region//继承父类的函数,初始化,注册函数
|
|||
|
protected override void OnRegisterSettingChangedHandler()
|
|||
|
{
|
|||
|
base.OnRegisterSettingChangedHandler();
|
|||
|
AddSettingChangedHandler(GameSettingKeyCode.EnableBGMusic, OnEnableBGMusicChanged);
|
|||
|
AddSettingChangedHandler(GameSettingKeyCode.EnableSound, OnEnableSoundChanged);
|
|||
|
AddSettingChangedHandler(GameSettingKeyCode.BGMusicVolume, OnBGMusicVolumeChanged);
|
|||
|
AddSettingChangedHandler(GameSettingKeyCode.SoundVolume, OnSoundVolumeChanged);
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnLoadDefault(bool isforce, bool save)
|
|||
|
{
|
|||
|
//背景音乐,默认开启
|
|||
|
GameSettingCore.SetUnSave(GameSettingKeyCode.EnableBGMusic, 1, isforce);
|
|||
|
//音效,默认开启
|
|||
|
GameSettingCore.SetUnSave(GameSettingKeyCode.EnableSound, 1, isforce);
|
|||
|
//背景音乐音量
|
|||
|
GameSettingCore.SetUnSave(GameSettingKeyCode.BGMusicVolume, 100, isforce);
|
|||
|
//音效音量
|
|||
|
GameSettingCore.SetUnSave(GameSettingKeyCode.SoundVolume, 100, isforce);
|
|||
|
|
|||
|
if(save)
|
|||
|
{
|
|||
|
GameSettingCore.Save();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region //声音配置改变后的处理函数
|
|||
|
public void OnEnableBGMusicChanged(int value)
|
|||
|
{
|
|||
|
if (value <= 0)
|
|||
|
{
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Music, 0f);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OnBGMusicVolumeChanged(GameSettingCore.Get(GameSettingKeyCode.BGMusicVolume));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//开启音效的配置改变
|
|||
|
public void OnEnableSoundChanged(int value)
|
|||
|
{
|
|||
|
if (value <= 0)
|
|||
|
{
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Ambient, 0f);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Sfx, 0f);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Speech, 0f);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.UI, 0f);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OnSoundVolumeChanged(GameSettingCore.Get(GameSettingKeyCode.SoundVolume));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//背景音乐音量
|
|||
|
public void OnBGMusicVolumeChanged(int value)
|
|||
|
{
|
|||
|
if (GameSettingCore.Get(GameSettingKeyCode.EnableBGMusic) > 0.5)
|
|||
|
{
|
|||
|
float v = UnityEngine.Mathf.Min(UnityEngine.Mathf.Max(0f, (float)value / 100f), 1f);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Music, v);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//音效的音量
|
|||
|
public void OnSoundVolumeChanged(int value)
|
|||
|
{
|
|||
|
if (GameSettingCore.Get(GameSettingKeyCode.EnableSound) > 0.5)
|
|||
|
{
|
|||
|
float v = UnityEngine.Mathf.Min(UnityEngine.Mathf.Max(0f, (float)value / 100f), 1f);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Ambient, v);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Sfx, v);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.Speech, v);
|
|||
|
AudioPlayer.SetVolume(AudioTypeCode.UI, v);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|