Add Start + Stop looping sounds in NamedStudioEventEmitter
This commit is contained in:
		
							parent
							
								
									2540747b86
								
							
						
					
					
						commit
						ab3345b106
					
				@ -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]
 | 
			
		||||
    public void StopSound(string objectName)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -71,28 +71,31 @@ public class NamedStudioEventEmitter : ComponentHandler {
 | 
			
		||||
    public override void Run(MyBT.NodeState nodeState) {
 | 
			
		||||
        // whan aborting
 | 
			
		||||
        if (nodeState == NodeState.Aborting) {
 | 
			
		||||
            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();
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user