public void StopSound(SndT t) { AudioSource src = GetSource(t); if (src != null) { src.Stop(); } else { Debug.LogWarning(this.gameObject + " SoundManager StopSound(): src is null"); } }
public bool CheckPlaying(SndT nSndT) { AudioSource src = GetSource(nSndT); if (src != null) { return(src.isPlaying); } else { return(false); } }
/// <summary> /// Trigger a sound to play; will automatically choose correct source and return success boolean /// </summary> public bool TriggerSound(SndT t, float delay = 0.0f, bool rand = true, int index = 0) // Trigger an AudioClip to play directly { AudioClip clip; AudioSource src = GetSource(t); if (rand) { clip = GetRandomSound(t); } else { clip = GetSound(t, index); } if (clip == null) { // Debug.LogWarning( this.gameObject + " SoundManager TriggerSound(): Audio clip is null" ); return(false); } if (src == null) { Debug.LogWarning(this.gameObject + " SoundManager TriggerSound(): Audio source is null"); return(false); } if (randomizePitch) { src.pitch = Random.Range(pitchBase - SND_PITCH_VAR, pitchBase + SND_PITCH_VAR); } if (delay != 0.0f) { StartCoroutine(TriggerDelay(src, clip, delay)); return(true); } src.clip = clip; if (src.gameObject.activeInHierarchy) { src.Play(); CreateSoundEvent(owner, src, SoundIntensity.NOTEWORTHY); return(true); } // else // Debug.LogWarning(this.gameObject + " SoundManager TriggerSound(): Attempting to play a null AudioClip through a valid AudioSource, nothing will play..."); return(false); }
public AudioClip GetSound(SndT t, int index) { AudioClip snd; switch (t) { case SndT.FOOT: snd = Foot(index); break; case SndT.FALL: snd = Fall(index); break; case SndT.IDLE: snd = Idle(index); break; case SndT.ALERT: snd = Alert(index); break; case SndT.HUNT: snd = Hunt(index); break; case SndT.AGGRO: snd = Aggro(index); break; case SndT.HURT: snd = Hurt(index); break; case SndT.DIE: snd = Die(index); break; case SndT.ATK: snd = Atk(index); break; case SndT.NONE: default: snd = null; break; } return(snd); }
public AudioClip GetRandomSound(SndT t) { AudioClip snd; switch (t) { case SndT.FOOT: snd = RandFoot(); break; case SndT.FALL: snd = RandFall(); break; case SndT.IDLE: snd = RandIdle(); break; case SndT.ALERT: snd = RandAlert(); break; case SndT.HUNT: snd = RandHunt(); break; case SndT.AGGRO: snd = RandAggro(); break; case SndT.HURT: snd = RandHurt(); break; case SndT.DIE: snd = RandDie(); break; case SndT.ATK: snd = RandAtk(); break; case SndT.NONE: default: snd = null; break; } return(snd); }
public AudioSource GetSource(SndT t) { AudioSource src; switch (t) { case SndT.FOOT: case SndT.FALL: src = footSource; break; case SndT.IDLE: case SndT.ALERT: case SndT.HUNT: case SndT.AGGRO: case SndT.HURT: case SndT.DIE: src = voxSource; break; case SndT.ATK: src = atkSource; break; case SndT.NONE: Debug.LogWarning(this.gameObject + " SoundManager GetSource(): SoundTrigger (SndT) NONE passed to GetSource(), mistake?"); src = null; break; default: Debug.LogError(this.gameObject + " SoundManager GetSource(): Invalid SoundTrigger (SndT) passed to GetSource()"); src = null; break; } return(src); }
/// <summary> /// Calls this LiveEntity's SoundManager to play a sound of the specified type /// </summary> public virtual bool PlaySound(SndT type, float delay = 0.0f, bool rand = true, int index = 0) { return(SoundMgr != null?SoundMgr.TriggerSound(type, delay, rand, index) : false); }