// Determines channel and clip to play public void PlaySound(AudioChannel audioChannel, string clipName, bool isPlayAfter, string nextClip) { AudioRef myRef = ParseAudioRef(clipName); int channelIndex = (int)audioChannel; StopChannel(audioChannel); // This will be used later to save volume /*if (SaveLoad.main != null) * { * audioSources[channelIndex].volume = SaveLoad.main.gameData.masterVolume * myRef.volume; * }*/ audioSources[channelIndex].clip = myRef.clipRef; audioSources[channelIndex].loop = myRef.isLooping; audioSources[channelIndex].Play(); if (isPlayAfter == true) { StartCoroutine(WaitForSound(nextClip)); } }
private IEnumerator WaitForSound(string clipname) { AudioRef myRef = ParseAudioRef(clipname); yield return(new WaitForSeconds(myRef.clipRef.length)); PlaySound(AudioChannel.PLAYER_SOUNDS, clipname, false, null); }
/// <summary> /// Transition audio play. Should be used to play context-sensitive sounds /// (such as changing state or vocalizations) that are expected to play once /// in their entirety. /// </summary> /// <param name="refIn">The State associated with the desired clip.</param> /// <returns>false if the audio could not be found</returns> public bool PlayOneShot(AudioRef refIn) { if (l_audioDictionary.ContainsKey(refIn)) { return(false); } AudioClip activeClip; l_audioDictionary.TryGetValue(refIn, out activeClip); c_audioSource.PlayOneShot(activeClip); return(true); }
/// <summary> /// State-based audio play. Should be used for sounds that are associated with /// a given state (riding on different types of terrain, etc.) and should cleanly /// loop /// </summary> /// <param name="refIn">The State associated with the desired clip.</param> /// <returns>false if the audio could not be found</returns> public bool PlayAudio(AudioRef refIn) { if (l_audioDictionary.ContainsKey(refIn)) { c_audioSource.Stop(); return(false); } AudioClip activeClip; l_audioDictionary.TryGetValue(refIn, out activeClip); c_audioSource.clip = activeClip; c_audioSource.Play(); return(true); }
public AudioRef GetAudioState() { AudioRef foundClip = AudioRef.ERROR_CLIP; StateRef airState = c_airMachine.GetCurrentState(); StateRef rideState = c_accelMachine.GetCurrentState(); StateRef turnState = c_turnMachine.GetCurrentState(); StateRef groundState = StateRef.TERR_SNOW; // currently always snow // obey the order of the tree: air, ground, turn, terre AudioDTree currentBranch = t_audioStateTree.GetChild(airState); currentBranch = currentBranch.GetChild(rideState); currentBranch = currentBranch.GetChild(turnState); currentBranch = currentBranch.GetChild(groundState); foundClip = currentBranch.GetLeaf(); return(foundClip); }
// Returns a AudioRef to use based on the string public AudioRef ParseAudioRef(string name) { AudioRef foundRef = null; foreach (AudioRef audioRef in audioReferences) { if (audioRef.name == name) { foundRef = audioRef; break; } } // In case miss spelling of audio clip if (foundRef == null) { Debug.LogError("<b>" + name + "</b> audio effect not found!"); } return(foundRef); }
// leaf constructor public AudioDTree(StateRef stateIn, AudioRef audioIn) { this.s_heldState = stateIn; this.a_clipOut = audioIn; }
// non-leaf branch constructor public AudioDTree(StateRef stateIn) { this.s_heldState = stateIn; this.a_clipOut = AudioRef.ERROR_CLIP; this.l_children = new List <StateDTree>(); }
public Message(AudioRef dataIn) { a_data = dataIn; }
/// <summary> /// Updates the audio controller with the current state, playing the associated sounds /// </summary> private void UpdateAudio() { AudioRef audio = GetAudioState(); //c_audioController.PlayAudio(GetAudioState()); }