public virtual void PlaySound(AnimationEvent e) { if (e.animatorClipInfo.weight < 0.1) { return; // if is too small the weight of the animation clip do nothing } EventSound SoundEvent = m_EventSound.Find(item => item.name == e.stringParameter); if (SoundEvent != null && SoundEvent.active) { SoundEvent.VolumeWeight = e.animatorClipInfo.weight; if (anim) { _audioSource.pitch = anim.speed; //Match the AnimatorSpeed with the Sound Pitch } if (_audioSource.isPlaying) //If the Audio is already Playing play the one that has more weight { if (SoundEvent.VolumeWeight * SoundEvent.volume > _audioSource.volume) { SoundEvent.PlayAudio(_audioSource); } } else { SoundEvent.PlayAudio(_audioSource); } } }
public virtual void EnableSoundEvent(string SoundName) { EventSound SoundEvent = m_EventSound.Find(item => item.name == SoundName); if (SoundEvent != null) { SoundEvent.active = true; } }
IEnumerator C_Playforever(EventSound E_sound) { if (E_sound.interval <= 0) { yield return(null); } else { var timeInterval = new WaitForSeconds(E_sound.interval); while (true) { E_sound.PlayAudio(_audioSource); yield return(timeInterval); } } yield return(null); }