Exemplo n.º 1
0
        public virtual void GrabStart(DistanceGrabStartInfo grabInfo)
        {
            Grabber = grabInfo.Grabber;

            OriginalLayer = null;

            if (Grabber.GrabbingLayer != null)
            {
                MoveAllObjectsToLayer(Grabber.GrabbingLayer.layerIndex);
            }
        }
        public override void GrabStart(DistanceGrabStartInfo grabStartInfo)
        {
            base.GrabStart(grabStartInfo);

            var target = Grabber.GetTarget();

            _lastGrabberTargetPose.position = target.position;
            _lastGrabberTargetPose.rotation = target.rotation;

            if (Handle)
            {
                _grabOffset = Root.position - Handle.transform.position;
            }
            else
            {
                _grabOffset = Root.position - grabStartInfo.Position;
            }
        }
        void Update()
        {
            if (OVRInput.Get(this.Button, this.Controller))
            {
                // the user is either starting, or continueing a grab

                var target = GetTarget();

                if (CurrentGrabbable != null)
                {
                    // continue grab
                    CurrentGrabbable.GrabUpdate();
                }
                else
                {
                    // check to initiate a grab
                    DistanceGrabbableBase grabbable;

                    Ray        ray = new Ray(this.transform.position, this.transform.forward);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, this.MaxGrabDistance, this.GrabLayerMask))
                    {
                        grabbable = hit.transform.gameObject.GetComponentInParent <DistanceGrabbableBase>();

                        if (grabbable != null && !grabbable.IsGrabbed)
                        {
                            DistanceGrabStartInfo grabInfo = new DistanceGrabStartInfo(this, hit.point);

                            grabbable.GrabStart(grabInfo);

                            this.CurrentGrabbable = grabbable;
                        }
                    }
                }
            }
            else if (CurrentGrabbable != null)
            {
                // release the currently held object
                CurrentGrabbable.GrabEnd();
                CurrentGrabbable = null;
            }
        }