Esempio n. 1
0
    public bool SetActiveController(SVControllerType activeController)
    {
        if (activeController == SVControllerType.SVController_Left &&
            SVControllerManager.leftControllerActive)
        {
            return(false);
        }

        if (activeController == SVControllerType.SVController_Right &&
            SVControllerManager.rightControllerActive)
        {
            return(false);
        }

        this.activeController = activeController;

#if USES_STEAM_VR
        this.activeControllerDevice = Controller(activeController);
        this.activeRenderModel      = SteamController(this.activeController).GetComponentInChildren <SteamVR_RenderModel>();
#endif

        if (this.activeController == SVControllerType.SVController_Right)
        {
            SVControllerManager.rightControllerActive = true;
        }
        else
        {
            SVControllerManager.leftControllerActive = true;
        }

        return(true);
    }
Esempio n. 2
0
    private bool GetOVRButtonPressDown(SVControllerType controller, SVInputButton button)
    {
        bool isRight = (controller == SVControllerType.SVController_Right);
        Dictionary <int, bool> buttonState = isRight ? this.buttonStateRight : this.buttonStateLeft;

        bool isDown      = GetOVRButtonDown(controller, button);
        bool inputIsDown = buttonState.ContainsKey((int)button) && (bool)buttonState [(int)button];
        bool isPressDown = (!inputIsDown && isDown);

        buttonState [(int)button] = isDown;
        return(isPressDown);
    }
Esempio n. 3
0
    public Quaternion RotationForController(SVControllerType controller)
    {
        if (controller == SVControllerType.SVController_Left)
        {
            return(LeftControllerRotation);
        }
        else if (controller == SVControllerType.SVController_Right)
        {
            return(RightControllerRotation);
        }

        return(Quaternion.identity);
    }
Esempio n. 4
0
    //------------------------
    // Controller Info
    //------------------------
    public Vector3 PositionForController(SVControllerType controller)
    {
        if (controller == SVControllerType.SVController_Left)
        {
            return(LeftControllerPosition);
        }
        else if (controller == SVControllerType.SVController_Right)
        {
            return(RightControllerPosition);
        }

        return(Vector3.zero);
    }
Esempio n. 5
0
    public bool ControllerIsConnected(SVControllerType controller)
    {
        if (controller == SVControllerType.SVController_Left)
        {
            return(LeftControllerIsConnected);
        }
        else if (controller == SVControllerType.SVController_Right)
        {
            return(RightControllerIsConnected);
        }

        return(false);
    }
Esempio n. 6
0
    public bool GetButtonPressDown(SVControllerType controller, SVInputButton button)
    {
        if (button == SVInputButton.SVButton_None || !ControllerIsConnected(controller))
        {
            return(false);
        }

#if USES_STEAM_VR
        return(Controller(controller).GetPressDown(GetSteamButtonMapping(button)));
#elif USES_OPEN_VR
        return(GetOVRButtonPressDown(controller, button));
#else
        return(false);
#endif
    }
Esempio n. 7
0
    public void ClearActiveController()
    {
#if USES_STEAM_VR
        this.activeControllerDevice = null;
        this.activeRenderModel      = null;
#endif

        if (this.activeController == SVControllerType.SVController_Right)
        {
            SVControllerManager.rightControllerActive = false;
        }
        else
        {
            SVControllerManager.leftControllerActive = false;
        }

        this.activeController = SVControllerType.SVController_None;
    }
Esempio n. 8
0
    //------------------------
    // State Changes
    //------------------------
    private void TrySetActiveController(SVControllerType controller)
    {
        if (this.input.activeController != SVControllerType.SVController_None ||
            controller == SVControllerType.SVController_None)
        {
            return;
        }

        if (input.gripAutoHolds)
        {
            if (!input.GetGripButtonPressed(controller))
            {
                return;
            }
        }
        else
        {
            if (!input.GetGripButtonDown(controller))
            {
                return;
            }
        }

        if (this.input.SetActiveController(controller))
        {
            this.grabStartTime             = Time.time;
            this.grabStartPosition         = this.gameObject.transform.position;
            this.grabStartRotation         = this.gameObject.transform.rotation;
            outlineComponent.outlineActive = 0;

            Rigidbody rigidbody = this.GetComponent <Rigidbody> ();
            rigidbody.isKinematic = true;

            // hide the controller model
            this.input.HideActiveModel();
        }
    }
Esempio n. 9
0
 //------------------------
 // Getters
 //------------------------
     #if USES_STEAM_VR
 private GameObject SteamController(SVControllerType type)
 {
     return(type == SVControllerType.SVController_Left ? controllerManager.left : controllerManager.right);          //TODO : Cache this component for performance
 }
Esempio n. 10
0
    private void UngrabbedUpdate()
    {
        this.inHand = false;

        // Reset our knockable state after dropping this bad boy
        if (grabData.recentlyReleased && (Time.time - grabData.grabEndTime) > kGrabResetTime)
        {
            grabData.recentlyReleased = false;
            grabData.recentlyDropped  = false;
            this.isKnockable          = grabData.wasKnockable;
        }

        // If we drop something, give it a little cooldown so it can drop to the floor before we snag it.
        if (grabData.recentlyDropped)
        {
            return;
        }

        float distanceToLeftHand = 1000;

        if (input.LeftControllerIsConnected)
        {
            distanceToLeftHand = (this.transform.position - input.LeftControllerPosition).magnitude;
        }

        float distanceToRightHand = 1000;

        if (input.RightControllerIsConnected)
        {
            distanceToRightHand = (this.transform.position - input.RightControllerPosition).magnitude;
        }

        // Within grabbing distance?
        if (grabFlyDistance > distanceToLeftHand ||
            grabFlyDistance > distanceToRightHand)
        {
            float distance = Mathf.Min(distanceToLeftHand, distanceToRightHand);
            if (this.gripIndicatorComponent)
            {
                float distanceForHighlight = grabFlyDistance / 4f;
                float highlight            = Mathf.Max(0, Mathf.Min(1, (grabFlyDistance - distance) / distanceForHighlight));
                gripIndicatorComponent.indicatorActive = highlight;
            }

            // order them based on distance
            SVControllerType firstController  = SVControllerType.SVController_None;
            SVControllerType secondController = SVControllerType.SVController_None;

            if (distanceToLeftHand < distanceToRightHand)
            {
                if (SVControllerManager.nearestGrabbableToLeftController == this)
                {
                    firstController = SVControllerType.SVController_Left;
                }

                if (SVControllerManager.nearestGrabbableToRightController == this)
                {
                    secondController = SVControllerType.SVController_Right;
                }
            }
            else
            {
                if (SVControllerManager.nearestGrabbableToRightController == this)
                {
                    firstController = SVControllerType.SVController_Right;
                }

                if (SVControllerManager.nearestGrabbableToLeftController == this)
                {
                    secondController = SVControllerType.SVController_Left;
                }
            }

            TrySetActiveController(firstController);
            TrySetActiveController(secondController);

            // Update grabbable distance so we always grab the nearest object
            if (distanceToLeftHand < SVControllerManager.distanceToLeftController ||
                SVControllerManager.nearestGrabbableToLeftController == null ||
                SVControllerManager.nearestGrabbableToLeftController == this)
            {
                SVControllerManager.nearestGrabbableToLeftController = this;
                SVControllerManager.distanceToLeftController         = distanceToLeftHand;
            }

            if (distanceToRightHand < SVControllerManager.distanceToRightController ||
                SVControllerManager.nearestGrabbableToRightController == null ||
                SVControllerManager.nearestGrabbableToRightController == this)
            {
                SVControllerManager.nearestGrabbableToRightController = this;
                SVControllerManager.distanceToRightController         = distanceToRightHand;
            }
        }
        else
        {
            if (this.gripIndicatorComponent)
            {
                gripIndicatorComponent.indicatorActive = 0;
            }
            // Clear our object as nearest if it's not in grabbin range!
            if (SVControllerManager.nearestGrabbableToRightController == this)
            {
                SVControllerManager.nearestGrabbableToRightController = null;
            }
            if (SVControllerManager.nearestGrabbableToLeftController == this)
            {
                SVControllerManager.nearestGrabbableToLeftController = null;
            }
        }
    }
Esempio n. 11
0
    private bool GetOVRButtonDown(SVControllerType controller, SVInputButton button)
    {
        bool isRight = (controller == SVControllerType.SVController_Right);

        OVRInput.Controller ovrController = (isRight ? OVRInput.Controller.RTouch : OVRInput.Controller.LTouch);

        switch (button)
        {
        // Buttons
        case SVInputButton.SVButton_A:
        case SVInputButton.SVButton_B:
        case SVInputButton.SVButton_System:
        case SVInputButton.SVButton_Thumbstick_Press:
            return(OVRInput.Get(GetOVRButtonMapping(button), ovrController));

        // 2D Axis
        case SVInputButton.SVButton_Thumbstick_Down:
        case SVInputButton.SVButton_Thumbstick_Left:
        case SVInputButton.SVButton_Thumbstick_Right:
        case SVInputButton.SVButton_Thumbstick_Up:
        {
            OVRInput.Axis2D axis2D = OVRInput.Axis2D.PrimaryThumbstick;

            Vector2 vec = OVRInput.Get(axis2D, ovrController);

            if (button == SVInputButton.SVButton_Thumbstick_Down)
            {
                return(vec.y < -0.75);
            }
            else if (button == SVInputButton.SVButton_Thumbstick_Up)
            {
                return(vec.y > 0.75);
            }
            else if (button == SVInputButton.SVButton_Thumbstick_Left)
            {
                return(vec.x < -0.75);
            }
            else if (button == SVInputButton.SVButton_Thumbstick_Right)
            {
                return(vec.x > 0.75);
            }
            return(false);
        }

        // 1D Axis
        case SVInputButton.SVButton_Trigger:
        case SVInputButton.SVButton_Grip:
        {
            OVRInput.Axis1D axis = OVRInput.Axis1D.PrimaryIndexTrigger;
            if (button == SVInputButton.SVButton_Trigger)
            {
                axis = OVRInput.Axis1D.PrimaryIndexTrigger;
            }
            else if (button == SVInputButton.SVButton_Grip)
            {
                axis = OVRInput.Axis1D.PrimaryHandTrigger;
            }
            return(OVRInput.Get(axis, ovrController) > 0.75f);
        }

        default:
            return(false);
        }
    }
 public bool GetTriggerButtonPressed(SVControllerType controller)
 {
     return(this.GetButtonPressDown(controller, this.triggerButton));
 }
Esempio n. 13
0
    //------------------------
    // State Changes
    //------------------------
    private void TrySetActiveController(SVControllerType controller)
    {
        if (this.input.activeController != SVControllerType.SVController_None ||
            controller == SVControllerType.SVController_None)
        {
            return;
        }

        if (input.gripAutoHolds)
        {
            if (!input.GetGripButtonPressed(controller))
            {
                return;
            }
        }
        else
        {
            if (!input.GetGripButtonDown(controller))
            {
                return;
            }
        }

        if (this.input.SetActiveController(controller))
        {
            this.grabData.grabStartTime          = Time.time;
            this.grabData.grabStartPosition      = this.gameObject.transform.position;
            this.grabData.grabStartWorldRotation = this.gameObject.transform.rotation;
            this.grabData.grabStartLocalRotation = Quaternion.Inverse(this.input.RotationForController(controller)) * this.grabData.grabStartWorldRotation;
            this.grabData.hasJoint = (this.gameObject.GetComponent <Joint>() != null);
            if (this.gripIndicatorComponent)
            {
                gripIndicatorComponent.indicatorActive = 0;
            }

            // Update our rigidbody to respect being controlled by the player
            grabData.wasKinematic   = rb.isKinematic;
            grabData.didHaveGravity = rb.useGravity;
            if (this.ignorePhysicsInHand)
            {
                rb.isKinematic = true;
                foreach (Collider collider in this.colliders)
                {
                    collider.enabled = false;
                }
            }
            else
            {
                rb.useGravity = false;
            }

            if (!grabData.recentlyReleased)
            {
                grabData.wasKnockable = this.isKnockable;
                this.isKnockable      = false;
            }

            // hide the controller model
            this.input.HideActiveModel();
        }
    }
 public bool GetCloseBarrelPressed(SVControllerType controller)
 {
     return(this.GetButtonPressDown(controller, this.closeBarrelButton));
 }
Esempio n. 15
0
 public bool GetReleaseGripButtonPressed(SVControllerType controller)
 {
     return(this.GetButtonPressDown(controller, this.releaseGripButton));
 }
Esempio n. 16
0
    //------------------------
    // Input Checkers
    //------------------------

    public bool GetGripButtonDown(SVControllerType controller)
    {
        return(this.GetButtonDown(controller, this.gripButton));
    }
Esempio n. 17
0
    private void UngrabbedUpdate()
    {
        this.inHand = false;

        float distanceToLeftHand = 1000;

        if (input.LeftControllerIsConnected)
        {
            distanceToLeftHand = (this.transform.position - input.LeftControllerPosition).magnitude;
        }

        float distanceToRightHand = 1000;

        if (input.RightControllerIsConnected)
        {
            distanceToRightHand = (this.transform.position - input.RightControllerPosition).magnitude;
        }

        if (grabDistance > distanceToLeftHand ||
            grabDistance > distanceToRightHand)
        {
            float distance = Mathf.Min(distanceToLeftHand, distanceToRightHand);
            if (this.outlineComponent)
            {
                float distanceForHighlight = grabDistance / 4f;
                float highlight            = Mathf.Max(0, Mathf.Min(1, (grabDistance - distance) / distanceForHighlight));
                outlineComponent.outlineActive = highlight;
            }

            // order them based on distance
            SVControllerType firstController  = SVControllerType.SVController_None;
            SVControllerType secondController = SVControllerType.SVController_None;

            if (distanceToLeftHand < distanceToRightHand)
            {
                if (SVControllerManager.nearestGrabbableToLeftController == this)
                {
                    firstController = SVControllerType.SVController_Left;
                }

                if (SVControllerManager.nearestGrabbableToRightController == this)
                {
                    secondController = SVControllerType.SVController_Right;
                }
            }
            else
            {
                if (SVControllerManager.nearestGrabbableToRightController == this)
                {
                    firstController = SVControllerType.SVController_Right;
                }

                if (SVControllerManager.nearestGrabbableToLeftController == this)
                {
                    secondController = SVControllerType.SVController_Left;
                }
            }

            TrySetActiveController(firstController);
            TrySetActiveController(secondController);

            // Update grabbable distance so we always grab the nearest revolver
            if (distanceToLeftHand < SVControllerManager.distanceToLeftController ||
                SVControllerManager.nearestGrabbableToLeftController == null ||
                SVControllerManager.nearestGrabbableToLeftController == this)
            {
                SVControllerManager.nearestGrabbableToLeftController = this;
                SVControllerManager.distanceToLeftController         = distanceToLeftHand;
            }

            if (distanceToRightHand < SVControllerManager.distanceToRightController ||
                SVControllerManager.nearestGrabbableToRightController == null ||
                SVControllerManager.nearestGrabbableToRightController == this)
            {
                SVControllerManager.nearestGrabbableToRightController = this;
                SVControllerManager.distanceToRightController         = distanceToRightHand;
            }
        }
        else
        {
            outlineComponent.outlineActive = 0;
        }
    }
Esempio n. 18
0
    private SteamVR_Controller.Device Controller(SVControllerType type)
    {
        GameObject steamController = (type == SVControllerType.SVController_Left ? controllerManager.left : controllerManager.right);         //TODO : Cache this component for performance

        return(SteamVR_Controller.Input((int)steamController.GetComponent <SteamVR_TrackedObject>().index));
    }