Beispiel #1
0
        protected void PlayMoveSound(float speed)
        {
            if (slidePitchFactor > 0f)
            {
                float targetPitch = Mathf.Min(1f, speed * slidePitchFactor);
                moveSound.audioSource.pitch = Mathf.Lerp(moveSound.audioSource.pitch, targetPitch, Time.deltaTime * 3f);
            }

            if (speed > slideSoundThreshold)
            {
                if (!moveSound.IsPlaying())
                {
                    moveSound.Play(moveSoundClip, true);
                }
            }
            else if (moveSound.IsPlaying() && !moveSound.IsFading())
            {
                moveSound.FadeOut(0.2f);
            }
        }
Beispiel #2
0
        protected void PlayMoveSound(float speed, float trackValue)
        {
            if (speed > slideSoundThreshold)
            {
                moveSound.relativeVolume = (speed - slideSoundThreshold);                // * 5f;
                moveSound.SetMaxVolume();
                if (slidePitchFactor > 0f)
                {
                    moveSound.GetComponent <AudioSource>().pitch = Mathf.Lerp(GetComponent <AudioSource>().pitch, Mathf.Min(1f, speed), Time.deltaTime * 5f);
                }
            }

            if (speed > slideSoundThreshold && !moveSound.IsPlaying())             // && trackValue > 0.02f && trackValue < 0.98f)
            {
                moveSound.relativeVolume = (speed - slideSoundThreshold);          // * 5f;
                moveSound.Play(moveSoundClip, true);
            }
            else if (speed <= slideSoundThreshold && moveSound.IsPlaying() && !moveSound.IsFading())
            {
                moveSound.FadeOut(0.2f);
            }
        }
Beispiel #3
0
        override public float Run()
        {
            if (runtimeSound == null)
            {
                return(0f);
            }

            if (!isRunning)
            {
                isRunning = true;

                if (ignoreIfPlaying && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                {
                    if ((audioClip != null && runtimeSound.IsPlaying(audioClip)) || (audioClip == null && runtimeSound.IsPlaying()))
                    {
                        // Sound object is already playing the desired clip
                        return(0f);
                    }
                }

                if (audioClip && runtimeSound.GetComponent <AudioSource>())
                {
                    if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)
                    {
                        runtimeSound.GetComponent <AudioSource>().clip = audioClip;
                    }
                }

                if (runtimeSound.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                {
                    Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[];
                    foreach (Sound sound in sounds)
                    {
                        sound.EndOld(SoundType.Music, runtimeSound);
                    }
                }

                if (soundAction == SoundAction.Play)
                {
                    runtimeSound.Play(loop);

                    if (!loop && willWait)
                    {
                        return(defaultPauseTime);
                    }
                }
                else if (soundAction == SoundAction.FadeIn)
                {
                    if (fadeTime <= 0f)
                    {
                        runtimeSound.Play(loop);
                    }
                    else
                    {
                        runtimeSound.FadeIn(fadeTime, loop);

                        if (!loop && willWait)
                        {
                            return(defaultPauseTime);
                        }
                    }
                }
                else if (soundAction == SoundAction.FadeOut)
                {
                    if (fadeTime <= 0f)
                    {
                        runtimeSound.Stop();
                    }
                    else
                    {
                        runtimeSound.FadeOut(fadeTime);

                        if (willWait)
                        {
                            return(fadeTime);
                        }
                    }
                }
                else if (soundAction == SoundAction.Stop)
                {
                    runtimeSound.Stop();

                    if (affectChildren)
                    {
                        foreach (Transform child in runtimeSound.transform)
                        {
                            if (child.GetComponent <Sound>())
                            {
                                child.GetComponent <Sound>().Stop();
                            }
                        }
                    }
                }
            }
            else
            {
                if (soundAction == SoundAction.FadeOut)
                {
                    isRunning = false;
                    return(0f);
                }

                if (runtimeSound.IsPlaying())
                {
                    return(defaultPauseTime);
                }
                else
                {
                    isRunning = false;
                }
            }

            return(0f);
        }
Beispiel #4
0
        override public float Run()
        {
            if (soundObject)
            {
                if ((audioClip != null && soundObject.IsPlaying(audioClip)) || (audioClip == null && soundObject.IsPlaying()))
                {
                    // Sound object is already playing the desired clip
                    if (ignoreIfPlaying && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                    {
                        return(0f);
                    }
                }

                if (audioClip && soundObject.GetComponent <AudioSource>())
                {
                    if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)
                    {
                        soundObject.GetComponent <AudioSource>().clip = audioClip;
                    }
                }

                if (soundObject.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                {
                    Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[];
                    foreach (Sound sound in sounds)
                    {
                        sound.EndOldMusic(soundObject);
                    }
                }

                if (soundAction == SoundAction.Play)
                {
                    soundObject.Play(loop);
                }
                else if (soundAction == SoundAction.FadeIn)
                {
                    if (fadeTime == 0f)
                    {
                        soundObject.Play(loop);
                    }
                    else
                    {
                        soundObject.FadeIn(fadeTime, loop);
                    }
                }
                else if (soundAction == SoundAction.FadeOut)
                {
                    if (fadeTime == 0f)
                    {
                        soundObject.Stop();
                    }
                    else
                    {
                        soundObject.FadeOut(fadeTime);
                    }
                }
                else if (soundAction == SoundAction.Stop)
                {
                    soundObject.Stop();

                    if (affectChildren)
                    {
                        foreach (Transform child in soundObject.transform)
                        {
                            if (child.GetComponent <Sound>())
                            {
                                child.GetComponent <Sound>().Stop();
                            }
                        }
                    }
                }
            }

            return(0f);
        }