音效管理器

using UnityEngine;
using System.Collections;
/// <summary>
/// 音效管理器
/// </summary>
public class SoundManager : MonoBehaviour {
	
	public static AudioSource SoundEffAudio;//播放器
	public static bool isInitSounds;//是否初始化
	
	#region 系统
	public static AudioClip Item;
	public static AudioClip BuySell;
	#endregion
	
	#region 战斗
	public static AudioClip AttackEff;
	public static AudioClip Wound;
	public static AudioClip Thrown;
	public static AudioClip Bomb;
	#endregion
	
	#region 技能
	public static AudioClip accel;
	public static AudioClip blackhole;
	public static AudioClip blessed;
	public static AudioClip dash;
	public static AudioClip fireball;
	public static AudioClip firebomb;
	public static AudioClip healing;
	public static AudioClip nightmare;
	public static AudioClip speed;
	public static AudioClip thrown;
	public static AudioClip qiu;
	public static AudioClip wind;
	#endregion
	
	void Start() {
		//添加播放器
		if(SoundEffAudio == null)
			SoundEffAudio = transform.Find("SoundEff").gameObject.AddComponent<AudioSource>();
		
		if(!isInitSounds){
			//系统
			Item = Resources.Load("Sound/SoundEffects/system/item") as AudioClip;
			BuySell = Resources.Load("Sound/SoundEffects/system/buysell") as AudioClip;
			
			//战斗
			AttackEff = Resources.Load("Sound/SoundEffects/other/attack") as AudioClip;
			Wound = Resources.Load("Sound/SoundEffects/other/wound") as AudioClip;
			Thrown = Resources.Load("Sound/SoundEffects/other/thrown") as AudioClip;
			Bomb = Resources.Load("Sound/SoundEffects/other/bomb") as AudioClip;
			
			//技能
			accel = Resources.Load("Sound/SoundEffects/skill/accel") as AudioClip;
			blackhole = Resources.Load("Sound/SoundEffects/skill/blackhole") as AudioClip;
			blessed = Resources.Load("Sound/SoundEffects/skill/blessed") as AudioClip;
			dash = Resources.Load("Sound/SoundEffects/skill/dash") as AudioClip;
			fireball = Resources.Load("Sound/SoundEffects/skill/fireball") as AudioClip;
			firebomb = Resources.Load("Sound/SoundEffects/skill/firebomb") as AudioClip;
			healing = Resources.Load("Sound/SoundEffects/skill/healing") as AudioClip;
			nightmare = Resources.Load("Sound/SoundEffects/skill/nightmare") as AudioClip;
			speed = Resources.Load("Sound/SoundEffects/skill/speed") as AudioClip;
			thrown = Resources.Load("Sound/SoundEffects/skill/thrown") as AudioClip;
			qiu = Resources.Load("Sound/SoundEffects/skill/qiu") as AudioClip;
			wind = Resources.Load("Sound/SoundEffects/skill/wind") as AudioClip;
			
			Debug.Log("SoundManager.Start 初始化音效资源");
			isInitSounds = true;
		}
	}
	
	/// <summary>
	/// 播放音效(音效)
	/// </summary>
	public static void PlaySoundEff(AudioSource audio, AudioClip clip){
		audio.volume = UISetting.SoundEffectsVolume;
		audio.PlayOneShot(clip);
	}
	
	/// <summary>
	/// 播放音效(音效名称)
	/// </summary>
	public static void PlaySoundEff(AudioSource audio, string name){
		AudioClip clip = null;
		switch(name){
			case "accel": clip = accel; break;
			case "blackhole": clip = blackhole; break;
			case "blessed": clip = blessed; break;
			case "dash": clip = dash; break;
			case "fireball": clip = fireball; break;
			case "firebomb": clip = firebomb; break;
			case "healing": clip = healing; break;
			case "nightmare": clip = nightmare; break;
			case "speed": clip = speed; break;
			case "thrown": clip = thrown; break;
			case "qiu": clip = qiu; break;
			case "wind": clip = wind; break;
		}
		PlaySoundEff(audio,clip);
	}
	
	/// <summary>
	/// 播放音效(内置播放器)
	/// </summary>
	public static void PlaySoundEff(AudioClip clip){
		SoundEffAudio.volume = UISetting.SoundEffectsVolume;
		SoundEffAudio.PlayOneShot(clip);
	}
}

  

posted @ 2014-02-12 21:38  小薇林  阅读(306)  评论(0编辑  收藏  举报