// public static void Play(SoundMainMixer mainMixer, string triggerName){ // if (mainMixer != null){ // if (mainMixer.categories != null){ // foreach(SoundCategory sc in mainMixer.categories){ // foreach (SoundSource ss in sc.sources){ // if (ss.triggerName == triggerName){ // ss.childGo.GetComponent<PlayAudio>().triggerType = ss.musicType; // ss.childGo.GetComponent<PlayAudio>().transition = ss.transition; // ss.childGo.GetComponent<PlayAudio>().playAudio(); // } // } // } // } // } // } public static void Play(SoundMainMixer mainMixer, string triggerName) { SoundSource ss = new SoundSource(); if ((ss = getFromTrigger(mainMixer, triggerName)) != null){ ss.childGo.GetComponent<SoundSourcePlayer>().playAudio(); } else { Debug.LogError("Couldn't play " + triggerName); } }
public static void LoadFromSceneName(string fileName, ref SoundMainMixer mainMixer) { //Debug.LogWarning("Calling: LoadFromSceneName"); #if UNITY_EDITOR if (!SoundManagerMainWindow.GetIsCompiling()) #endif { string filename = (Application.dataPath+"/" + fileName); Debug.LogWarning("loading " + filename); try { mainMixer = Deserialize(filename); // deserialize xml file } catch { mainMixer = null;//////////////////////// mainMixer = new SoundMainMixer(); return; } //Debug.Log(filename + " loaded."); foreach(SoundCategory sc in mainMixer.categories){ // for every sound category if (sc != null){ // if the sound category has been set up //Debug.Log(sc.name + " found."); foreach(SoundSource so in sc.sources){ // for every sound source in this category - not including in the groups if(so != null){ // if the source is not null //Debug.Log(so.name + " found."); so.populateClips(); // load clips via name so.populateGameObject(); } } // foreach(SoundGroup gr in sc.groups){ // for every sound group in the categories // if (gr != null){ // //Debug.Log(gr.name + " found."); // foreach(SoundSource so in sc.sources){ // for every sound source in this category - not including in the groups // if(so != null){ // if the source is not null // //Debug.Log(so.name + " found."); // so.populateClips(); // load clips via name // so.populateGameObject(); // } // } // } // } } } } }
public static SoundSource getFromTrigger(SoundMainMixer mainMixer, string triggerName) { if (mainMixer != null){ if (mainMixer.categories != null){ foreach(SoundCategory sc in mainMixer.categories){ foreach (SoundSource ss in sc.sources){ if (ss.triggerName == triggerName){ return ss; } } } } } return null; }
//foreach loop of death. use this when loading, still incomplete. public static void Load(String path, SoundMainMixer mainMixer) { //Debug.LogWarning("Calling: Load"); mainMixer = Deserialize(Application.dataPath + path); // deserialize xml file foreach(SoundCategory sc in mainMixer.categories){ // for every sound category if (sc != null){ // if the sound category has been set up Debug.Log(sc.name + " found."); foreach(SoundSource so in sc.sources){ // for every sound source in this category - not including in the groups if(so != null){ // if the source is not null Debug.Log(so.name + " found."); so.populateClips(); // load clips via name } } foreach(SoundGroup gr in sc.groups){ // for every sound group in the categories if (gr != null){ Debug.Log(gr.name + " found."); foreach(SoundSource so in gr.sources){ // for every sound source in these categories if (so != null){ Debug.Log(so.name + " found."); // source found if (so.goName != null){ //Debug.Log(so.goName); so.populateGameObject(); // game object found Debug.Log("heya"); } so.populateClips(); // populate clips // foreach(SoundTransition st in so.transitions){ // if (st != null){ // Debug.Log("transition found"); // } // } } } } } } } // }
void Awake() { //print ("the mixer behaviour has awaken!"); if(_instance == null){ _instance = this; #if UNITY_EDITOR if(Application.isEditor){ SoundManagerMainWindow.Launch(); _mainMixer = SoundManagerMainWindow.Window.mainMixer; _mainMixerGlobal = SoundManagerMainWindow.Window.mainMixerGlobal; if(_mainMixer == null) { print ("window not open"); MixerSerialize.LoadFromSceneName(_filename, ref _mainMixer); MixerSerialize.LoadFromSceneName(SoundMainMixer.mainMixerGlobalPath, ref _mainMixerGlobal); } } else #endif { MixerSerialize.LoadFromSceneName(_filename, ref _mainMixer); MixerSerialize.LoadFromSceneName(SoundMainMixer.mainMixerGlobalPath, ref _mainMixerGlobal); } #if UNITY_EDITOR SoundManagerMainWindow.CheckForRunningChange(); #endif } }
public static void Serialize(string filePath, SoundMainMixer mainMixer) { if(mainMixer == null) { Debug.Log("cannot serialize mixer because it is null"); return; } Debug.LogWarning("Calling: Serialize"); //if (!SoundManagerMainWindow.GetIsCompiling()){ string filename = (Application.dataPath+"/" + filePath); XmlSerializer serializer = new XmlSerializer(typeof(SoundMainMixer)); FileStream stream = new FileStream(filename, FileMode.Create);//, 1024, true); serializer.Serialize(stream, mainMixer); Debug.Log(filename + " saved."); stream.Close(); //} }
private void Init() { _showingGlobal = false; _initDone = false; _currentLevel = GetCurrentLevelName(); EditorApplication.update += CheckForSceneChange; PrepareScene(); //if(_mainMixer == null) { _mainMixer = new SoundMainMixer(); LoadCurrentScene(); BuildmodelForEmptyScene(_mainMixer); } //if(_mainMixerGlobal == null) { _mainMixerGlobal = new SoundMainMixer(); LoadGlobal(); BuildmodelForEmptyScene(_mainMixerGlobal); } this.title = "Sound Manager"; if(window != null) window.skin = (GUISkin)Resources.Load("SoundManagerSkin"); currentSelectedMixer = _mainMixer; RebuildGUI(); _initDone = true; executed = false; }
private void BuildmodelForEmptyScene(SoundMainMixer mixer) { if(mixer.categories.Count == 0) { mixer.categories.Add(new SoundCategory("FX")); mixer.categories[0].addSoundSource("An empty sound source"); mixer.categories.Add(new SoundCategory("Dialog")); mixer.categories.Add(new SoundCategory("Atmosphere")); mixer.categories.Add(new SoundCategory("Music")); } }
public void CheckForSceneChange() { //Debug.Log("whoot"); if(_currentLevel != null && _currentLevel != GetCurrentLevelName()) { //Debug.Log("wheee"); _initDone = false; MixerSerialize.Serialize(_currentLevel + SoundMainMixer.filePostfix, _mainMixer); MixerSerialize.Serialize(SoundMainMixer.mainMixerGlobalPath, _mainMixerGlobal); _currentLevel = GetCurrentLevelName(); _mainMixer = new SoundMainMixer(); LoadCurrentScene(); BuildmodelForEmptyScene(_mainMixer); BuildmodelForEmptyScene(_mainMixerGlobal); RebuildGUI(); _initDone = true; } }
public static void toggleMute(SoundMainMixer mainMixer, string triggerName) { SoundSource ss = new SoundSource(); if ((ss = getFromTrigger(mainMixer, triggerName)) != null) ss.audioSource.mute = !ss.audioSource.mute; }
public static void setVolume(SoundMainMixer mainMixer, string triggerName, float volume) { SoundSource ss = new SoundSource(); if ((ss = getFromTrigger(mainMixer, triggerName)) != null) ss.audioSource.volume = volume; }
public static void setPitch(SoundMainMixer mainMixer, string triggerName, float pitch) { SoundSource ss = new SoundSource(); if ((ss = getFromTrigger(mainMixer, triggerName)) != null) ss.audioSource.pitch = pitch; }
public static void setPan(SoundMainMixer mainMixer, string triggerName, float pan) { SoundSource ss = new SoundSource(); if ((ss = getFromTrigger(mainMixer, triggerName)) != null) ss.audioSource.pan = pan; }
public static void Play(SoundMainMixer mainMixer, SoundSource ss) { //ss.childGo.GetComponent<SoundSourcePlayer>().source = ss; ss.childGo.GetComponent<SoundSourcePlayer>().playAudio(); }