public FMODClip playMusic(TMusicEnum music, float time = 0f, Action MusicEndedCallback = null, bool cancelCallbackOnInterrupt = true) { FMODClip namedClip = null; if (MusicDictionary.TryGetValue(music, out namedClip) && namedClip != null && namedClip.EventPath != null) { MainAudioSource.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); MainAudioSource = FMODUnity.RuntimeManager.CreateInstance(namedClip.EventPath); MainAudioSource.setVolume(namedClip.volume); MainAudioSource.start(); currentMusic = music; if (MusicEndedCallback != null) { if (_MusicCallcabkCorutine != null) { StopCoroutine(_MusicCallcabkCorutine); } _MusicCallcabkCorutine = MusicCallcabkCorutine(MusicEndedCallback, cancelCallbackOnInterrupt); StartCoroutine(_MusicCallcabkCorutine); } } return(namedClip); }
private FMODClip playSound(FMODClip sound, Action SoundEndedCallback = null) { if (sound != null && sound.EventPath != null) { FMODUnity.RuntimeManager.PlayOneShot(sound.EventPath); var oneShotInstance = FMODUnity.RuntimeManager.CreateInstance(sound.EventPath); float clipLength = getEventLength(oneShotInstance); if (SoundEndedCallback != null) { StartCoroutine(ClipCallcabkCorutine(clipLength, SoundEndedCallback)); } } return(sound); }
private FMODClip playSound(TSoundsEnum sound, Action SoundEndedCallback = null) { FMODClip namedClip = null; if (SoundsDictionary.TryGetValue(sound, out namedClip) && namedClip != null && namedClip.EventPath != null) { FMODUnity.RuntimeManager.PlayOneShot(namedClip.EventPath); var oneShotInstance = FMODUnity.RuntimeManager.CreateInstance(namedClip.EventPath); float clipLength = getEventLength(oneShotInstance); if (SoundEndedCallback != null) { StartCoroutine(ClipCallcabkCorutine(clipLength, SoundEndedCallback)); } } return(namedClip); }
public static FMODClip Play(FMODClip sound, Action SoundEndedCallback = null) { return(Instance.playSound(sound, SoundEndedCallback)); }
public void UpdateInspectorAndDictionaries() { //Update sounds list var soundNames = Enum.GetNames(typeof(TSoundsEnum)); if (lastEnumCount_Sounds != soundNames.Length || lastListCount_Sounds != soundNames.Length) { SoundsDictionary.Clear(); List <FMODClip> newSoundsList = new List <FMODClip>(); foreach (var soundName in soundNames) { var newFMODClip = new FMODClip(); newFMODClip.Name = soundName; if (SoundsList != null) { //check if the clip already been set before, and move it to the new list var oldFMODClip = SoundsList.FirstOrDefault(x => x.Name == soundName); if (oldFMODClip != null) { newFMODClip.EventPath = oldFMODClip.EventPath; newFMODClip.volume = oldFMODClip.volume; } } //add to dictionary TSoundsEnum value = (TSoundsEnum)Enum.Parse(typeof(TSoundsEnum), newFMODClip.Name); SoundsDictionary[value] = newFMODClip; newSoundsList.Add(newFMODClip); } SoundsList = newSoundsList.ToArray(); } //Update music list var musicNames = Enum.GetNames(typeof(TMusicEnum)); if (lastEnumCount_Music != musicNames.Length || lastListCount_Music != musicNames.Length) { MusicDictionary.Clear(); List <FMODClip> newMusicList = new List <FMODClip>(); foreach (var musicName in musicNames) { var newFMODClip = new FMODClip(); newFMODClip.Name = musicName; if (MusicList != null) { //check if the clip already been set before, and move it to the new list var oldFMODClip = MusicList.FirstOrDefault(x => x.Name == musicName); if (oldFMODClip != null) { newFMODClip.EventPath = oldFMODClip.EventPath; newFMODClip.volume = oldFMODClip.volume; } } //add to dictionary TMusicEnum value = (TMusicEnum)Enum.Parse(typeof(TMusicEnum), newFMODClip.Name); MusicDictionary[value] = newFMODClip; newMusicList.Add(newFMODClip); } MusicList = newMusicList.ToArray(); } //Set delay variables lastInspectorUpdate = DateTime.Now; }