예제 #1
0
        public static AudioSource PlayClip(ExtendedAudioClip clip, float fadeDuration, Transform parent, Vector3 localPosition)
        {
            AudioSource source = pool.GetAvailable(parent, true, localPosition, Quaternion.identity).source;

            if (source.Play(clip, fadeDuration))
            {
                return(source);
            }
            return(null);
        }
예제 #2
0
        public static AudioSource PlayClip(ExtendedAudioClip clip, float fadeDuration, Transform parent, Vector3 localPosition)
        {
            AudioSource source = pool.GetAvailable().source;

            source.transform.SetParent(parent, localPosition);
            if (source.Play(clip, fadeDuration))
            {
                return(source);
            }
            return(null);
        }
예제 #3
0
        public static AudioSource PlayClip(ExtendedAudioClip clip, float fadeDuration, Vector3 position)
        {
            AudioSource source = pool.GetAvailable().source;

            source.transform.position = position;
            if (source.Play(clip, fadeDuration))
            {
                return(source);
            }
            return(null);
        }
예제 #4
0
        public static bool Play(this AudioSource source, ExtendedAudioClip clip, float fadeIn)
        {
            AudioClip audioClip = clip.clips.GetRandom(null);

            if (audioClip == null)
            {
                Debug.LogWarning("No AudioClip Found");
                return(false);
            }

            source.pitch = (clip.pitchRange.x == clip.pitchRange.y) ? clip.pitchRange.x : UnityEngine.Random.Range(clip.pitchRange.x, clip.pitchRange.y);

            if (clip.is2D)
            {
                source.spatialBlend = 0;
            }
            else
            {
                source.spatialBlend = 1;
                source.rolloffMode  = clip.useLinearRolloff ? AudioRolloffMode.Linear : AudioRolloffMode.Logarithmic;
                source.minDistance  = clip.minMaxDistance.x;
                source.maxDistance  = clip.minMaxDistance.y;

                source.spread       = clip.spread;
                source.dopplerLevel = clip.doppler;
            }

            source.priority  = clip.priority;
            source.panStereo = clip.stereoPan;

            if (clip.oneShot)
            {
                source.loop = false;
                source.PlayOneShot(audioClip, clip.volume);
            }
            else
            {
                source.Stop(0);
                source.volume = clip.volume;
                source.loop   = clip.loop;
                source.clip   = audioClip;
                source.Play();
            }

            if (fadeIn > 0)
            {
                FadingAudioSource.FadeInSource(source, fadeIn);
            }

            return(true);
        }