상속: MonoBehaviour
예제 #1
0
        // Token: 0x06003FDC RID: 16348 RVA: 0x00140F9C File Offset: 0x0013F39C
        private void _setSlideTargetVolumes(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit)
        {
            PhysSoundMaterial physSoundMaterial = null;
            PhysSoundBase     physSoundBase     = (!(otherObject == null)) ? otherObject.GetComponent <PhysSoundBase>() : null;

            if (physSoundBase)
            {
                if (!(physSoundBase is PhysSoundTerrain))
                {
                    physSoundMaterial = physSoundBase.GetPhysSoundMaterial(contactPoint);
                }
            }
            PhysSoundAudioContainer physSoundAudioContainer2;

            if (physSoundMaterial)
            {
                PhysSoundAudioContainer physSoundAudioContainer;
                if (this.audioContainersDic.TryGetValue(physSoundMaterial.MaterialTypeKey, out physSoundAudioContainer))
                {
                    physSoundAudioContainer.SetTargetVolumeAndPitch(base.gameObject, otherObject, relativeVelocity, normal, exit, 1f);
                }
                else if (this.SoundMaterial.FallbackTypeKey != -1 && this.audioContainersDic.TryGetValue(this.SoundMaterial.FallbackTypeKey, out physSoundAudioContainer))
                {
                    physSoundAudioContainer.SetTargetVolumeAndPitch(base.gameObject, otherObject, relativeVelocity, normal, exit, 1f);
                }
            }
            else if (this.SoundMaterial.FallbackTypeKey != -1 && this.audioContainersDic.TryGetValue(this.SoundMaterial.FallbackTypeKey, out physSoundAudioContainer2))
            {
                physSoundAudioContainer2.SetTargetVolumeAndPitch(base.gameObject, otherObject, relativeVelocity, normal, exit, 1f);
            }
        }
예제 #2
0
        private void setSlideTargetVolumes(PhysSoundBase otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit)
        {
            PhysSoundMaterial m = null;

            if (otherObject)
            {
                //Special case for sliding against a terrain
                if (otherObject is PhysSoundTerrain)
                {
                    PhysSoundTerrain terr = otherObject as PhysSoundTerrain;
                    Dictionary <int, PhysSoundComposition> compDic = terr.GetComposition(contactPoint);

                    foreach (PhysSoundAudioContainer c in audioContainersDic.Values)
                    {
                        PhysSoundComposition comp;
                        float mod = 0;

                        if (compDic.TryGetValue(c.KeyIndex, out comp))
                        {
                            mod = comp.GetAverage();
                        }

                        c.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit, mod);
                    }

                    return;
                }
                else
                {
                    m = otherObject.GetPhysSoundMaterial(contactPoint);
                }
            }

            //General cases
            //If the other object has a PhysSound material
            if (m)
            {
                PhysSoundAudioContainer aud;

                if (audioContainersDic.TryGetValue(m.MaterialTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit);
                }
                else if (SoundMaterial.FallbackTypeKey != -1 && audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit);
                }
            }
            //If it doesnt we set vols based on the fallback setting of our material
            else
            {
                PhysSoundAudioContainer aud;

                if (SoundMaterial.FallbackTypeKey != -1 && audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the impact audio clip based on the given object that was hit, the velocity of the collision, the normal, and the contact point.
        /// </summary>
        public AudioClip GetImpactAudio(PhysSoundBase otherObject, Vector3 relativeVel, Vector3 norm, Vector3 contact)
        {
            if (audioSetDic == null)
                return null;

            PhysSoundMaterial m = null;

            if (otherObject)
                m = otherObject.GetPhysSoundMaterial(contact);

            //Get sounds using collision velocity
            if (UseCollisionVelocity)
            {
                float velNorm = GetImpactVolume(relativeVel, norm);

                if (velNorm < 0)
                    return null;

                if (m)
                {
                    PhysSoundAudioSet audSet;

                    if (audioSetDic.TryGetValue(m.MaterialTypeKey, out audSet))
                        return audSet.GetImpact(velNorm, false);
                    else if (FallbackTypeKey != -1)
                        return audioSetDic[FallbackTypeKey].GetImpact(velNorm, false);
                }
                else if (FallbackTypeKey != -1)
                    return audioSetDic[FallbackTypeKey].GetImpact(velNorm, false);
            }
            //Get sound randomly
            else
            {
                if (m)
                {
                    PhysSoundAudioSet audSet;

                    if (audioSetDic.TryGetValue(m.MaterialTypeKey, out audSet))
                        return audSet.GetImpact(0, true);
                    else if (FallbackTypeKey != -1)
                        return audioSetDic[FallbackTypeKey].GetImpact(0, true);
                }
                else if (FallbackTypeKey != -1)
                    return audioSetDic[FallbackTypeKey].GetImpact(0, true);
            }

            return null;
        }
예제 #4
0
        private void playImpactSound(PhysSoundBase otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint)
        {
            if (ImpactAudio)
            {
                AudioClip a = SoundMaterial.GetImpactAudio(otherObject, relativeVelocity, normal, contactPoint);

                if (a)
                {
                    float pitch = baseImpactPitch + Random.Range(-SoundMaterial.PitchRandomness, SoundMaterial.PitchRandomness);
                    float vol   = baseImpactVol * SoundMaterial.GetImpactVolume(relativeVelocity, normal);

                    ImpactAudio.pitch = pitch;
                    if (SoundMaterial.ScaleImpactVolume)
                    {
                        ImpactAudio.volume = vol;
                    }

                    ImpactAudio.clip = a;
                    ImpactAudio.Play();
                }
            }
        }
예제 #5
0
        private void setSlideTargetVolumes(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit)
        {
            //log("Sliding! " + gameObject.name + " against " + otherObject.name + " - Relative Velocity: " + relativeVelocity + ", Normal: " + normal + ", Contact Point: " + contactPoint + ", Exit: " + exit);

            if (SoundMaterial == null || !this.enabled || SoundMaterial.AudioSets.Count == 0)
            {
                return;
            }

            PhysSoundMaterial m = null;
            PhysSoundBase     b = otherObject == null ? null : otherObject.GetComponent <PhysSoundBase>();

            if (b)
            {
                //Special case for sliding against a terrain
                if (b is PhysSoundTerrain)
                {
                    PhysSoundTerrain terr = b as PhysSoundTerrain;
                    Dictionary <int, PhysSoundComposition> compDic = terr.GetComposition(contactPoint);

                    foreach (PhysSoundAudioContainer c in _audioContainersDic.Values)
                    {
                        PhysSoundComposition comp;
                        float mod = 0;

                        if (compDic.TryGetValue(c.KeyIndex, out comp))
                        {
                            mod = comp.GetAverage();
                        }

                        c.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit, mod);
                    }

                    return;
                }
                else
                {
                    m = b.GetPhysSoundMaterial(contactPoint);
                }
            }

            //General cases
            //If the other object has a PhysSound material
            if (m)
            {
                PhysSoundAudioContainer aud;

                if (_audioContainersDic.TryGetValue(m.MaterialTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit);
                }
                else if (!SoundMaterial.HasAudioSet(m.MaterialTypeKey) && SoundMaterial.FallbackTypeKey != -1 && _audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit);
                }
            }
            //If it doesnt we set volumes based on the fallback setting of our material
            else
            {
                PhysSoundAudioContainer aud;

                if (SoundMaterial.FallbackTypeKey != -1 && _audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Gets the impact audio clip based on the given object that was hit, the velocity of the collision, the normal, and the contact point.
        /// </summary>
        public AudioClip GetImpactAudio(GameObject otherObject, Vector3 relativeVel, Vector3 norm, Vector3 contact, int layer = -1)
        {
            if (audioSetDic == null)
            {
                return(null);
            }

            if (!CollideWith(otherObject))
            {
                return(null);
            }

            PhysSoundMaterial m = null;
            PhysSoundBase     b = otherObject.GetComponent <PhysSoundBase>();

            if (b)
            {
                m = b.GetPhysSoundMaterial(contact);
            }

            //Get sounds using collision velocity
            if (UseCollisionVelocity)
            {
                float velNorm = GetImpactVolume(relativeVel, norm);

                if (velNorm < 0)
                {
                    return(null);
                }

                if (m)
                {
                    PhysSoundAudioSet audSet;

                    if (audioSetDic.TryGetValue(m.MaterialTypeKey, out audSet))
                    {
                        return(audSet.GetImpact(velNorm, false));
                    }
                    else if (FallbackTypeKey != -1)
                    {
                        return(audioSetDic[FallbackTypeKey].GetImpact(velNorm, false));
                    }
                }
                else if (FallbackTypeKey != -1)
                {
                    return(audioSetDic[FallbackTypeKey].GetImpact(velNorm, false));
                }
            }
            //Get sound randomly
            else
            {
                if (m)
                {
                    PhysSoundAudioSet audSet;

                    if (audioSetDic.TryGetValue(m.MaterialTypeKey, out audSet))
                    {
                        return(audSet.GetImpact(0, true));
                    }
                    else if (FallbackTypeKey != -1)
                    {
                        return(audioSetDic[FallbackTypeKey].GetImpact(0, true));
                    }
                }
                else if (FallbackTypeKey != -1)
                {
                    return(audioSetDic[FallbackTypeKey].GetImpact(0, true));
                }
            }

            return(null);
        }
예제 #7
0
        private void setSlideTargetVolumes(PhysSoundBase otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit)
        {
            PhysSoundMaterial m = null;

            if (otherObject)
            {
                //Special case for sliding against a terrain
                if (otherObject is PhysSoundTerrain)
                {
                    PhysSoundTerrain terr = otherObject as PhysSoundTerrain;
                    Dictionary<int, PhysSoundComposition> compDic = terr.GetComposition(contactPoint);

                    foreach (PhysSoundAudioContainer c in audioContainersDic.Values)
                    {
                        PhysSoundComposition comp;
                        float mod = 0;

                        if (compDic.TryGetValue(c.KeyIndex, out comp))
                            mod = comp.GetAverage();

                        c.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit, mod);
                    }

                    return;
                }
                else
                    m = otherObject.GetPhysSoundMaterial(contactPoint);
            }

            //General cases
            //If the other object has a PhysSound material
            if (m)
            {
                PhysSoundAudioContainer aud;

                if (audioContainersDic.TryGetValue(m.MaterialTypeKey, out aud))
                    aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit);
                else if (SoundMaterial.FallbackTypeKey != -1 && audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                    aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit);
            }
            //If it doesnt we set vols based on the fallback setting of our material
            else
            {
                PhysSoundAudioContainer aud;

                if (SoundMaterial.FallbackTypeKey != -1 && audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                    aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit);
            }
        }
예제 #8
0
        private void playImpactSound(PhysSoundBase otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint)
        {
            if (ImpactAudio)
            {
                AudioClip a = SoundMaterial.GetImpactAudio(otherObject, relativeVelocity, normal, contactPoint);

                if (a)
                {
                    float pitch = baseImpactPitch + Random.Range(-SoundMaterial.PitchRandomness, SoundMaterial.PitchRandomness);
                    float vol = baseImpactVol * SoundMaterial.GetImpactVolume(relativeVelocity, normal);

                    ImpactAudio.pitch = pitch;
                    if (SoundMaterial.ScaleImpactVolume)
                        ImpactAudio.volume = vol;

                    ImpactAudio.clip = a;
                    ImpactAudio.Play();
                }
            }
        }
예제 #9
0
        // Token: 0x06003FCA RID: 16330 RVA: 0x00140500 File Offset: 0x0013E900
        public KeyValuePair <int, int>?GetImpactAudio(GameObject otherObject, Vector3 relativeVel, Vector3 norm, Vector3 contact, int layer = -1)
        {
            if (this.audioSetDic == null)
            {
                return(null);
            }
            if (!this.CollideWith(otherObject))
            {
                return(null);
            }
            PhysSoundMaterial physSoundMaterial = null;
            PhysSoundBase     component         = otherObject.GetComponent <PhysSoundBase>();

            if (component)
            {
                physSoundMaterial = component.GetPhysSoundMaterial(contact);
            }
            int key = 0;
            int?num = null;

            if (this.UseCollisionVelocity)
            {
                float impactVolume = this.GetImpactVolume(relativeVel, norm);
                if (impactVolume < 0f)
                {
                    return(null);
                }
                if (physSoundMaterial)
                {
                    PhysSoundAudioSet physSoundAudioSet;
                    if (this.audioSetDic.TryGetValue(physSoundMaterial.MaterialTypeKey, out physSoundAudioSet))
                    {
                        key = physSoundMaterial.MaterialTypeKey;
                        num = physSoundAudioSet.GetImpact(impactVolume, false);
                    }
                    else if (this.FallbackTypeKey != -1)
                    {
                        key = this.FallbackTypeKey;
                        num = physSoundAudioSet.GetImpact(impactVolume, false);
                    }
                }
                else if (this.FallbackTypeKey != -1)
                {
                    key = this.FallbackTypeKey;
                    num = this.audioSetDic[this.FallbackTypeKey].GetImpact(impactVolume, false);
                }
            }
            else if (physSoundMaterial)
            {
                PhysSoundAudioSet physSoundAudioSet2;
                if (this.audioSetDic.TryGetValue(physSoundMaterial.MaterialTypeKey, out physSoundAudioSet2))
                {
                    key = physSoundMaterial.MaterialTypeKey;
                    num = physSoundAudioSet2.GetImpact(0f, true);
                }
                else if (this.FallbackTypeKey != -1)
                {
                    key = this.FallbackTypeKey;
                    num = physSoundAudioSet2.GetImpact(0f, true);
                }
            }
            else if (this.FallbackTypeKey != -1)
            {
                key = this.FallbackTypeKey;
                num = this.audioSetDic[this.FallbackTypeKey].GetImpact(0f, true);
            }
            if (num != null)
            {
                return(new KeyValuePair <int, int>?(new KeyValuePair <int, int>(key, num.Value)));
            }
            return(null);
        }