public void Detach(bool fromAttachMethod = false) { //Debug.Log("Detach: " + this, gameObject); //TrackedPoseDriver approach { DestroyTrackedPoseDriver(); } transform.DOKill(); //SLOT //------------------------------------------------- if (!fromAttachMethod) { TryStore(OwnerHandVR); } //------------------------------------------------- OwnerHandVR.AttachedGrabbable = null; //not needed, the BelongState gives if it is attached, not need to check if ownerHandVR is null like before, so ownerHandVR mainstains the last ownerHandVR when state is changed until it is attached again //can be useful to return grabbable to last hand //OwnerHandVR = null; //if it has been attached to a slot if (Stored) { //Events OnDetached?.Invoke(OwnerHandVR); #if UNITY_EDITOR Debug.Log("Dettached and Stored Grabbable: " + this + " from HandVR: " + OwnerHandVR, gameObject); #endif return; } //TrackedPoseDriver approach { transform.position = /*OwnerHandVR.transform.position*/ OwnerHandVR.PoseProvider.AttachPosition; transform.rotation = /*OwnerHandVR.transform.rotation*/ OwnerHandVR.PoseProvider.AttachRotation; } transform.parent = null; AdjustPhysicsWithPhysicsTracker(OwnerHandVR); state = BelongState.Free; PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders, false); //Undo Ignore Collisions between this and CharacterVR //Events OnDetached?.Invoke(OwnerHandVR); #if UNITY_EDITOR Debug.Log("Dettached Grabbable: " + this + " from HandVR: " + OwnerHandVR, gameObject); #endif }
public void SetOwnerSlot(Slot slot) { OwnerSlot = slot; state = BelongState.Stored; }
public void Attach(HandVR handVR, bool iterateAttachmentPoint = false) { //Debug.Log("Attach: " + this, gameObject); // TO DO: Test if not necessary I did it because maybe detach events are important. But attach should let things as they should be. if (Attached) { //True to avoid possible attach to Slot. Imagine you get from one hand to the other but the from hand is hovering a slot. then the detach will attach grabbable to the slot and then attach to the new hand making a strange effect Detach(true); } else if (Stored) { TryUnstore(OwnerSlot); } if (iterateAttachmentPoint) { currentAttachmentPointIndex++; } if (currentAttachmentPointIndex == attachmentPoints.Count) { currentAttachmentPointIndex = 0; } transform.DOKill(); transform.parent = handVR.transform; OwnerHandVR = handVR; //Important to do this and next line before real physic attach (position and rotation) to be able to detach from it if other hand steal it on the fly to the hand handVR.AttachedGrabbable = this; DisableColliders(); //Disable collider to avoid not desired collisions on attach Vector3 attachPositionOffset = Vector3.zero; Quaternion attachRotationOffset = Quaternion.identity; GetLocalAttachmentPositionAndRotation(handVR.transform, out attachPositionOffset, out attachRotationOffset, handVR.AttachmentPointName.name, iterateAttachmentPoint); float attachTime = DataVR.Instance.grabbable.attachTime; transform.DOLocalMove(-attachPositionOffset, attachTime).SetEase(Ease.OutSine); transform.DOLocalRotate(-attachRotationOffset.eulerAngles, attachTime).SetEase(Ease.OutSine).OnComplete ( () => { PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders); //Ignore Collisions between this and CharacterVR EnableColliders(); //Enable collider (disabled above, before tween attach) WARNING. it is detected by ontriggerenter of physicsproximityAdjust //TrackedPoseDriver approach { ////Set final position ////------------------------------------------------- //if (attachmentPoints.Count == 0 || (handVR.AttachmentPointName.name == "" && iterateAttachmentPoint == false)) //{ // transform.localPosition = Vector3.zero; // transform.localRotation = Quaternion.identity; //} //else //{ // transform.localPosition = -attachPositionOffset; // transform.localRotation = Quaternion.Inverse(attachRotationOffset); //} ////------------------------------------------------- } //SLOT: as it could be in a slot make it kinematic again Rigidbody.interpolation = RigidbodyInterpolation.None; Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative; //TrackedPoseDriver approach { //Original approach //Rigidbody.isKinematic = true; AddTrackedPoseDriver(handVR, attachPositionOffset, attachRotationOffset); } Rigidbody.useGravity = false; state = BelongState.Attached; //Events OnAttached?.Invoke(handVR); #if UNITY_EDITOR Debug.Log("Attach Grabbable: " + this + " to HandVR: " + handVR, gameObject); #endif } ); }