Exemple #1
0
        public static void LocalGrab(HandTarget handTarget, GameObject obj, bool rangeCheck = true)
        {
            Rigidbody objRigidbody = obj.GetComponent <Rigidbody>();
            Transform objTransform = obj.GetComponent <Transform>();

            if (handTarget.grabbedObject == null)
            {
                if (objRigidbody != null)
                {
                    NoGrab noGrab = objRigidbody.GetComponent <NoGrab>();
                    if (noGrab != null)
                    {
                        return;
                    }
                }

                if (objRigidbody != null && objRigidbody.mass > maxGrabbingMass)
                {
                    return;
                }

                bool grabbed = false;
                if (objRigidbody != null)
                {
                    grabbed = GrabRigidbody(handTarget, objRigidbody, rangeCheck);
                }
                else
                {
                    grabbed = GrabStaticObject(handTarget, objTransform, rangeCheck);
                }

                if (grabbed)
                {
                    if (handTarget.humanoid.physics)
                    {
                        //HumanoidTarget.SetColliderToTrigger(handTarget.hand.bone.transform.gameObject, true);
                        AdvancedHandPhysics.SetNonKinematic(handTarget.handRigidbody, handTarget.colliders);
                        //handTarget.colliders = HumanoidTarget.SetColliderToTrigger(handTarget.hand.bone.transform.gameObject);
                        if (handTarget.handPhysics != null && handTarget.handPhysics.mode != AdvancedHandPhysics.PhysicsMode.ForceLess)
                        {
                            handTarget.handPhysics.DeterminePhysicsMode(kinematicMass);
                        }
                    }

                    handTarget.SendMessage("OnGrabbing", handTarget.grabbedObject, SendMessageOptions.DontRequireReceiver);
                    handTarget.grabbedObject.SendMessage("OnGrabbed", handTarget, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
Exemple #2
0
        public static void LocalLetGo(HandTarget handTarget)
        {
            //Debug.Log("LetGo");
            if (handTarget.hand.bone.transform == null || handTarget.grabbedObject == null)
            {
                return;
            }


            if (handTarget.humanoid.physics)
            {
                AdvancedHandPhysics.SetNonKinematic(handTarget.handRigidbody, handTarget.colliders);
            }
            //AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody, true);
            //handTarget.colliders = AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody);

            Joint joint = handTarget.hand.bone.transform.GetComponent <Joint>();

            if (joint != null)
            {
                LetGoJoint(handTarget, joint);
            }
            else
            {
                LetGoParenting(handTarget);
            }

            if (handTarget.humanoid.physics)
            {
                handTarget.colliders = AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody);
            }

            if (handTarget.humanoid.dontDestroyOnLoad)
            {
                // Prevent this object inherites the dontDestroyOnLoad from the humanoid
                Object.DontDestroyOnLoad(handTarget.grabbedObject);
            }

            LetGoGrabbedObject(handTarget);
        }