Пример #1
0
        protected void CheckIsAnotherGrabber(GameObject other)
        {
            GrabberBehaviour otherGrabber = other.gameObject.GetComponentInParent <GrabberBehaviour>();

            if (otherGrabber != null && OnNewGrabber != null)
            {
                currentlyHoveredGrabber = otherGrabber;
            }
        }
Пример #2
0
 protected void OnNewRightGrabber(GrabberBehaviour grabber)
 {
     currentRightGrabber.OnNewGrabber -= OnNewRightGrabber;
     if (currentRightGrabber == defaultRightGrabber)
     {
         currentRightGrabber.gameObject.SetActive(false);
     }
     currentRightGrabber = grabber;
     WearGrabber(currentRightGrabber, rightHand, OnNewRightGrabber);
 }
Пример #3
0
 private void OnTriggerExit(Collider other)
 {
     if (currentlyHoveredGrabber != null)
     {
         GrabberBehaviour otherGrabber = other.gameObject.GetComponentInParent <GrabberBehaviour>();
         if (otherGrabber != null && currentlyHoveredGrabber == otherGrabber)
         {
             currentlyHoveredGrabber = null;
         }
     }
 }
Пример #4
0
 private void OnTriggerExit(Collider other)
 {
     if (currentHoverinGrabber != null && state == GrabbableState.hovering)
     {
         GrabberBehaviour otherGrabber = other.gameObject.GetComponentInParent <GrabberBehaviour>();
         if (otherGrabber != null && currentHoverinGrabber == otherGrabber)
         {
             currentHoverinGrabber = null;
             state = GrabbableState.free;
         }
     }
 }
Пример #5
0
 private void OnTriggerStay(Collider other)
 {
     if (state == GrabbableState.free)
     {
         var grabber = other.gameObject.GetComponentInParent <GrabberBehaviour>();
         if (grabber != null)
         {
             state = GrabbableState.hovering;
             currentHoverinGrabber = grabber;
         }
     }
 }
Пример #6
0
        private void Awake()
        {
            VRPlayer                      = new VRPlayer();
            VRPlayer.head                 = head;
            VRPlayer.leftHand             = leftHand;
            VRPlayer.rightHand            = rightHand;
            VRPlayer.cameraSettings       = cameraSettings;
            VRPlayer.network              = new MirrorNetworkInterface(this);
            VRPlayer.leftControllerInput  = new ControllerInput();
            VRPlayer.rightControllerInput = new ControllerInput();

            currentLeftGrabber = defaultLeftGrabber;
            WearGrabber(currentLeftGrabber, leftHand, OnNewLeftGrabber);

            currentRightGrabber = defaultRightGrabber;
            WearGrabber(currentRightGrabber, rightHand, OnNewRightGrabber);
        }
Пример #7
0
        public void Update()
        {
            if (!isLocalPlayer)
            {
                return;
            }

            VRPlayer.Update();
            UpdateInputState(VRPlayer.leftControllerInput, leftButtonsStates);
            UpdateInputState(VRPlayer.rightControllerInput, rightButtonsStates);

            switch (currentLeftGrabber.GetState())
            {
            case GrabberBehaviour.GrabberState.free:
                break;

            case GrabberBehaviour.GrabberState.hovering:
                break;

            case GrabberBehaviour.GrabberState.worn:
                break;

            case GrabberBehaviour.GrabberState.grabbingOtherObject:
                break;

            default:
                break;
            }

            if (leftButtonsStates[ButtonType.Trigger] == ButtonState.Pressed)
            {
                currentLeftGrabber.TryGrab();
            }

            if (leftButtonsStates[ButtonType.Grip] == ButtonState.Pressed)
            {
                switch (currentLeftGrabber.GetState())
                {
                case GrabberBehaviour.GrabberState.worn:
                    if (currentLeftGrabber != defaultLeftGrabber)
                    {
                        currentLeftGrabber.UnWear();
                        currentLeftGrabber = defaultLeftGrabber;
                        WearGrabber(currentLeftGrabber, leftHand, OnNewLeftGrabber);
                    }
                    break;

                case GrabberBehaviour.GrabberState.grabbingOtherObject:
                    currentLeftGrabber.Release();
                    break;

                default:
                    break;
                }
            }

            if (rightButtonsStates[ButtonType.Trigger] == ButtonState.Pressed)
            {
                currentRightGrabber.TryGrab();
            }

            if (rightButtonsStates[ButtonType.Grip] == ButtonState.Pressed)
            {
                switch (currentRightGrabber.GetState())
                {
                case GrabberBehaviour.GrabberState.worn:
                    if (currentRightGrabber != defaultRightGrabber)
                    {
                        currentRightGrabber.UnWear();
                        currentRightGrabber = defaultRightGrabber;
                        WearGrabber(currentRightGrabber, rightHand, OnNewRightGrabber);
                    }
                    break;

                case GrabberBehaviour.GrabberState.grabbingOtherObject:
                    currentRightGrabber.Release();
                    break;

                default:
                    break;
                }
            }
        }
Пример #8
0
 protected static void WearGrabber(GrabberBehaviour grabber, Transform pivot, System.Action <GrabberBehaviour> OnNewGrabber)
 {
     grabber.gameObject.SetActive(true);
     grabber.Wear(pivot);
     grabber.OnNewGrabber += OnNewGrabber;
 }