Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public void Add(SoundHandle handle)
 {
     dict[handle.sound.id].Add(handle);
 }
Ejemplo n.º 5
0
 public void Remove(SoundHandle handle)
 {
     dict[handle.sound.id].Remove(handle);
 }