Exemple #1
0
        // Token: 0x06002041 RID: 8257 RVA: 0x0009F4E8 File Offset: 0x0009D6E8
        private void PhysicsAttach(Hand hand)
        {
            this.PhysicsDetach(hand);
            Rigidbody rigidbody = null;
            Vector3   item      = Vector3.zero;
            float     num       = float.MaxValue;

            for (int i = 0; i < this.rigidBodies.Count; i++)
            {
                float num2 = Vector3.Distance(this.rigidBodies[i].worldCenterOfMass, hand.transform.position);
                if (num2 < num)
                {
                    rigidbody = this.rigidBodies[i];
                    num       = num2;
                }
            }
            if (rigidbody == null)
            {
                return;
            }
            if (this.attachMode == ComplexThrowable.AttachMode.FixedJoint)
            {
                Util.FindOrAddComponent <Rigidbody>(hand.gameObject).isKinematic = true;
                hand.gameObject.AddComponent <FixedJoint>().connectedBody        = rigidbody;
            }
            hand.HoverLock(null);
            Vector3 b = hand.transform.position - rigidbody.worldCenterOfMass;

            b    = Mathf.Min(b.magnitude, 1f) * b.normalized;
            item = rigidbody.transform.InverseTransformPoint(rigidbody.worldCenterOfMass + b);
            hand.AttachObject(base.gameObject, this.attachmentFlags, "");
            this.holdingHands.Add(hand);
            this.holdingBodies.Add(rigidbody);
            this.holdingPoints.Add(item);
        }
Exemple #2
0
        //-------------------------------------------------
        public void PhysicsAttach(Hand hand, GrabTypes startingGrabType)
        {
            GetComponentsInChildren(rigidBodies);
            PhysicsDetach(hand);

            Rigidbody holdingBody  = null;
            Vector3   holdingPoint = Vector3.zero;

            // The hand should grab onto the nearest rigid body
            float closestDistance = float.MaxValue;

            for (int i = 0; i < rigidBodies.Count; i++)
            {
                float distance = Vector3.Distance(rigidBodies[i].worldCenterOfMass, hand.transform.position);
                if (distance < closestDistance)
                {
                    holdingBody     = rigidBodies[i];
                    closestDistance = distance;
                }
            }

            // Couldn't grab onto a body
            if (holdingBody == null)
            {
                return;
            }

            // Create a fixed joint from the hand to the holding body
            if (attachMode == AttachMode.FixedJoint)
            {
                Rigidbody handRigidbody = Util.FindOrAddComponent <Rigidbody>(hand.gameObject);
                handRigidbody.isKinematic = true;

                FixedJoint handJoint = hand.gameObject.AddComponent <FixedJoint>();
                handJoint.enableCollision = true;
                handJoint.connectedBody   = holdingBody;
            }

            // Don't let the hand interact with other things while it's holding us
            hand.HoverLock(null);

            // Affix this point
            Vector3 offset = hand.transform.position - holdingBody.worldCenterOfMass;

            offset       = Mathf.Min(offset.magnitude, 1.0f) * offset.normalized;
            holdingPoint = holdingBody.transform.InverseTransformPoint(holdingBody.worldCenterOfMass + offset);

            hand.AttachObject(this.gameObject, startingGrabType, attachmentFlags);

            // Update holding list
            holdingHands.Add(hand);
            holdingBodies.Add(holdingBody);
            holdingPoints.Add(holdingPoint);
        }