using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
[LuaCallCSharp]
public class SoundManager : MonoBehaviour
{
private float bgmVolumScale = 1f; //背景音乐声音大小比例
private float effVolumScale = 0.5f; //音效声音大小比例
public List<AudioSource> audioSourceList = new List<AudioSource>(); //音效播放器
private AudioSource musicAudio; //背景音乐播放器
GameObject thisObj;
Transform thisTrans;
// Start is called before the first frame update
public static SoundManager Init()
{
GameObject obj = new GameObject("SoundManager");
SoundManager soundManager = obj.AddComponent<SoundManager>();
obj.AddComponent<AudioListener>();
return soundManager;
}
private void Awake()
{
thisObj = gameObject;
thisTrans = transform;
//存储关闭时的音量比例
if (PlayerPrefs.HasKey("bgmVolumScale"))
bgmVolumScale = PlayerPrefs.GetFloat("bgmVolumScale");
if (PlayerPrefs.HasKey("effVolumScale"))
effVolumScale = PlayerPrefs.GetFloat("effVolumScale");
musicAudio = gameObject.AddComponent<AudioSource>();
musicAudio.playOnAwake = false;
musicAudio.loop = true;
musicAudio.volume = bgmVolumScale;
//FadeVolumeScale = FadeVolume / FadeDistance;
InitAudioSources();
DontDestroyOnLoad(gameObject);
}
//增加as组件播放器
void InitAudioSources()
{
for (int i = 0; i < 20; i++)
{