Esempio n. 1
0
        /// <summary>Called by the hand whenever this item is grabbed</summary>
        public virtual void OnGrab(Hand hand)
        {
            placePoint?.Remove(this);
            placePoint = null;
            if (lockHandOnGrab)
            {
                hand.GetComponent <Rigidbody>().isKinematic = true;
            }

            body.interpolation = RigidbodyInterpolation.Interpolate;
            if (!body.isKinematic)
            {
                body.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            }
            else
            {
                body.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
            }

            if (parentOnGrab)
            {
                body.transform.parent = hand.transform.parent;
            }
            heldBy?.Add(hand);
            throwing  = false;
            beingHeld = true;
            onGrab?.Invoke();

            OnGrabEvent?.Invoke(hand, this);
        }
Esempio n. 2
0
        /// <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();
                }
            }
        }
Esempio n. 3
0
        /// <summary>Called by the hand whenever this item is grabbed</summary>
        public virtual void OnGrab(Hand hand)
        {
            if (lockHandOnGrab)
            {
                hand.GetComponent <Rigidbody>().isKinematic = true;
            }

            if (parentOnGrab)
            {
                body.transform.parent = hand.transform.parent;
            }
            heldBy?.Add(hand);
            throwing  = false;
            beingHeld = true;
            ContinuousCollisionDetection();
            gameObject.layer = LayerMask.NameToLayer("Holding");
            onGrab?.Invoke();
            if (placePoint != null)
            {
                placePoint.Remove(this);
            }

            OnGrabEvent?.Invoke(hand, this);
        }