From ab3345b106a805699d71d2c950d083bb110fe7ac Mon Sep 17 00:00:00 2001 From: Nadine Ganz Date: Wed, 8 Jan 2025 14:14:10 +0100 Subject: [PATCH] Add Start + Stop looping sounds in NamedStudioEventEmitter --- Viagg-io/Assets/Packages/MyBT/BTC/BTC.cs | 12 ------ .../MyBT/BTC/Handlers/ComponentHandler.cs | 8 ---- .../BTC/Handlers/NamedStudioEventEmitter.cs | 41 +++++-------------- .../Assets/Scripts/Audio/OnCollideSound.cs | 2 + Viagg-io/Assets/Scripts/Audio/OnGrabSound.cs | 2 + .../Assets/Scripts/Audio/OnSocketSnapSound.cs | 2 + .../Assets/Scripts/Audio/OnStirringSound.cs | 2 + 7 files changed, 19 insertions(+), 50 deletions(-) diff --git a/Viagg-io/Assets/Packages/MyBT/BTC/BTC.cs b/Viagg-io/Assets/Packages/MyBT/BTC/BTC.cs index 7524b1c..745f807 100644 --- a/Viagg-io/Assets/Packages/MyBT/BTC/BTC.cs +++ b/Viagg-io/Assets/Packages/MyBT/BTC/BTC.cs @@ -277,18 +277,6 @@ public class BTC : MonoBehaviour { } } - [Task] - public void StartSound(string objectName) - { - List handlers = GetHandlers(objectName); - handlers.ForEach(handler => handler.StartSound(Task.getState)); - if (handlers.Count == 0) - { - Debug.LogWarning($"BTC.StartSound: no components under the name '{objectName}'"); - Task.SetSucceeded(); - } - } - [Task] public void StopSound(string objectName) { diff --git a/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/ComponentHandler.cs b/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/ComponentHandler.cs index d11a3e0..2fb74f0 100644 --- a/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/ComponentHandler.cs +++ b/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/ComponentHandler.cs @@ -220,14 +220,6 @@ public class ComponentHandler : MonoBehaviour { } } - public virtual void StartSound(MyBT.NodeState nodeState) - { - if (Task.isDebugging) - { - Debug.LogWarning($"ComponentHandler.StartSound: not implemented for {this.GetType()}"); - } - } - public virtual void StopSound(MyBT.NodeState nodeState) { if (Task.isDebugging) diff --git a/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedStudioEventEmitter.cs b/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedStudioEventEmitter.cs index 950cd92..ed9ff3a 100644 --- a/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedStudioEventEmitter.cs +++ b/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedStudioEventEmitter.cs @@ -71,28 +71,31 @@ public class NamedStudioEventEmitter : ComponentHandler { public override void Run(MyBT.NodeState nodeState) { // whan aborting if (nodeState == NodeState.Aborting) { - studioEventEmitter.Stop(); + bool isOneShot; + studioEventEmitter.EventDescription.isOneshot(out isOneShot); + if (isOneShot) + { + studioEventEmitter.Stop(); + } + return; } // at start if (nodeState == NodeState.FirstRun) { - // reset event trigger studioEventEmitter.Play(); + UnityEngine.Debug.Log($"NamedStudioEventEmitter: Event from {gameObject.name} start playing."); } - // int val; - // FMOD.RESULT res = studioEventEmitter.EventInstance.getTimelinePosition(out val); - // during runtime if (nodeState == NodeState.Running) { bool isOneShot; studioEventEmitter.EventDescription.isOneshot(out isOneShot); - /*if (!isOneShot) + if (!isOneShot) { Task.SetSucceeded(); return; - }*/ + } if (!studioEventEmitter.IsPlaying()) { Task.SetSucceeded(); @@ -101,31 +104,9 @@ public class NamedStudioEventEmitter : ComponentHandler { } } - public override void StartSound(MyBT.NodeState nodeState) - { - if (nodeState == NodeState.Aborting) - { - studioEventEmitter.Stop(); - return; - } - - if (nodeState == NodeState.FirstRun) - { - studioEventEmitter.Play(); - UnityEngine.Debug.Log($"NamedStudioEventEmitter: Event from {gameObject.name} start playing."); - Task.SetSucceeded(); - return; - } - } - + // For Looping Sounds public override void StopSound(MyBT.NodeState nodeState) { - if (nodeState == NodeState.Aborting) - { - studioEventEmitter.Stop(); - return; - } - if (nodeState == NodeState.FirstRun) { studioEventEmitter.Stop(); diff --git a/Viagg-io/Assets/Scripts/Audio/OnCollideSound.cs b/Viagg-io/Assets/Scripts/Audio/OnCollideSound.cs index fb95341..e835038 100644 --- a/Viagg-io/Assets/Scripts/Audio/OnCollideSound.cs +++ b/Viagg-io/Assets/Scripts/Audio/OnCollideSound.cs @@ -9,6 +9,7 @@ using FMODUnity; [RequireComponent(typeof(Rigidbody))] public class OnCollideSound : MonoBehaviour { +#if FMOD_AVAILABLE [SerializeField] EventReference soundRef; @@ -53,4 +54,5 @@ public class OnCollideSound : MonoBehaviour _specialCase = false; } } +#endif } diff --git a/Viagg-io/Assets/Scripts/Audio/OnGrabSound.cs b/Viagg-io/Assets/Scripts/Audio/OnGrabSound.cs index 0ef0f3d..91a79f3 100644 --- a/Viagg-io/Assets/Scripts/Audio/OnGrabSound.cs +++ b/Viagg-io/Assets/Scripts/Audio/OnGrabSound.cs @@ -10,6 +10,7 @@ using FMODUnity; [RequireComponent(typeof(XRGrabInteractable))] public class OnGrabSound : MonoBehaviour { +#if FMOD_AVAILABLE [SerializeField] EventReference soundRef; @@ -26,4 +27,5 @@ public class OnGrabSound : MonoBehaviour { RuntimeManager.PlayOneShot(soundRef, transform.position); } +#endif } diff --git a/Viagg-io/Assets/Scripts/Audio/OnSocketSnapSound.cs b/Viagg-io/Assets/Scripts/Audio/OnSocketSnapSound.cs index 7affce3..b39ef2f 100644 --- a/Viagg-io/Assets/Scripts/Audio/OnSocketSnapSound.cs +++ b/Viagg-io/Assets/Scripts/Audio/OnSocketSnapSound.cs @@ -9,6 +9,7 @@ using FMODUnity; public class OnSocketSnapSound : MonoBehaviour { +#if FMOD_AVAILABLE [SerializeField] EventReference soundRef; @@ -25,4 +26,5 @@ public class OnSocketSnapSound : MonoBehaviour { RuntimeManager.PlayOneShot(soundRef, transform.position); } +#endif } diff --git a/Viagg-io/Assets/Scripts/Audio/OnStirringSound.cs b/Viagg-io/Assets/Scripts/Audio/OnStirringSound.cs index dbe53bd..7c8697e 100644 --- a/Viagg-io/Assets/Scripts/Audio/OnStirringSound.cs +++ b/Viagg-io/Assets/Scripts/Audio/OnStirringSound.cs @@ -8,6 +8,7 @@ using FMODUnity; public class OnStirringSound : MonoBehaviour { +#if FMOD_AVAILABLE [SerializeField] EventReference stirringDrySoundRef; @@ -19,4 +20,5 @@ public class OnStirringSound : MonoBehaviour emitter.Stop(); emitter.ChangeEvent(stirringDrySoundRef); } +#endif }