Example #1
0
        public override void Grabbed(GameObject currentGrabbingObject)
        {
            base.Grabbed(currentGrabbingObject);

            controllerEvents = currentGrabbingObject.GetComponent<VRTK_ControllerEvents>();
            controllerActions = currentGrabbingObject.GetComponent<VRTK_ControllerActions>();

            ToggleSlide(true);
            ToggleSafetySwitch(true);

            //Limit hands grabbing when picked up
            if (VRTK_DeviceFinder.GetControllerHand(currentGrabbingObject) == VRTK_DeviceFinder.ControllerHand.Left)
            {
                allowedTouchControllers = AllowedController.Left_Only;
                allowedUseControllers = AllowedController.Left_Only;
                slide.allowedGrabControllers = AllowedController.Right_Only;
                safetySwitch.allowedGrabControllers = AllowedController.Right_Only;
            }
            else if (VRTK_DeviceFinder.GetControllerHand(currentGrabbingObject) == VRTK_DeviceFinder.ControllerHand.Right)
            {
                allowedTouchControllers = AllowedController.Right_Only;
                allowedUseControllers = AllowedController.Right_Only;
                slide.allowedGrabControllers = AllowedController.Left_Only;
                safetySwitch.allowedGrabControllers = AllowedController.Left_Only;
            }
        }
Example #2
0
        public override void Ungrabbed(GameObject previousGrabbingObject)
        {
            base.Ungrabbed(previousGrabbingObject);

            ToggleSlide(false);
            ToggleSafetySwitch(false);

            //Unlimit hands
            allowedTouchControllers = AllowedController.Both;
            allowedUseControllers = AllowedController.Both;
            slide.allowedGrabControllers = AllowedController.Both;
            safetySwitch.allowedGrabControllers = AllowedController.Both;

            controllerEvents = null;
            controllerActions = null;
        }
Example #3
0
        private void DoObjectGrab(object sender, InteractableObjectEventArgs e)
        {
            if (VRTK_SDK_Bridge.IsControllerLeftHand(e.interactingObject))
            {
                holdControl = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent<VRTK_ControllerEvents>();
                stringControl = VRTK_DeviceFinder.GetControllerRightHand().GetComponent<VRTK_ControllerEvents>();

                holdActions = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent<VRTK_ControllerActions>();
                stringActions = VRTK_DeviceFinder.GetControllerRightHand().GetComponent<VRTK_ControllerActions>();
            }
            else
            {
                stringControl = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent<VRTK_ControllerEvents>();
                holdControl = VRTK_DeviceFinder.GetControllerRightHand().GetComponent<VRTK_ControllerEvents>();

                stringActions = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent<VRTK_ControllerActions>();
                holdActions = VRTK_DeviceFinder.GetControllerRightHand().GetComponent<VRTK_ControllerActions>();
            }
            StartCoroutine("GetBaseRotation");
        }
Example #4
0
 public override void Grabbed(GameObject grabbingObject)
 {
     base.Grabbed(grabbingObject);
     controllerActions = grabbingObject.GetComponent<VRTK_ControllerActions>();
     controllerEvents = grabbingObject.GetComponent<VRTK_ControllerEvents>();
 }
 public override void StopUsing(GameObject previousUsingObject)
 {
     base.StopUsing(previousUsingObject);
     controllerEvents = null;
     controllerActions = null;
 }
 public override void StartUsing(GameObject usingObject)
 {
     base.StartUsing(usingObject);
     controllerEvents = usingObject.GetComponent<VRTK_ControllerEvents>();
     controllerActions = usingObject.GetComponent<VRTK_ControllerActions>();
 }
Example #7
0
    public override void Grabbed(GameObject grabbingObject)
    {
        VRTK_InteractGrab      grabScript        = grabbingObject.GetComponent <VRTK_InteractGrab>();
        VRTK_InteractTouch     touchScript       = grabbingObject.GetComponent <VRTK_InteractTouch>();
        VRTK_ControllerActions controllerActions = grabbingObject.GetComponent <VRTK_ControllerActions>();

        grabScript.ForceRelease();

        bool isRightController = grabbingObject.name.Contains("right");

        if (!alwaysUseSlider && (alwaysUseStatic || attachPtCount >= staticAttachPtCount))
        {
            //print("making static joint");
            staticAttachPtCount++;


            GameObject zbAttachPoint = Instantiate(StaticAttachPoint_PF);
            GameObject attachPoint   = zbAttachPoint.transform.GetChild(0).gameObject;

            foreach (ZB_PaddleBlade paddle in paddleBlades)
            {
                if (alwaysUseSlider)
                {
                    paddle.mainControlActions = controllerActions;
                }
                else
                {
                    paddle.secondaryControlActions = controllerActions;
                    paddle.ForcePoint = attachPoint.gameObject;
                }
            }

            ZB_AttachPoint attachPointScript = attachPoint.GetComponent <ZB_AttachPoint>();

            Transform spawnPoint = (grabScript && grabScript.controllerAttachPoint) ? grabScript.controllerAttachPoint.transform: grabbingObject.transform;
            //Transform spawnPoint = grabbingObject.transform.GetChild(0).transform.GetChild(1).GetChild(0).transform;

            if (isRightController)
            {
                rightSnapHandle = attachPoint.transform.GetChild(0).transform;
            }
            else
            {
                leftSnapHandle = attachPoint.transform.GetChild(0).transform;
            }

            attachPointScript.spawningObj = this;

            touchScript.ForceStopTouching();
            touchScript.ForceTouch(attachPoint.gameObject);

            zbAttachPoint.transform.position = spawnPoint.position;
            zbAttachPoint.transform.rotation = transform.rotation;
            float   attachPtLocalY = transform.InverseTransformPoint(zbAttachPoint.transform.position).y;
            Vector3 zeroPos        = transform.TransformPoint(new Vector3(0f, attachPtLocalY, 0f));
            zbAttachPoint.transform.position = zeroPos;

            ConfigurableJoint attachPtJoint = attachPoint.GetComponent <ConfigurableJoint>();

            //sliderJoint.connectedBody = rBody;

            attachPtJoint.connectedBody = rBody;
            SetStaticAttachPointJointRestraints(ref attachPtJoint);

            attachPtJoint.connectedBody = rBody;

            grabScript.AttemptGrab();

            if (isRightController)
            {
                rightControlLocalY = attachPtLocalY;
                currRightControl   = grabbingObject;
                if (alwaysUseSlider)
                {
                    rightRotateTrack.follow = true;
                }
                attachPointScript.isRightController = true;
                currRightAttachPt = attachPointScript.gameObject;
            }
            else
            {
                leftControlLocalY = attachPtLocalY;
                currLeftControl   = grabbingObject;
                if (alwaysUseSlider)
                {
                    leftRotateTrack.follow = true;
                }
                attachPointScript.isRightController = false;
                currLeftAttachPt = attachPointScript.gameObject;
            }
        }
        else
        {
            //print("making slider joint");
            attachPtCount++;

            foreach (ZB_PaddleBlade paddleBlade in paddleBlades)
            {
                paddleBlade.mainControlActions = controllerActions;
            }

            GameObject     zbAttachPoint     = Instantiate(AttachPoint_PF);
            GameObject     attachPoint       = zbAttachPoint.transform.GetChild(0).gameObject;
            GameObject     slider            = zbAttachPoint.transform.GetChild(1).gameObject;
            ZB_AttachPoint attachPointScript = attachPoint.GetComponent <ZB_AttachPoint>();

            Transform spawnPoint = (grabScript && grabScript.controllerAttachPoint) ? grabScript.controllerAttachPoint.transform : grabbingObject.transform;

            if (isRightController)
            {
                rightSnapHandle = attachPoint.transform.GetChild(0).transform;
            }
            else
            {
                leftSnapHandle = attachPoint.transform.GetChild(0).transform;
            }

            attachPointScript.spawningObj = this;

            touchScript.ForceStopTouching();
            touchScript.ForceTouch(attachPoint.gameObject);

            zbAttachPoint.transform.position = spawnPoint.position;
            zbAttachPoint.transform.rotation = transform.rotation;
            float   attachPtLocalY = transform.InverseTransformPoint(zbAttachPoint.transform.position).y;
            Vector3 zeroPos        = transform.TransformPoint(new Vector3(0f, attachPtLocalY, 0f));
            zbAttachPoint.transform.position = zeroPos;

            ConfigurableJoint sliderJoint   = slider.GetComponent <ConfigurableJoint>();
            ConfigurableJoint attachPtJoint = attachPoint.GetComponent <ConfigurableJoint>();

            attachPtJoint.connectedBody = rBody;
            SetStaticAttachPointJointRestraints(ref attachPtJoint);
            SetSliderJointRestraints(ref sliderJoint);

            attachPtJoint.connectedBody = rBody;
            sliderJoint.connectedBody   = rBody;

            grabScript.AttemptGrab();

            if (isRightController)
            {
                rightControlLocalY = attachPtLocalY;
                currRightControl   = grabbingObject;

                rightRotateTrack.follow = true;


                attachPointScript.isRightController = true;
                currRightAttachPt = attachPointScript.gameObject;
            }
            else
            {
                leftControlLocalY      = attachPtLocalY;
                currLeftControl        = grabbingObject;
                leftRotateTrack.follow = false;

                attachPointScript.isRightController = false;
                currLeftAttachPt = attachPointScript.gameObject;
            }

            StartCoroutine(DelayedJointConnect(attachPtJoint, slider.GetComponent <Rigidbody>()));
        }
    }
Example #8
0
 private void Awake()
 {
     trackedController = GetComponent <SteamVR_TrackedObject>();
     controllerActions = GetComponent <VRTK_ControllerActions>();
 }
 void OnTriggerEnter(Collider coll)
 {
     controllerActions = coll.GetComponentInParent <VRTK_ControllerActions> ();
     controllerActions.TriggerHapticPulse(1.0f);
 }
Example #10
0
 public override void Grabbed(GameObject grabbingObject)
 {
     base.Grabbed(grabbingObject);
     controllerActions = grabbingObject.GetComponent <VRTK_ControllerActions>();
 }
        private void Start()
        {
            if (GetComponent<VRTK_ControllerEvents>() == null)
            {
                Debug.LogError("VRTK_ControllerEvents_ListenerExample is required to be attached to a Controller that has the VRTK_ControllerEvents script attached to it");
                return;
            }

            events = GetComponent<VRTK_ControllerEvents>();
            actions = GetComponent<VRTK_ControllerActions>();
            tooltips = GetComponentInChildren<VRTK_ControllerTooltips>();

            //Setup controller event listeners
            events.TriggerPressed += new ControllerInteractionEventHandler(DoTriggerPressed);
            events.TriggerReleased += new ControllerInteractionEventHandler(DoTriggerReleased);

            events.ApplicationMenuPressed += new ControllerInteractionEventHandler(DoApplicationMenuPressed);
            events.ApplicationMenuReleased += new ControllerInteractionEventHandler(DoApplicationMenuReleased);

            events.GripPressed += new ControllerInteractionEventHandler(DoGripPressed);
            events.GripReleased += new ControllerInteractionEventHandler(DoGripReleased);

            events.TouchpadPressed += new ControllerInteractionEventHandler(DoTouchpadPressed);
            events.TouchpadReleased += new ControllerInteractionEventHandler(DoTouchpadReleased);

            tooltips.ToggleTips(false);
        }