protected virtual bool isValidGrabbale(Collider col, Grabbable grab) { // Object has been deactivated. Remove it if (col == null || grab == null || !grab.isActiveAndEnabled || !col.enabled) { return(false); } // Not considered grabbable any longer. May have been picked up, marked, etc. else if (!grab.IsGrabbable()) { return(false); } // Snap Zone without an item isn't a valid grab. Want to skip this unless something is inside else if (grab.GetComponent <SnapZone>() != null && grab.GetComponent <SnapZone>().HeldItem == null) { return(false); } // Position was manually set outside of break distance // No longer possible for it to be the closestGrabbable else if (grab == ClosestGrabbable) { if (grab.BreakDistance > 0 && Vector3.Distance(grab.transform.position, transform.position) > grab.BreakDistance) { return(false); } } return(true); }
IEnumerator EjectMagRoutine(Grabbable ejectedMag) { if (ejectedMag != null && ejectedMag.GetComponent <Rigidbody>() != null) { Rigidbody ejectRigid = ejectedMag.GetComponent <Rigidbody>(); // Wait before ejecting // Move clip down before we eject it ejectedMag.transform.parent = transform; if (ejectedMag.transform.localPosition.y > -ClipSnapDistance) { ejectedMag.transform.localPosition = new Vector3(0, -0.1f, 0); } // Eject with physics force ejectedMag.transform.parent = null; ejectRigid.AddForce(-ejectedMag.transform.up * EjectForce, ForceMode.VelocityChange); yield return(new WaitForFixedUpdate()); ejectedMag.transform.parent = null; } yield return(null); }
public void GrabGrabbable(Grabbable grab) { // Grab is already in Snap Zone if (grab.transform.parent != null && grab.transform.parent.GetComponent <SnapZone>() != null) { return; } if (HeldItem != null) { ReleaseAll(); } HeldItem = grab; // Set scale factor // Use SnapZoneScale if specified if (grab.GetComponent <SnapZoneScale>()) { _scaleTo = grab.GetComponent <SnapZoneScale>().Scale; } else { _scaleTo = ScaleItem; } // Is there an offset to apply? SnapZoneOffset off = grab.GetComponent <SnapZoneOffset>(); if (off) { offset = off; } else { offset = grab.gameObject.AddComponent <SnapZoneOffset>(); offset.LocalPositionOffset = Vector3.zero; offset.LocalRotationOffset = Vector3.zero; } // Disable the grabbable. This is picked up through a Grab Action disableGrabbable(grab); grab.transform.parent = transform; // Call event if (OnSnapEvent != null) { OnSnapEvent.Invoke(grab); } if (SoundOnSnap) { VRUtils.Instance.PlaySpatialClipAt(SoundOnSnap, transform.position, 0.75f); } }
public void TryRelease() { if (HeldGrabbable != null && HeldGrabbable.CanBeDropped) { GrabbableEventArgs args = new GrabbableEventArgs(HeldGrabbable.GetComponent <Grabbable>(), this); HeldGrabbable.DropItem(this); Drop?.Invoke(args); } // No longer try to bring flying grabbable to us resetFlyingGrabbable(); }
void Awake() { grabClipArea = GetComponentInChildren <GrabberArea>(); if (transform.parent != null) { parentWeapon = transform.parent.GetComponent <RaycastWeapon>(); } // Check to see if we started with a loaded magazine if (HeldMagazine != null) { AttachGrabbableMagazine(HeldMagazine, HeldMagazine.GetComponent <Collider>()); } }
void Start() { weaponRigid = GetComponent <Rigidbody>(); if (SecondHandGrabbable) { secondHandRigid = SecondHandGrabbable.GetComponent <Rigidbody>(); } if (MuzzleFlashObject) { MuzzleFlashObject.SetActive(false); } ws = GetComponentInChildren <WeaponSlide>(); updateChamberedBullet(); }
public void GrabGrabbable(Grabbable grab) { // Grab is already in Snap Zone if (grab.transform.parent != null && grab.transform.parent.GetComponent <SnapZone>() != null) { return; } if (HeldItem != null) { ReleaseAll(); } HeldItem = grab; heldItemRigid = HeldItem.GetComponent <Rigidbody>(); // Mark as kinematic so it doesn't fall down if (heldItemRigid) { heldItemWasKinematic = heldItemRigid.isKinematic; heldItemRigid.isKinematic = true; } else { heldItemWasKinematic = false; } // Set the parent of the object grab.transform.parent = transform; // Set scale factor // Use SnapZoneScale if specified if (grab.GetComponent <SnapZoneScale>()) { _scaleTo = grab.GetComponent <SnapZoneScale>().Scale; } else { _scaleTo = ScaleItem; } // Is there an offset to apply? SnapZoneOffset off = grab.GetComponent <SnapZoneOffset>(); if (off) { offset = off; } else { offset = grab.gameObject.AddComponent <SnapZoneOffset>(); offset.LocalPositionOffset = Vector3.zero; offset.LocalRotationOffset = Vector3.zero; } // Lock into place if (offset) { HeldItem.transform.localPosition = offset.LocalPositionOffset; HeldItem.transform.localEulerAngles = offset.LocalRotationOffset; } else { HeldItem.transform.localPosition = Vector3.zero; HeldItem.transform.localEulerAngles = Vector3.zero; } // Disable the grabbable. This is picked up through a Grab Action disableGrabbable(grab); // Call Grabbable Event from SnapZone if (OnSnapEvent != null) { OnSnapEvent.Invoke(grab); } // Fire Off Events on Grabbable GrabbableEvents[] ge = grab.GetComponents <GrabbableEvents>(); if (ge != null) { for (int x = 0; x < ge.Length; x++) { ge[x].OnSnapZoneEnter(); } } if (SoundOnSnap) { VRUtils.Instance.PlaySpatialClipAt(SoundOnSnap, transform.position, 0.75f); } }