SoundFXRef.cs 2.8 KB

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