コード例 #1
0
        protected virtual void OnCollisionEnter(Collision collision)
        {
            Collider collider = collision.collider;

            if (SoundObjects.ContainsKey(collider))
            {
                NVRCollisionSoundObject collisionSoundObject = SoundObjects[collider];

                float volume = CalculateImpactVolume(collision);
                if (volume < NVRCollisionSoundController.Instance.MinCollisionVolume)
                {
                    //Debug.Log("Volume too low to play: " + Volume);
                    return;
                }

                NVRCollisionSoundController.Play(this.Material, collision.contacts[0].point, volume);
                NVRCollisionSoundController.Play(collisionSoundObject.Material, collision.contacts[0].point, volume);
            }
        }
コード例 #2
0
        public void PlayCollisionAudio(Collision collision, float volume)
        {
            if (m_cooldownTimer > 0)
            {
                // Ignore sound
                return;
            }

            float thisScale = transform.localScale.x;

            // Play this object's collision sound, depending on scale if so configured
            string thisMat = m_material;

            if (m_smallScaleThreshold != 0.0f && thisScale < m_smallScaleThreshold)
            {
                thisMat = m_smallScaleMaterial;
            }
            else if (m_largeScaleThreshold != 0.0f && thisScale > m_largeScaleThreshold)
            {
                thisMat = m_largeScaleMaterial;
            }

            if (string.IsNullOrEmpty(thisMat))
            {
                thisMat = NVRCollisionSoundMaterialsList.DefaultMaterial;
            }

            if (thisMat != NVRCollisionSoundMaterialsList.EmptyMaterialName)
            {
                //Debug.Log("Play " + thisMat + " " + gameObject.name);
                NVRCollisionSoundController.Play(thisMat, collision.contacts[0].point, volume);
            }

            if (m_soundCooldown > 0)
            {
                // Start timer to prevent multiple sounds triggered in quick succession
                m_cooldownTimer = m_soundCooldown;
            }
        }