Add Start + Stop looping sounds in NamedStudioEventEmitter

programming
Nadine Ganz 2025-01-08 14:14:10 +01:00
parent 2540747b86
commit ab3345b106
7 changed files with 19 additions and 50 deletions

View File

@ -277,18 +277,6 @@ public class BTC : MonoBehaviour {
} }
} }
[Task]
public void StartSound(string objectName)
{
List<ComponentHandler> 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] [Task]
public void StopSound(string objectName) public void StopSound(string objectName)
{ {

View File

@ -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) public virtual void StopSound(MyBT.NodeState nodeState)
{ {
if (Task.isDebugging) if (Task.isDebugging)

View File

@ -71,28 +71,31 @@ public class NamedStudioEventEmitter : ComponentHandler {
public override void Run(MyBT.NodeState nodeState) { public override void Run(MyBT.NodeState nodeState) {
// whan aborting // whan aborting
if (nodeState == NodeState.Aborting) { if (nodeState == NodeState.Aborting) {
studioEventEmitter.Stop(); bool isOneShot;
studioEventEmitter.EventDescription.isOneshot(out isOneShot);
if (isOneShot)
{
studioEventEmitter.Stop();
}
return; return;
} }
// at start // at start
if (nodeState == NodeState.FirstRun) { if (nodeState == NodeState.FirstRun) {
// reset event trigger
studioEventEmitter.Play(); studioEventEmitter.Play();
UnityEngine.Debug.Log($"NamedStudioEventEmitter: Event from {gameObject.name} start playing.");
} }
// int val;
// FMOD.RESULT res = studioEventEmitter.EventInstance.getTimelinePosition(out val);
// during runtime // during runtime
if (nodeState == NodeState.Running) { if (nodeState == NodeState.Running) {
bool isOneShot; bool isOneShot;
studioEventEmitter.EventDescription.isOneshot(out isOneShot); studioEventEmitter.EventDescription.isOneshot(out isOneShot);
/*if (!isOneShot) if (!isOneShot)
{ {
Task.SetSucceeded(); Task.SetSucceeded();
return; return;
}*/ }
if (!studioEventEmitter.IsPlaying()) { if (!studioEventEmitter.IsPlaying()) {
Task.SetSucceeded(); Task.SetSucceeded();
@ -101,31 +104,9 @@ public class NamedStudioEventEmitter : ComponentHandler {
} }
} }
public override void StartSound(MyBT.NodeState nodeState) // For Looping Sounds
{
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;
}
}
public override void StopSound(MyBT.NodeState nodeState) public override void StopSound(MyBT.NodeState nodeState)
{ {
if (nodeState == NodeState.Aborting)
{
studioEventEmitter.Stop();
return;
}
if (nodeState == NodeState.FirstRun) if (nodeState == NodeState.FirstRun)
{ {
studioEventEmitter.Stop(); studioEventEmitter.Stop();

View File

@ -9,6 +9,7 @@ using FMODUnity;
[RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(Rigidbody))]
public class OnCollideSound : MonoBehaviour public class OnCollideSound : MonoBehaviour
{ {
#if FMOD_AVAILABLE
[SerializeField] [SerializeField]
EventReference soundRef; EventReference soundRef;
@ -53,4 +54,5 @@ public class OnCollideSound : MonoBehaviour
_specialCase = false; _specialCase = false;
} }
} }
#endif
} }

View File

@ -10,6 +10,7 @@ using FMODUnity;
[RequireComponent(typeof(XRGrabInteractable))] [RequireComponent(typeof(XRGrabInteractable))]
public class OnGrabSound : MonoBehaviour public class OnGrabSound : MonoBehaviour
{ {
#if FMOD_AVAILABLE
[SerializeField] [SerializeField]
EventReference soundRef; EventReference soundRef;
@ -26,4 +27,5 @@ public class OnGrabSound : MonoBehaviour
{ {
RuntimeManager.PlayOneShot(soundRef, transform.position); RuntimeManager.PlayOneShot(soundRef, transform.position);
} }
#endif
} }

View File

@ -9,6 +9,7 @@ using FMODUnity;
public class OnSocketSnapSound : MonoBehaviour public class OnSocketSnapSound : MonoBehaviour
{ {
#if FMOD_AVAILABLE
[SerializeField] [SerializeField]
EventReference soundRef; EventReference soundRef;
@ -25,4 +26,5 @@ public class OnSocketSnapSound : MonoBehaviour
{ {
RuntimeManager.PlayOneShot(soundRef, transform.position); RuntimeManager.PlayOneShot(soundRef, transform.position);
} }
#endif
} }

View File

@ -8,6 +8,7 @@ using FMODUnity;
public class OnStirringSound : MonoBehaviour public class OnStirringSound : MonoBehaviour
{ {
#if FMOD_AVAILABLE
[SerializeField] [SerializeField]
EventReference stirringDrySoundRef; EventReference stirringDrySoundRef;
@ -19,4 +20,5 @@ public class OnStirringSound : MonoBehaviour
emitter.Stop(); emitter.Stop();
emitter.ChangeEvent(stirringDrySoundRef); emitter.ChangeEvent(stirringDrySoundRef);
} }
#endif
} }