public AudioSource PlayLoop(AudioPlayArea playArea) { return(PlayOneShot(playArea, true)); }
public AudioSource PlayOneShot(AudioPlayArea playArea, bool loop = false) { if (loadedAudioclipDic.TryGetValue(playArea, out AudioClip tempClip)) { if (tempClip == null) { loadedAudioclipDic.Remove(playArea); Debug.LogError("音频路径配置错误,类型:" + playArea); return(null); } int asCount = allPlayer.Count; AudioSource tempAs; for (int i = 0; i < asCount; i++) { tempAs = allPlayer[i]; if (!tempAs.isPlaying) { tempAs.clip = tempClip; tempAs.loop = loop; tempAs.mute = !GameManager.Instance.GetSoundOn(); tempAs.Play(); return(tempAs); } } tempAs = Root.AddComponent <AudioSource>(); allPlayer.Add(tempAs); tempAs.clip = tempClip; tempAs.loop = loop; tempAs.mute = !GameManager.Instance.GetSoundOn(); tempAs.Play(); return(tempAs); } else { if (audioClipPathDic.TryGetValue(playArea, out string tempClipFileName)) { tempClip = Resources.Load <AudioClip>(LoadAudioFrontPath + tempClipFileName); if (tempClip == null) { Debug.LogError("配置的音频文件路径错误,类型:" + playArea); return(null); } int asCount = allPlayer.Count; AudioSource tempAs; for (int i = 0; i < asCount; i++) { tempAs = allPlayer[i]; if (!tempAs.isPlaying) { tempAs.clip = tempClip; tempAs.loop = loop; tempAs.mute = !GameManager.Instance.GetSoundOn(); tempAs.Play(); return(tempAs); } } tempAs = Root.AddComponent <AudioSource>(); allPlayer.Add(tempAs); tempAs.clip = tempClip; tempAs.loop = loop; tempAs.mute = !GameManager.Instance.GetSoundOn(); tempAs.Play(); return(tempAs); } else { Debug.LogError("没有配置音频文件路径,类型:" + playArea); return(null); } } }