示例#1
0
    /// <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);
    }
示例#2
0
        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;
        }
示例#3
0
        //-----------------------------------------------------------
        /// <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
        }
示例#4
0
        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;
            }
        }
示例#5
0
        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);
                }
            }
        }
示例#6
0
 //---------------------------------------------------------
 //Remove event type entry from dictionary, including all listeners
 public void RemoveEvent(AudioEventType AudioEventType)
 {
     //Remove entry from dictionary
     Listeners.Remove(AudioEventType);
 }
示例#7
0
 public static void ListenForEvent(AudioEventType AudioEventType, OnEvent Listener)
 {
     Instance.AddListener(AudioEventType, Listener);
 }
示例#8
0
 //-----------------------------------------------------------
 /// <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);
 }
示例#9
0
 private AudioEventData(AudioEventType audioEventType)
 {
     EventType = audioEventType;
 }
示例#10
0
 public static AudioEventData Create(AudioEventType audioEventType) =>
 new AudioEventData(audioEventType);