#region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; #endregion namespace Precision { class AudioManager { private AudioEngine engine; private WaveBank waveBank; private SoundBank soundBank; private Cue cue = null; private AudioCategory category; private List cueList = new List(); private List catList = new List(); public AudioManager(AudioEngine engine, WaveBank waveBank, SoundBank soundBank) { this.engine = engine; this.waveBank = waveBank; this.soundBank = soundBank; } public void playSound(string name) { cue = soundBank.GetCue(name); cue.Play(); cueList.Add(cue); cue = null; } public void pauseSound(string name) { cue = soundBank.GetCue(name); if (!cue.IsPaused) cue.Pause(); cue = null; } public void resumeSound(string name) { cue = soundBank.GetCue(name); if(cue.IsPaused) cue.Resume(); cue = null; } public void stopAllSound() { for (int i = cueList.Count - 1; i >= 0; i--) { cueList[i].Stop(AudioStopOptions.AsAuthored); cueList.RemoveAt(i); } } public void stopOneSound(string name) { cue = soundBank.GetCue(name); if (!cue.IsStopped || !cue.IsStopping) { cue.Stop(AudioStopOptions.AsAuthored); for (int i = cueList.Count - 1; i >= 0; i--) { if (cue.Name.ToString() == name) { cueList.RemoveAt(i); return; } } } cue = null; } public void setPitch(string cue, float pitch) { this.cue = soundBank.GetCue(cue); this.cue.SetVariable("Pitch", pitch); this.cue = null; } public void setVolume(string category, float volume) { this.category = engine.GetCategory(category); this.category.SetVolume(volume); if (!catList.Contains(this.category)) catList.Add(this.category); } public void setAllUsedVolume(float volume) { foreach (AudioCategory cat in catList) { cat.SetVolume(volume); } } public void Update() { engine.Update(); } } }