private IEnumerator PlayOneShotSoundAtCoroutine(SoundNames name, AudioSource audioSource, float delay) { if (delay > 0) { yield return(new WaitForSeconds(delay)); } CorrectedSoundClip clip = null; float minPitch = 0; float maxPitch = 0; for (int i = 0; i < sounds.Length; i++) { Sound sound = sounds[i]; if (sounds[i].name == name) { clip = sound.audioClips[UnityEngine.Random.Range(0, sound.audioClips.Length)]; minPitch = sound.minPitch; maxPitch = sound.maxPitch; } } if (clip == null) { Debug.LogError("NO SOUND FOUND!"); } else { audioSource.clip = clip.clip; audioSource.pitch = UnityEngine.Random.Range(minPitch, maxPitch); audioSource.volume = clip.volume; audioSource.Play(); } }
/// <summary> /// Stops the sound /// </summary> /// <param name="soundName">Name of the sound that needs to be stopped</param> public void StopSound(SoundNames soundName) { SoundData soundData = m_AudioData.Find(x => x.SoundID == soundName); if (soundData.AudioSource != null) { soundData.AudioSource.Stop(); } }
// SOUNDS public void PlaySound(SoundNames soundID) { SoundSO sound = Sounds.Find(s => s.SoundID == soundID); if (sound != null) { StartCoroutine(PlayingSound(sound)); } }
public void PlaySFX(SoundNames soundName) { for (int i = 0; i < sounds.Length; i++) { if (sounds[i].name == soundName) { audioSource.PlayOneShot(sounds[i].audioClip); } } }
/// <summary> /// Plays a sound by name /// </summary> /// <param name="soundName">Name of the sound to play</param> /// <param name="loop">Loop the sound?</param> public void PlaySound(SoundNames soundName, bool loop = false) { SoundData soundData = m_AudioData.Find(x => x.SoundID == soundName); if (soundData.AudioSource != null) { soundData.AudioSource.loop = loop; soundData.AudioSource.Play(); } }
public sound_cache_file_gestalt(CacheBase Cache, int Address) { EndianReader Reader = Cache.Reader; Reader.SeekTo(Address); #region Codec Chunk int iCount = Reader.ReadInt32(); int iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { Codecs.Add(new Codec(Cache, iOffset + 3 * i)); } #endregion #region SoundName Chunk Reader.SeekTo(Address + 36); iCount = Reader.ReadInt32(); iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { SoundNames.Add(new SoundName(Cache, iOffset + 4 * i)); } #endregion #region Playback Chunk Reader.SeekTo(Address + 72); iCount = Reader.ReadInt32(); iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { PlayBacks.Add(new Playback(Cache, iOffset + 12 * i)); } #endregion #region SoundPermutation Chunk Reader.SeekTo(Address + 84); iCount = Reader.ReadInt32(); iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { SoundPermutations.Add(new SoundPermutation(Cache, iOffset + 16 * i)); } #endregion #region Raw Chunks Reader.SeekTo(Address + 160); iCount = Reader.ReadInt32(); iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { RawChunks.Add(new RawChunk(Cache, iOffset + 20 * i)); } #endregion }
public void Play(SoundNames soundName) { var s = Array.Find(sounds, sound => sound.SoundName == soundName); if (s == null) { Debug.LogWarning("Sound " + name + " not found!"); return; } s.Source.Play(); }
public void PlaySound(SoundNames soundName) { AudioClip audioClip = audioClipSilent; switch (soundName) { case SoundNames.Miss: audioClip = audioClipMiss; break; } this.GetComponent <AudioSource>().PlayOneShot(audioClip); }
/// <summary> /// Is the sound playing? /// </summary> /// <param name="soundName">Name of the sound</param> /// <returns>Whether the sound is playing or not</returns> public bool IsSoundPlaying(SoundNames soundName) { SoundData soundData = m_AudioData.Find(x => x.SoundID == soundName); if (soundData.AudioSource != null) { return(soundData.AudioSource.isPlaying); } else { return(false); } }
private static SoundAudioClip GetChosenSoundByName(SoundNames soundName) { for (int i = 0; i < Sounds.Instance.SoundsAudioClips.Length; i++) { if (Sounds.Instance.SoundsAudioClips[i].SoundName == soundName) { return(Sounds.Instance.SoundsAudioClips[i]); } } Debug.LogError("Sound " + soundName + " not found!"); return(null); }
private void DoCollisionViewStuff(bool hardCollision) { int currentFrameCount = Time.frameCount; if (currentFrameCount == frameCount) { return; } frameCount = currentFrameCount; animator.SetTrigger("Bounce"); collisionParticles.Play(); //SoundManager.PlayOneShotSoundAt(SoundNames.WallHit, audioSource); SoundNames soundName = hardCollision ? SoundNames.LowGlocken : SoundNames.AllGlocken; SoundManager.PlayOneShotSoundAt(soundName, transform.position); }
/// <summary> /// Generate default name lists, based on Descent 2's HAM file. Must be called after reading the data file. /// </summary> public void GenerateDefaultNamelists() { for (int i = 0; i < BaseFile.VClips.Count; i++) { VClips[i].Name = ElementLists.GetVClipName(i); } for (int i = 0; i < BaseFile.EClips.Count; i++) { EClips[i].Name = ElementLists.GetEClipName(i); } for (int i = 0; i < BaseFile.Robots.Count; i++) { Robots[i].Name = ElementLists.GetRobotName(i); } for (int i = 0; i < BaseFile.Weapons.Count; i++) { Weapons[i].Name = ElementLists.GetWeaponName(i); } for (int i = 0; i < BaseFile.Sounds.Length; i++) { SoundNames.Add(ElementLists.GetSoundName(i)); } if (BaseFile.Version >= 3) { for (int i = 0; i < BaseFile.Models.Count; i++) { Models[i].Name = ElementLists.GetModelName(i); } } else { for (int i = 0; i < BaseFile.Models.Count; i++) { Models[i].Name = ElementLists.GetDemoModelName(i); } } for (int i = 0; i < BaseFile.Powerups.Count; i++) { Powerups[i].Name = ElementLists.GetPowerupName(i); } for (int i = 0; i < BaseFile.Reactors.Count; i++) { Reactors[i].Name = ElementLists.GetReactorName(i); } }
private IEnumerator PlayOneShotSoundAtCoroutine(SoundNames name, Vector3 position, float delay) { if (delay > 0) { yield return(new WaitForSeconds(delay)); } CorrectedSoundClip clip = null; float minPitch = 0; float maxPitch = 0; float volumeModification = 0; for (int i = 0; i < sounds.Length; i++) { Sound sound = sounds[i]; if (sounds[i].name == name) { int clipIndex = 0; for (int j = 0; j < 8; j++) { clipIndex = UnityEngine.Random.Range(0, sound.audioClips.Length); if (!sound.audioClips[clipIndex].ignoreMe) { break; } } clip = sound.audioClips[clipIndex]; minPitch = sound.minPitch; maxPitch = sound.maxPitch; volumeModification = UnityEngine.Random.Range(0, sound.volumeModifier); } } if (clip == null) { Debug.LogError("NO SOUND FOUND: " + name.ToString()); } else { AudioSource oneShotSound = GetAvailableAudioSource(); oneShotSound.transform.position = position; oneShotSound.clip = clip.clip; oneShotSound.pitch = UnityEngine.Random.Range(minPitch, maxPitch); oneShotSound.volume = clip.volume + volumeModification; oneShotSound.Play(); } }
public void Play(SoundNames sound_name) { Sound sound_found = null; if (Array.Find(sounds_array, sound => sound.name == sound_name).clip) { sound_found = Array.Find(sounds_array, sound => sound.name == sound_name); } if (sound_found == null || sound_found.audio_source.isPlaying) { return; } if (sound_found.clip) { sound_found.audio_source.Play(); } }
public void playSound(Stream s = null, SoundNames soundName = 0) { if (InvokeRequired) { Invoke(new Action <Stream, SoundNames>(playSound), new object[] { s, soundName }); return; } switch (soundName) { case SoundNames.Waka: samplePlayer.playWaka(false); break; default: SoundPlayer player = new SoundPlayer(s); player.Play(); break; } }
public void PlaySound(SoundNames soundName) { SoundAudioClip chosenSound = GetChosenSoundByName(soundName); AudioSource source = chosenSound.AudioSource; if (soundName == SoundNames.Jump) { source.pitch = 1 + (Random.Range(-JumpPitchAlteration, JumpPitchAlteration)); } else if (soundName == SoundNames.CollectCorrect) { source.pitch = goodCollectionPitch; } else { source.pitch = 1; } source.loop = chosenSound.Loop; source.volume = chosenSound.Volume; source.clip = chosenSound.AudioClip; source.Play(); }
public static void PlayOneShotSoundAt(SoundNames name, Vector3 position, float delay = 0) { instance.StartCoroutine(instance.PlayOneShotSoundAtCoroutine(name, position, delay)); }
public static void PlayOneShotSoundAt(SoundNames name, AudioSource audioSource, float delay = 0) { instance.StartCoroutine(instance.PlayOneShotSoundAtCoroutine(name, audioSource, delay)); }
public void StopSound(SoundNames soundName) { SoundAudioClip chosenSound = GetChosenSoundByName(soundName); chosenSound.AudioSource.Stop(); }