IEnumerator TryEquipOnTargetReceiver() { if (!currentTargetReceiver) { yield break; } yield return(null); // Check to see if we can equip this receiver. if (ReceivedEquipRequest?.Invoke(currentTargetReceiver) == false) { yield break; } // Equip to the receiver. rigidbody.isKinematic = true; transform.parent = currentTargetReceiver.transform; transform.localPosition = equipLocalPos; transform.localEulerAngles = equipLocalRot; // Set the current receiver and forget the receiver target. CurrentReceiver = currentTargetReceiver; currentTargetReceiver = null; // Disable grab. Destroy(grabInteractable); // Call event. Equipped?.Invoke(CurrentReceiver); }
bool IsOnSameRigAsOtherEquippables(XREquippableReceiver targetReceiver) { // Try to find an XRRig in other equippables. XRRig othersRig = null; foreach (var otherEquippable in otherEquippables) { try { othersRig = otherEquippable.CurrentReceiver.GetComponentInParent <XRRig>(); break; } catch { } } // If we found a rig, check if it is the same rig as the one we are targetting. if (othersRig) { return(othersRig == targetReceiver.GetComponentInParent <XRRig>()); } else { return(true); } }
void TryEquipStartOnOther(Collider other) { XREquippableReceiver targetEquipable = other.GetComponent <XREquippableReceiver>(); // Stop if the other is not an acceptable receiver. if (!targetEquipable || (!string.IsNullOrWhiteSpace(receiverNameToCheck) && receiverNameToCheck != targetEquipable.ReceiverName)) { return; } // Stop if we are not grabbed. if (!grabInteractable.selectingInteractor) { return; } // Stop if our equip condition isn't met. if (EquipCondition == null || EquipCondition(targetEquipable)) { return; } // Ask the receiver to drop the object. We should equip when we see that we are released. currentTargetReceiver = targetEquipable; grabInteractable.selectingInteractor.DropObjectNow(); }