예제 #1
0
        protected void playImpactSound(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint)
        {
            if (SoundMaterial == null || !this.enabled || SoundMaterial.AudioSets.Count == 0 || Time.frameCount == _lastFrame)
            {
                return;
            }

            if (ImpactAudio)
            {
                AudioClip a = SoundMaterial.GetImpactAudio(otherObject, relativeVelocity, normal, contactPoint);

                if (a)
                {
                    float pitch = baseImpactPitch * SoundMaterial.GetScaleModPitch(transform.localScale) + SoundMaterial.GetRandomPitch();
                    float vol   = baseImpactVol * SoundMaterial.GetScaleModVolume(transform.localScale) * SoundMaterial.GetImpactVolume(relativeVelocity, normal);

                    if (PlayClipAtPoint)
                    {
                        PhysSoundTempAudioPool.Instance.PlayClip(a, transform.position, ImpactAudio, SoundMaterial.ScaleImpactVolume ? vol : ImpactAudio.volume, pitch);
                    }
                    else
                    {
                        ImpactAudio.pitch = pitch;
                        if (SoundMaterial.ScaleImpactVolume)
                        {
                            ImpactAudio.volume = vol;
                        }

                        ImpactAudio.clip = a;
                        ImpactAudio.Play();
                    }

                    _lastFrame = Time.frameCount;
                }
            }
        }
        /// <summary>
        /// Sets the target volume and pitch of the sliding sound effect based on the given object that was hit, velocity, and normal.
        /// </summary>
        public void SetTargetVolumeAndPitch(GameObject parentObject, GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, bool exit, float mod = 1)
        {
            if (SlideAudio == null)
            {
                return;
            }

            float vol = exit || !_mat.CollideWith(otherObject) ? 0 : _mat.GetSlideVolume(relativeVelocity, normal) * _baseVol * mod;

            if (_lastFrame == Time.frameCount)
            {
                if (_targetVolume < vol)
                {
                    _targetVolume = vol;
                }
            }
            else
            {
                _targetVolume = vol;
            }

            if (!SlideAudio.isPlaying)
            {
                _basePitchRand = _basePitch * _mat.GetScaleModPitch(parentObject.transform.localScale) + _mat.GetRandomPitch();
                SlideAudio.Play();
            }

            SlideAudio.pitch = _basePitchRand + relativeVelocity.magnitude * _mat.SlidePitchMod;

            _lastFrame = Time.frameCount;
        }