/// <summary> /// Play corresponding sound once for given audio event type /// </summary> /// <param name="type"></param> public void PlaySoundOneShot(AudioEventType type, Vector3 position) { var sound = m_AudioEvents.FirstOrDefault(x => x.type == type); if (sound == null) { return; } PlaySoundOneShot(sound.clip, position); }
private void AssertAudioEvent(EventMessages eventMessages, AudioEventType audioEventType, int receiveCount = 1) { Assert.NotNull(eventMessages); Assert.AreEqual(1, eventMessages.Count); Assert.AreEqual(receiveCount, Object.FindObjectOfType <TestReceiver>().ReceiveCount); Assert.IsInstanceOf <AudioSource>(eventMessages[0].Sender); Assert.IsInstanceOf <AudioEventData>(eventMessages[0].EventData); Assert.NotNull(eventMessages[0].EventData); Assert.AreEqual(audioEventType, ((AudioEventData)eventMessages[0].EventData).EventType); HasAssert = true; }
//----------------------------------------------------------- /// <summary> /// Function to add specified listener-object to array of listeners /// </summary> /// <param name="AudioEventType">Event to Listen for</param> /// <param name="Listener">Object to listen for event</param> public void AddListener(AudioEventType AudioEventType, OnEvent Listener) { //List of listeners for this event List <OnEvent> ListenList = null; //New item to be added. Check for existing event type key. If one exists, add to list if (Listeners.TryGetValue(AudioEventType, out ListenList)) { //List exists, so add new item ListenList.Add(Listener); return; } //Otherwise create new list as dictionary key ListenList = new List <OnEvent>(); ListenList.Add(Listener); Listeners.Add(AudioEventType, ListenList); //Add to internal listeners list }
public void DoAudioEvent(AudioEventType audioEventType, Component Sender, object Param = null) { //print (">>>>>>>>>>>>>>>>>>>>>>>DoAudioEvent " + audioEventType); switch (audioTriggers[audioEventType]) { case AudioActionType.HardStart: if (fadingOut) { Stop(); fadingOut = false; float musicVol = Mathf.Lerp(-80f, 0f, 1); mixer.SetFloat(mixerGroupVolumeParameter, musicVol); loopIsRunning = false; } Invoker.InvokeDelayed(Play, IntroDelay); break; case AudioActionType.HardStop: Invoke("Stop", 0); break; case AudioActionType.FadeIn: Invoker.InvokeDelayed(StartFadeIn, IntroDelay); // Invoke("StartFadeIn", IntroDelay); break; case AudioActionType.FadeOut: fadingOut = true; Invoke("StartFadeOut", 0); break; default: // print("Audio Trigger ot recognized"); break; } }
public void PostNotification(AudioEventType AudioEventType, Component Sender, object Param = null) { //Notify all listeners of an event //List of listeners for this event only List <OnEvent> ListenList = null; //If no event entry exists, then exit because there are no listeners to notify if (!Listeners.TryGetValue(AudioEventType, out ListenList)) { return; } //Entry exists. Now notify appropriate listeners for (int i = 0; i < ListenList.Count; i++) { if (!ListenList[i].Equals(null)) //If object is not null, then send message via interfaces { ListenList[i](AudioEventType, Sender, Param); } } }
//--------------------------------------------------------- //Remove event type entry from dictionary, including all listeners public void RemoveEvent(AudioEventType AudioEventType) { //Remove entry from dictionary Listeners.Remove(AudioEventType); }
public static void ListenForEvent(AudioEventType AudioEventType, OnEvent Listener) { Instance.AddListener(AudioEventType, Listener); }
//----------------------------------------------------------- /// <summary> /// Function to post event to listeners /// </summary> /// <param name="AudioEventType">Event to invoke</param> /// <param name="Sender">Object invoking event</param> /// <param name="Param">Optional argument</param> /// public static void PostEvent(AudioEventType AudioEventType, Component Sender, object Param = null) { Instance.PostNotification(AudioEventType, Sender, Param); }
private AudioEventData(AudioEventType audioEventType) { EventType = audioEventType; }
public static AudioEventData Create(AudioEventType audioEventType) => new AudioEventData(audioEventType);