FittsLaw/Assets/Oculus/AudioManager/Scripts/Audio/SoundFXRef.cs

140 lines
2.9 KiB
C#
Raw Normal View History

2018-10-14 23:33:23 -04:00
using UnityEngine;
using System.Collections;
/*
-----------------------
SoundFXRef
just a references to a SoundFX.. all the SoundFX methods are called indirectly from here
-----------------------
*/
[System.Serializable]
public class SoundFXRef {
public string soundFXName = string.Empty;
private bool initialized = false;
private SoundFX soundFXCached = null;
public SoundFX soundFX {
get {
if ( !initialized ) {
Init();
}
return soundFXCached;
}
}
public string name { get { return soundFXName; } set { soundFXName = value; Init(); } }
/*
-----------------------
Init()
-----------------------
*/
void Init() {
// look up the actual SoundFX object
soundFXCached = AudioManager.FindSoundFX( soundFXName );
if ( soundFXCached == null ) {
soundFXCached = AudioManager.FindSoundFX( string.Empty );
}
initialized = true;
}
/*
-----------------------
Length()
-----------------------
*/
public int Length { get { return soundFX.Length; } }
/*
-----------------------
IsValid()
-----------------------
*/
public bool IsValid { get { return soundFX.IsValid; } }
/*
-----------------------
GetClip()
-----------------------
*/
public AudioClip GetClip() {
return soundFX.GetClip();
}
/*
-----------------------
GetClipLength()
-----------------------
*/
public float GetClipLength( int idx ) {
return soundFX.GetClipLength( idx );
}
/*
-----------------------
PlaySound()
-----------------------
*/
public int PlaySound( float delaySecs = 0.0f ) {
return soundFX.PlaySound( delaySecs );
}
/*
-----------------------
PlaySoundAt()
-----------------------
*/
public int PlaySoundAt( Vector3 pos, float delaySecs = 0.0f, float volume = 1.0f, float pitchMultiplier = 1.0f ) {
return soundFX.PlaySoundAt( pos, delaySecs, volume, pitchMultiplier );
}
/*
-----------------------
SetOnFinished()
get a callback when the sound is finished playing
-----------------------
*/
public void SetOnFinished( System.Action onFinished ) {
soundFX.SetOnFinished( onFinished );
}
/*
-----------------------
SetOnFinished()
get a callback with an object parameter when the sound is finished playing
-----------------------
*/
public void SetOnFinished( System.Action<object> onFinished, object obj ) {
soundFX.SetOnFinished( onFinished, obj );
}
/*
-----------------------
StopSound()
-----------------------
*/
public bool StopSound() {
return soundFX.StopSound();
}
/*
-----------------------
AttachToParent()
-----------------------
*/
public void AttachToParent( Transform parent)
{
soundFX.AttachToParent( parent);
}
/*
-----------------------
DetachFromParent()
-----------------------
*/
public void DetachFromParent()
{
soundFX.DetachFromParent();
}
}