public override ArdenAudioInstance Play(AudioSourceSettings settings, float volume, MixerGroup group = MixerGroup.sfx, bool looped = false)
        {
            PooledAudioSource source = SoundManager.PlayPooledClip(audioClip, group, volume * this.volume, GetPitch(), looped, settings);

            ArdenAudioClipInstance instance = new ArdenAudioClipInstance(this, settings);

            instance.Init(source);

            return(instance);
        }
Пример #2
0
        //A single function to unify play and play at point, under the hood
        protected ArdenAudioInstance Play_Internal(AudioSourceSettings settings, float volume, MixerGroup group, bool looped, bool playAtPoint, Vector3 location)
        {
            if (layers == null)
            {
                return(null);
            }

            if (layers.Count == 0)
            {
                return(null);
            }

            ArdenAudioMixerInstance instance = new ArdenAudioMixerInstance(this, settings);

            instance.Init(volume, group, playAtPoint, location);

            return(instance);
        }
        public override ArdenAudioInstance Play(AudioSourceSettings settings, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
        {
            int r = Random.Range(0, audioClips.Count);

            return(audioClips[r].Play(settings, volume, group, looped));
        }
 public ArdenAudioInstance(ArdenAudioAsset asset, AudioSourceSettings sourceSettings)
 {
     this.asset          = asset;
     this.sourceSettings = sourceSettings;
 }
 public virtual ArdenAudioInstance Play(AudioSourceSettings settings, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(null);
 }
Пример #6
0
 public ArdenAudioMixerInstance(ArdenAudioAsset asset, AudioSourceSettings settings) : base(asset, settings)
 {
 }
Пример #7
0
 public override ArdenAudioInstance PlayAtPoint(AudioSourceSettings settings, Vector3 location, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(Play_Internal(settings, volume, group, looped, true, location));
 }
Пример #8
0
 public override ArdenAudioInstance Play(AudioSourceSettings settings, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(Play_Internal(settings, volume, group, looped, false, new Vector3()));
 }
Пример #9
0
        //Play a sound at a position
        public static PooledAudioSource PlayPooledClip(AudioClip clip, Vector3?position, MixerGroup group = MixerGroup.sfx, float volume = 1, float pitch = 1, bool loop = false, AudioSourceSettings settings = null)
        {
            if (Instance.audioPool == null)
            {
                Instance.audioPool = new List <AudioSource>();
            }

            if (Instance.audioPoolObject == null)
            {
                Instance.audioPoolObject = new GameObject("__Audio Pool (Singleton)");
                GameObject.DontDestroyOnLoad(Instance.audioPoolObject);
            }

            if (clip == null)
            {
                return(null);
            }

            if (settings == null)
            {
                settings = new AudioSourceSettings();
            }

            AudioSource audioSource = null;

            if (position == null)
            {
                audioSource = Instance.GetAudioSource();
            }
            else
            {
                audioSource = Instance.GetAudioSource((Vector3)position);
            }

            audioSource.outputAudioMixerGroup = GetMixerGroup(group);

            audioSource.clip   = clip;
            audioSource.volume = volume;
            audioSource.loop   = loop;
            audioSource.name   = clip.name;
            audioSource.time   = 0;

            if (pitch > 0)
            {
                audioSource.pitch = pitch;
            }
            else
            {
                audioSource.pitch = 0.01f;
            }

            audioSource.Play();

            audioSource.rolloffMode = settings.rolloffMode;
            audioSource.maxDistance = settings.maxDistance;
            audioSource.minDistance = settings.minDistance;

            PooledAudioSource audioSourceData = new PooledAudioSource();

            audioSourceData.audioSource = audioSource;
            audioSourceData.complete    = false;

            //By default, anything not music, ambient, or UI will be affected by time
            if (group != MixerGroup.ambient && group != MixerGroup.music && group != MixerGroup.ui)
            {
                audioSourceData.gameTimebased = true;
            }

            if (loop == false)
            {
                IEnumerator WaitTillAudioComplete()
                {
                    yield return(new WaitWhile(() =>
                    {
                        if (audioSource == null)
                        {
                            return false;
                        }
                        return audioSource.isPlaying;
                    }));

                    if (audioSourceData.onComplete != null)
                    {
                        audioSourceData.onComplete();
                    }
                    Instance.OnAudioSourceDone(audioSourceData);
                }

                audioSourceData.coroutine = CoroutineManager.RunExternalCoroutine(WaitTillAudioComplete());
            }

            Instance.playingAudio.Add(audioSourceData);

            return(audioSourceData);
        }
Пример #10
0
 public static PooledAudioSource PlayPooledClip(AudioClip clip, MixerGroup group = MixerGroup.ui, float volume = 1, float pitch = 1, bool loop = false, AudioSourceSettings settings = null)
 {
     return(PlayPooledClip(clip, null, group, volume, pitch, loop, settings));
 }
Пример #11
0
        public static PooledAudioSource PlayAudioAtPoint(ArdenAudioClip clip, Vector3 position, MixerGroup group = MixerGroup.ui, float volume = 1, AudioSourceSettings settings = null, bool looped = false)
        {
            if (clip == null)
            {
                return(null);
            }

            return(PlayPooledClip(clip.audioClip, position, group, clip.volume * volume, clip.GetPitch(), looped, settings));
        }
Пример #12
0
        //Play a random sound at a position selected from a list
        public static PooledAudioSource PlayAudioAtPoint(List <ArdenAudioClip> clips, Vector3 position, MixerGroup group = MixerGroup.sfx, float volume = 1, bool looped = false, AudioSourceSettings settings = null)
        {
            if (clips == null)
            {
                return(null);
            }

            if (clips.Count == 0)
            {
                return(null);
            }

            if (clips.Count == 1)
            {
                PlayPooledClip(clips[0].audioClip, position, group, clips[0].volume * volume, clips[0].GetPitch(), looped, settings);
            }

            int r = UnityEngine.Random.Range(0, clips.Count);

            return(PlayPooledClip(clips[r].audioClip, position, group, clips[r].volume * volume, clips[r].GetPitch(), looped, settings));
        }
Пример #13
0
        public static PooledAudioSource PlayAudioAtTransform(ArdenAudioClip clip, Transform transform, MixerGroup group = MixerGroup.ui, float volume = 1, AudioSourceSettings settings = null, bool looped = false)
        {
            if (clip == null)
            {
                return(null);
            }

            PooledAudioSource source = PlayPooledClip(clip.audioClip, transform.position, group, clip.volume * volume, clip.GetPitch(), looped, settings);

            if (source != null)
            {
                source.attached = transform;
                source.Update();
            }

            return(source);
        }
Пример #14
0
        //Play a random sound at a position selected from a list
        public static PooledAudioSource PlayAudioAtTransform(List <ArdenAudioClip> clips, Transform transform, MixerGroup group = MixerGroup.sfx, float volume = 1, bool looped = false, AudioSourceSettings settings = null)
        {
            if (clips == null)
            {
                return(null);
            }

            if (clips.Count == 0)
            {
                return(null);
            }

            PooledAudioSource source = null;

            if (clips.Count == 1)
            {
                source = PlayPooledClip(clips[0].audioClip, transform.position, group, clips[0].volume * volume, clips[0].GetPitch(), looped, settings);
            }
            else
            {
                int r = UnityEngine.Random.Range(0, clips.Count);
                source = PlayPooledClip(clips[r].audioClip, transform.position, group, clips[r].volume * volume, clips[r].GetPitch(), looped, settings);
            }

            if (source != null)
            {
                source.attached = transform;
                source.Update();
            }


            return(source);
        }