public override void Attach(Rigidbody connectedBody, ObjectGrabber hand) { base.Attach(connectedBody, hand); if (!Magnetic) { // Add a fixed joint to the object FixedJoint joint = GetComponent <FixedJoint>(); Destroy(joint); joint = gameObject.AddComponent <FixedJoint>(); // Attach the created joint to the hand joint.connectedBody = connectedBody; joint.anchor = Rigidbody.position - connectedBody.position; _connection = joint; } _grabDistance = Vector3.Distance(transform.position, Hand.HandRigidbody.position); _grabOffset = connectedBody.position - transform.position; Rigidbody.useGravity = GravityWhenGrabbed; StartCoroutine(AssistanceCheck(transform.position)); if (HighlightWhenGrabbed) { ActivateOutline(true); } }
/// <summary> /// Dettach the given joint from this interactable /// </summary> /// <param name="connection"></param> public virtual void Dettach(ObjectGrabber hand) { Hand = null; if (OnReleased != null) { OnReleased.Invoke(); } }
// Use this for initialization private void Start() { Application.runInBackground = true; string[] fingers = { "thumb_0", "index_0", "middle_0", "ring_0", "pinky_0" }; // Associate the game transforms with the skeletal model. GameTransforms = new Transform[5][]; _modelTransforms = new Transform[5][]; for (var i = 0; i < 5; i++) { GameTransforms[i] = new Transform[4]; _modelTransforms[i] = new Transform[4]; for (var j = 1; j < 4; j++) { var postfix = device_type == device_type_t.GLOVE_LEFT ? "_l" : "_r"; var finger = fingers[i] + j + postfix; GameTransforms[i][j] = FindDeepChild(RootTranform, finger); } } // Initializing the hand _handRigidbody = RootTranform.GetComponent <Rigidbody>(); Phalange handPhalange = _handRigidbody.gameObject.AddComponent <Phalange>(); handPhalange.PhalangeData = new PhalangeData(0, 0, device_type); _phalanges.Add(_handRigidbody.GetComponent <Phalange>()); GameObject phalangeParent = new GameObject("Phalanges"); ConvertFingersToPhysics(phalangeParent.transform); ReleaseHand(); foreach (var phalange in _phalanges) { phalange.CollisionEntered += PhalangeCollisionEntered; } //Prototype var grabbers = GetComponents <ObjectGrabber>(); foreach (var grabber in grabbers) { if (grabber.DeviceType == device_type) { _grabber = grabber; } } }
public override void Dettach(ObjectGrabber hand) { base.Dettach(hand); Rigidbody.useGravity = GravityWhenReleased; Rigidbody.isKinematic = KinematicWhenReleased; Destroy(_connection); if (HighlightWhenGrabbed) { ActivateOutline(false); } }
/// <summary> /// Attach this interactable to the given rigidbody /// </summary> /// <param name="connectedBody"></param> /// <param name="attachedJoint"></param> public virtual void Attach(Rigidbody connectedBody, ObjectGrabber hand) { if (Hand != null) { Hand.ReleaseItem(this); } Hand = hand; if (OnGrabbed != null) { OnGrabbed.Invoke(); } }