| 1 | using UnityEngine; |
| 2 | using System.Collections; |
| 3 | |
| 4 | namespace OVR |
| 5 | { |
| 6 | |
| 7 | /* |
| 8 | ----------------------- |
| 9 | SoundFXRef |
| 10 | just a references to a SoundFX.. all the SoundFX methods are called indirectly from here |
| 11 | ----------------------- |
| 12 | */ |
| 13 | [System.Serializable] |
| 14 | public class SoundFXRef { |
| 15 | |
| 16 | public string soundFXName = string.Empty; |
| 17 | |
| 18 | private bool initialized = false; |
| 19 | private SoundFX soundFXCached = null; |
| 20 | public SoundFX soundFX { |
| 21 | get { |
| 22 | if ( !initialized ) { |
| 23 | Init(); |
| 24 | } |
| 25 | return soundFXCached; |
| 26 | } |
| 27 | } |
| 28 | public string name { get { return soundFXName; } set { soundFXName = value; Init(); } } |
| 29 | |
| 30 | /* |
| 31 | ----------------------- |
| 32 | Init() |
| 33 | ----------------------- |
| 34 | */ |
| 35 | void Init() { |
| 36 | // look up the actual SoundFX object |
| 37 | soundFXCached = AudioManager.FindSoundFX( soundFXName ); |
| 38 | if ( soundFXCached == null ) { |
| 39 | soundFXCached = AudioManager.FindSoundFX( string.Empty ); |
| 40 | } |
| 41 | initialized = true; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | ----------------------- |
| 46 | Length() |
| 47 | ----------------------- |
| 48 | */ |
| 49 | public int Length { get { return soundFX.Length; } } |
| 50 | |
| 51 | /* |
| 52 | ----------------------- |
| 53 | IsValid() |
| 54 | ----------------------- |
| 55 | */ |
| 56 | public bool IsValid { get { return soundFX.IsValid; } } |
| 57 | |
| 58 | /* |
| 59 | ----------------------- |
| 60 | GetClip() |
| 61 | ----------------------- |
| 62 | */ |
| 63 | public AudioClip GetClip() { |
| 64 | return soundFX.GetClip(); |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | ----------------------- |
| 69 | GetClipLength() |
| 70 | ----------------------- |
| 71 | */ |
| 72 | public float GetClipLength( int idx ) { |
| 73 | return soundFX.GetClipLength( idx ); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | ----------------------- |
| 78 | PlaySound() |
| 79 | ----------------------- |
| 80 | */ |
| 81 | public int PlaySound( float delaySecs = 0.0f ) { |
| 82 | return soundFX.PlaySound( delaySecs ); |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | ----------------------- |
| 87 | PlaySoundAt() |
| 88 | ----------------------- |
| 89 | */ |
| 90 | public int PlaySoundAt( Vector3 pos, float delaySecs = 0.0f, float volume = 1.0f, float pitchMultiplier = 1.0f ) { |
| 91 | return soundFX.PlaySoundAt( pos, delaySecs, volume, pitchMultiplier ); |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | ----------------------- |
| 96 | SetOnFinished() |
| 97 | get a callback when the sound is finished playing |
| 98 | ----------------------- |
| 99 | */ |
| 100 | public void SetOnFinished( System.Action onFinished ) { |
| 101 | soundFX.SetOnFinished( onFinished ); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | ----------------------- |
| 106 | SetOnFinished() |
| 107 | get a callback with an object parameter when the sound is finished playing |
| 108 | ----------------------- |
| 109 | */ |
| 110 | public void SetOnFinished( System.Action<object> onFinished, object obj ) { |
| 111 | soundFX.SetOnFinished( onFinished, obj ); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | ----------------------- |
| 116 | StopSound() |
| 117 | ----------------------- |
| 118 | */ |
| 119 | public bool StopSound() { |
| 120 | return soundFX.StopSound(); |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | ----------------------- |
| 125 | AttachToParent() |
| 126 | ----------------------- |
| 127 | */ |
| 128 | public void AttachToParent( Transform parent) |
| 129 | { |
| 130 | soundFX.AttachToParent( parent); |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | ----------------------- |
| 135 | DetachFromParent() |
| 136 | ----------------------- |
| 137 | */ |
| 138 | public void DetachFromParent() |
| 139 | { |
| 140 | soundFX.DetachFromParent(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | } // namespace OVR |