/// <summary>Called by the hand whenever this item is release</summary> public virtual void OnRelease(Hand hand, bool thrown) { if (beingHeld) { if (lockHandOnGrab) { hand.GetComponent <Rigidbody>().isKinematic = false; } if (!heldBy.Remove(hand)) { return; } OnReleaseEvent?.Invoke(hand, this); if (heldBy.Count == 0) { beingHeld = false; body.transform.parent = originalParent; } onRelease?.Invoke(); if (body != null) { if (!beingHeld && thrown && !throwing && gameObject.layer != LayerMask.NameToLayer("Grabbing")) { throwing = true; body.velocity += hand.ThrowVelocity() * throwMultiplyer; try { body.angularVelocity = GetAngularVelocity(); } catch { } } Invoke("OriginalCollisionDetection", 5f); SetLayerRecursive(transform, LayerMask.NameToLayer("Grabbing"), LayerMask.NameToLayer("Releasing")); SetLayerRecursive(transform, LayerMask.NameToLayer("Holding"), LayerMask.NameToLayer("Releasing")); Invoke("ResetLayerAfterRelease", 0.5f); } if (placePoint != null) { if (placePoint.CanPlace(transform)) { placePoint.Place(this); } if (placePoint.callGrabbableHighlight) { Unhighlight(); } placePoint.StopHighlight(); } } }
public void OnTriggerEnter(Collider other) { if (other.GetComponent <PlacePoint>()) { var otherPoint = other.GetComponent <PlacePoint>(); if (heldBy.Count == 0 && !otherPoint.onlyPlaceWhileHolding) { return; } if (otherPoint == null) { return; } if (placePoint != null && placePoint.GetPlacedObject() != null) { return; } if (placePoint == null) { if (otherPoint.CanPlace(transform)) { placePoint = other.GetComponent <PlacePoint>(); if (placePoint.forcePlace) { if (lastPlacePoint == null || (lastPlacePoint != null && !lastPlacePoint.Equals(placePoint))) { ForceHandsRelease(); placePoint.Place(this); lastPlacePoint = placePoint; } } else { placePoint.Highlight(this); if (placePoint.grabbableHighlight) { Highlight(heldBy[0]); } } } } } }