Пример #1
0
 void PlayThrowSound()
 {
     if (hasThrowSource)
     {
         throwSource.volume = MathSupplement.Exerp(0, 1, Mathf.InverseLerp(0.06f, 8, rigidBody.velocity.sqrMagnitude));
         throwSource.Play();
     }
 }
Пример #2
0
        private void OnCollisionStay(Collision collision)
        {
            if (!enabled)
            {
                return;
            }

            if (collision.collider.gameObject.layer == InteractionManager.instance.contactBoneLayer)
            {
                return;
            }
            if (collision.collider.gameObject.tag == "NoSlideParticles")
            {
                return;
            }

            float particleTValue = Mathf.InverseLerp(0.1f, maxMagnitude, rigidBody.velocity.magnitude);

            if (HasSoundSource())
            {
                float soundTValue = Mathf.InverseLerp(0, maxSoundMagnitude, rigidBody.velocity.magnitude);
                interactionSound.SlideSource.volume = slideSoundVolume.Evaluate(soundTValue);
            }
            emission.rateOverTime       = Mathf.Lerp(0, maxEmissionRate, particleTValue);
            particle.transform.position = collision.contacts[0].point;

            bool grabbedByLeft  = false;
            bool grabbedByRight = false;

            // do grab feedback
            if (interactionBehaviour.graspingControllers.Count > 0)
            {
                // grabbing vibration feedback
                float leftGrabDistance  = 0;
                float rightGrabDistance = 0;

                InteractionController leftGrabbingController;
                InteractionController rightGrabbingController;

                float hapticTValue = MathSupplement.Coserp(0, 1, Mathf.InverseLerp(minHapticMagnitude, maxHapticMagnitude, rigidBody.velocity.magnitude));

                GetGrabbingControllers(out grabbedByLeft, out grabbedByRight, out leftGrabbingController, out rightGrabbingController);

                if (leftGrabbingController)
                {
                    leftGrabDistance = interactionBehaviour.GetHoverDistance(leftGrabbingController.GetGraspPoint());

                    HandFeedback.LeftHand.Amplitude = 1 - Mathf.InverseLerp(0, maxHapticDist, leftGrabDistance);
                    HandFeedback.LeftHand.Frequency = Mathf.Lerp(0, 320, hapticTValue);
                }

                if (rightGrabbingController)
                {
                    rightGrabDistance = interactionBehaviour.GetHoverDistance(rightGrabbingController.GetGraspPoint());

                    HandFeedback.RightHand.Amplitude = 1 - Mathf.InverseLerp(0, maxHapticDist, rightGrabDistance);
                    HandFeedback.RightHand.Frequency = Mathf.Lerp(0, 320, hapticTValue);
                }
            }

            if (grabbedByLeft != grabbedLeftPreviousFrame)
            {
                // state change
                if (grabbedByLeft)
                {
                    leftIsGrabbedToken = HandFeedback.LeftHand.OverridePenetrationHaptics.AddLens(new Lens <bool>(0, (grabbed) => true));
                }
                else
                {
                    leftIsGrabbedToken.Remove();
                    leftIsGrabbedToken = null;
                }
            }

            if (grabbedByRight != grabbedRightPreviousFrame)
            {
                // state change
                if (grabbedByRight)
                {
                    rightIsGrabbedToken = HandFeedback.RightHand.OverridePenetrationHaptics.AddLens(new Lens <bool>(0, (grabbed) => true));
                }
                else
                {
                    rightIsGrabbedToken.Remove();
                    rightIsGrabbedToken = null;
                }
            }

            // save our state
            grabbedLeftPreviousFrame  = grabbedByLeft;
            grabbedRightPreviousFrame = grabbedByRight;
        }