예제 #1
0
        private void UpdateGrabbableHighlight()
        {
            // TODO: NOT WORKING
            var closest = GetClosestGrabbable();

            if (closest != null && (closest.grabbedBy != null || !IsInSight(closest)))
            {
                if (previousClosest != null)
                {
                    previousClosest.onDeselected.Invoke();
                    previousClosest = null;
                }

                return;
            }

            if (previousClosest != null)
            {
                Debug.Log("Deselected");
                previousClosest.onDeselected.Invoke();
                previousClosest = null;
            }

            if (previousClosest != closest)
            {
                Debug.Log("Selected");
                closest.onSelected.Invoke();
                previousClosest = closest;
            }
        }
예제 #2
0
        private void UpdateMoving(Grabbable grabbable)
        {
            var grabbablePosition = grabbable.transform.position;
            var position          = transform.position;

            if (IsMove(grabbable, position))
            {
                MoveGrabbableTo(grabbable, grabbablePosition, position);
            }
            else
            {
                HandleMovingEnd(grabbable);
            }
        }
예제 #3
0
        private void HandleMovingEnd(Grabbable grabbable)
        {
            var joint = gameObject.AddComponent <FixedJoint>();

            joint.connectedBody = grabbable.Body;
            joint.breakForce    = breakForce;

            grabbable.Body.isKinematic = false;

            grabbed.Moving = false;
            grabbed.Joint  = joint;

            onGrab.Invoke(grabbable);
        }
예제 #4
0
        private void HandleMovingStart(Grabbable grabbable)
        {
            var otherGrabber = grabbable.grabbedBy;

            if (otherGrabber != null)
            {
                otherGrabber.Release();
            }

            grabbable.grabbedBy        = this;
            grabbable.Body.isKinematic = true;

            grabbed = new GrabbedGrabbable(
                grabbable: grabbable,
                moving: true
                );

            if (IsMove(grabbable, transform.position))
            {
                onMove.Invoke(grabbable);
            }
        }
예제 #5
0
 public GrabbedGrabbable(Grabbable grabbable, bool moving)
 {
     Grabbable = grabbable;
     Moving    = moving;
 }
예제 #6
0
        private bool IsMove(Grabbable grabbable, Vector3 to)
        {
            var from = grabbable.Body.ClosestPointOnBounds(to);

            return(Vector3.Distance(from, to) > grabbedRadius);
        }
예제 #7
0
        private void MoveGrabbableTo(Grabbable grabbable, Vector3 from, Vector3 to)
        {
            var newPosition = Vector3.MoveTowards(from, to, Time.deltaTime * grabSpeed);

            grabbable.Body.MovePosition(newPosition);
        }