예제 #1
0
        /// <summary>
        /// Generates the handle for the sound that needs to be played
        /// </summary>
        /// <param name="sound"></param>
        /// <returns></returns>
        private SoundHandle GetGlobalHandle(Sound sound)
        {
            var source = players[sound.id];

            var handle = new SoundHandle {
                audioSource = source,
                sound       = sound
            };

            return(handle);
        }
예제 #2
0
        /// <summary>
        /// Waits for a sound to end,
        /// assumes a sound
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        private IEnumerator WaitForSoundEnd(SoundHandle handle)
        {
            // Wait for the sound to play
            yield return(new WaitForSeconds(handle.sound.audioClip.length - handle.audioSource.time));

            // Remove context from currently playing sounds
            handleGroups.Remove(handle);

            // Invoke the on end callback on the sound handle
            handle.onEnd?.Invoke();
        }
예제 #3
0
        public void RegisterHandle(SoundHandle handle)
        {
            // Remove the handle for the sound after finishing playing
            var endRoutine = Systems.Instance.StartCoroutine(WaitForSoundEnd(handle));

            handle.onStop.AddListener(() => {
                handle.onEnd.Invoke();
                handleGroups.Remove(handle);
                StopCoroutine(endRoutine);
            });

            handleGroups.Add(handle);
        }
예제 #4
0
 public void Add(SoundHandle handle)
 {
     dict[handle.sound.id].Add(handle);
 }
예제 #5
0
 public void Remove(SoundHandle handle)
 {
     dict[handle.sound.id].Remove(handle);
 }