You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
81 lines
2.3 KiB
3 years ago
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
[ComponentOf(typeof(Scene))]
|
||
|
public class SoundComponent: Entity, IAwake
|
||
|
{
|
||
|
public static SoundComponent Instance;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 控制游戏全局音量
|
||
|
/// </summary>
|
||
|
public float SoundVolume
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return _soundVolume;
|
||
|
}
|
||
|
set
|
||
|
{
|
||
|
_soundVolume = Mathf.Clamp(value, 0, 1);
|
||
|
foreach (SoundData clip in m_clips.Values)
|
||
|
{
|
||
|
clip.Volume = _soundVolume * clip.volume;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public float _soundVolume = 0.8f;
|
||
|
|
||
|
//所有音效
|
||
|
public Dictionary<string, SoundData> m_clips = new Dictionary<string, SoundData>();
|
||
|
|
||
|
//根据类型分类所有音效
|
||
|
public Dictionary<SoundType, Dictionary<string, SoundData>> _allClips = new Dictionary<SoundType, Dictionary<string, SoundData>>()
|
||
|
{ { SoundType.Music, new Dictionary<string, SoundData>() }, { SoundType.Sound, new Dictionary<string, SoundData>() } };
|
||
|
|
||
|
//catch ab资源
|
||
|
public static Dictionary<string, SoundData> abSounds = new Dictionary<string, SoundData>();
|
||
|
|
||
|
//根物体
|
||
|
public Transform root;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 音乐静音
|
||
|
/// </summary>
|
||
|
public bool MusicMute
|
||
|
{
|
||
|
get { return _musicMute; }
|
||
|
set
|
||
|
{
|
||
|
_musicMute = value;
|
||
|
foreach (var soundData in _allClips[SoundType.Music].Values)
|
||
|
{
|
||
|
soundData.Mute = _musicMute;
|
||
|
}
|
||
|
PlayerPrefs.SetInt("MusicMute", value ? 1 : 0);
|
||
|
}
|
||
|
}
|
||
|
public bool _musicMute = false;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 音效静音
|
||
|
/// </summary>
|
||
|
public bool SoundMute
|
||
|
{
|
||
|
get { return _soundMute; }
|
||
|
set
|
||
|
{
|
||
|
_soundMute = value;
|
||
|
foreach (var soundData in _allClips[SoundType.Sound].Values)
|
||
|
{
|
||
|
soundData.Mute = _soundMute;
|
||
|
}
|
||
|
PlayerPrefs.SetInt("SoundMute", value ? 1 : 0);
|
||
|
}
|
||
|
}
|
||
|
public bool _soundMute = false;
|
||
|
}
|
||
|
}
|