Example #1
0
        public void PutInPool(PYAudioSource data)
        {
            if (_poolAudioSource.Contains(data))
            {
                return;
            }

            StartCoroutine(PutInPoolRoutine(data));
        }
Example #2
0
        public void Stop(PYAudioTags audio, float fadeDuration)
        {
            PYAudioSource source = GetPYAudioSource(audio);

            if (source == null)
            {
                return;
            }

            source.Stop(fadeDuration);
        }
Example #3
0
        public void Resume(PYAudioTags audio)
        {
            PYAudioSource audioSource = GetPYAudioSource(audio);

            if (audioSource == null)
            {
                return;
            }

            audioSource.Resume();
        }
Example #4
0
        public void Stop(PYAudioTags audio)
        {
            PYAudioSource audioSource = GetPYAudioSource(audio);

            if (audioSource == null)
            {
                return;
            }

            audioSource.Stop();
        }
Example #5
0
        private PYAudioSource StartBundleAudioClip(AudioClip audioClip, PYAudioTags audioTag, PYGroupTag group)
        {
            PYAudioSource audioSource = GetPYAudioSource(audioTag);

            if (audioSource != null && audioSource.Track.GroupTag == PYGroupTag.Voice)
            {
                return(audioSource);
            }

            return(StartAudio(audioTag, new AudioTrack(group, audioClip)));
        }
Example #6
0
        /// <summary>
        /// Use this to play audios from a specific bundleManager
        /// </summary>
        /// <param name="bundleManager">From which bundleManager the audio will be fetch</param>
        /// <param name="audioTag">Use PYAudioTags that start with a B_</param>
        /// <param name="group">In which group/channel this audio will be played</param>
        /// <returns></returns>
        public PYAudioSource StartAudio(PYBundleSubManager bundleManager, PYAudioTags audioTag, PYGroupTag group)
        {
            PYAudioSource audioSource = GetPYAudioSource(audioTag);

            if (audioSource != null && audioSource.Track.GroupTag == PYGroupTag.Voice)
            {
                return(audioSource);
            }

            return(StartAudio(audioTag, new AudioTrack(group, bundleManager.GetAsset <AudioClip>(audioTag.ToString().Replace("B_", "")))));
        }
Example #7
0
        private System.Collections.IEnumerator PutInPoolRoutine(PYAudioSource data)
        {
            yield return(new WaitForEndOfFrame());

            if (data.IsPlaying || data.IsPaused)
            {
                data.Stop();
            }

            data.name = "* " + data.name;
            _executingAudioSources.Remove(data);
            _poolAudioSource.Enqueue(data);
        }
Example #8
0
        /// <summary>
        /// Use this when you need to play a AudioClip inside a group/channel
        /// </summary>
        /// <param name="audioClip">AudioClip to be played</param>
        /// <param name="group">In which group/channel this audio will be played</param>
        /// <returns></returns>
        public PYAudioSource StartAudio(AudioClip audioClip, PYGroupTag group)
        {
            PYAudioTags audioTag = (PYAudioTags)ConvertNameToTag(audioClip.name);

            PYAudioSource audioSource = GetPYAudioSource(audioTag);

            if (audioSource != null && audioSource.Track.GroupTag == PYGroupTag.Voice)
            {
                return(audioSource);
            }

            return(StartAudio(audioTag, new AudioTrack(group, audioClip)));
        }
Example #9
0
        /// <summary>
        /// Use this to play Resource audios
        /// </summary>
        /// <param name="audioTag">Use PYAudioTags that dont start with a B_</param>
        /// <returns></returns>
        public PYAudioSource StartAudio(PYAudioTags audioTag)
        {
            PYAudioSource audioSource = GetPYAudioSource(audioTag);

            if (audioSource != null && audioSource.Track.GroupTag == PYGroupTag.Voice)
            {
                return(audioSource);
            }

            AudioTrack track = (audioTag == PYAudioTags.None) ?
                               new AudioTrack(audioTag.ToString(), PYGroupTag.Master, string.Empty) : GetAudioTrack(audioTag);

            return(StartAudio(audioTag, track));
        }
Example #10
0
        public void Play(string name, Action <PYAudioSource.PYAudioSourceEventData> callback)
        {
            PYPlayer      player = StartAudio(name);
            PYAudioSource source = player.PYSource;

            if (source == null)
            {
                return;
            }

            source.Volume(player.Volume)
            .Pitch(player.Pitch)
            .Delay(player.Delay)
            .Loop(player.Loop).Play(callback);
        }
Example #11
0
        public void Play(string name)
        {
            PYPlayer      player = StartAudio(name);
            PYAudioSource source = player.PYSource;

            if (source == null)
            {
                return;
            }

            source.Volume(player.Volume)
            .Pitch(player.Pitch)
            .Delay(player.Delay)
            .Loop(player.Loop).Play();
        }
Example #12
0
        public PYAudioSource.EventListenerData AddListenerPYAudio(PYAudioTags audioTag, PYAudioSource.EventsType type, Action <PYAudioSource.PYAudioSourceEventData> action)
        {
            if (!_audioSourceActions.ContainsKey(audioTag))
            {
                _audioSourceActions.Add(audioTag, new List <PYAudioSource.EventListenerData>());
            }
            _audioSourceActions[audioTag].Add(new PYAudioSource.EventListenerData()
            {
                Type = type, Action = action
            });

            // Caso o audio já esteja rodando adicionamos a ação nele
            PYAudioSource audioSource = GetPYAudioSource(audioTag);

            if (audioSource)
            {
                audioSource.AddListinerToEvent(type, action);
            }

            return(_audioSourceActions[audioTag][_audioSourceActions[audioTag].Count - 1]);
        }
Example #13
0
        public PYAudioTrigger.Trigger AddTriggerAction(PYAudioTags audioTag, float time, Action action)
        {
            if (!_audioTriggers.ContainsKey(audioTag))
            {
                _audioTriggers.Add(audioTag, new List <PYAudioTrigger.Trigger>());
            }
            _audioTriggers[audioTag].Add(new PYAudioTrigger.Trigger()
            {
                Time = time, Action = action
            });

            // Caso o audio já esteja rodando adicionamos o trigger nele
            PYAudioSource audioSource = GetPYAudioSource(audioTag);

            if (audioSource)
            {
                audioSource.AudioTrigger.AddTriggerAction(time, action);
            }

            return(_audioTriggers[audioTag][_audioTriggers[audioTag].Count - 1]);
        }
Example #14
0
        private PYAudioSource CreatePYAudioSource(string name)
        {
            PYAudioSource source = null;

            if (_poolAudioSource.Count > 0)
            {
                source = _poolAudioSource.Dequeue();
            }

            // Verifica pare ter certeza de que o aúdio removido do pool
            // realmente está parado, antes de reusá-lo, caso ele
            // ainda esteja sendo utilizado criamos um novo PYAudioSource
            if (source == null || source.IsPlaying || source.IsPaused)
            {
                GameObject clone = new GameObject();
                clone.transform.parent        = transform;
                clone.transform.localPosition = Vector3.zero;
                source = clone.AddComponent <PYAudioSource>();
            }

            source.name = string.Format("PYAudio ({0})", name);
            return(source);
        }
Example #15
0
        // Base method for others implementations
        private PYAudioSource StartAudio(PYAudioTags audioTag, AudioTrack track)
        {
            PYAudioSource audioSource = CreatePYAudioSource(audioTag.ToString());

            audioSource.Initialize(audioTag, track);

            if (_audioTriggers.ContainsKey(audioSource.AudioTag))
            {
                foreach (PYAudioTrigger.Trigger trigger in _audioTriggers[audioSource.AudioTag])
                {
                    audioSource.AudioTrigger.AddTriggerAction(trigger);
                }
            }

            if (_audioSourceActions.ContainsKey(audioSource.AudioTag))
            {
                foreach (PYAudioSource.EventListenerData listener in _audioSourceActions[audioSource.AudioTag])
                {
                    audioSource.AddListenerToEvent(listener);
                }
            }

            return(audioSource);
        }
Example #16
0
 public void AddInExecutingList(PYAudioSource data)
 {
     _executingAudioSources.Add(data);
 }