using UnityEngine;
using System.Collections;

public class AudioManager : MonoBehaviour
{
	private static AudioManager _instance;
	public static AudioManager shared { get{ return _instance; } }
	
	AudioClip SFX_SOUND;
	
	private bool _isMuted;
	
	public bool GetIsMuted() { return _isMuted; }
	
	public enum SFX { SOUND };
	
	void Awake()
	{
		_instance = this;	
		_isMuted = false;
			
		SFX_SOUND = Resources.Load("Sounds/SOUND") as AudioClip;
	}
	
	public void playSFX(SFX sfxId)
	{
		playSFX(sfxId, false);	
	}
	
	public void playSFX(SFX sfxId, bool playAtPoint)
	{
		if(_isMuted) 
			return;
		
		audio.volume = 1.0f;
		
		switch(sfxId)
		{
		case SFX.SOUND:
			audio.pitch = Random.Range(0.8f, 1.3f);
			audio.volume = 0.7f;
			
			if(!playAtPoint)
				audio.PlayOneShot(SFX_SOUND);
			break;
		}
		
		if(playAtPoint)
			AudioSource.PlayClipAtPoint(audio.clip, Vector3.zero, audio.volume);
	}
	
	public void ToggleMute()
	{
		if(_isMuted)
		{
			_isMuted = false;	
		}
		else
		{
			audio.volume = 0.0f;
			_isMuted = true;
		}
	}
}
