Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        rot = this.transform.localEulerAngles;
        pos = this.transform.position;
        if (offsetCompensation && offset)
        {
            pos = VectorHelper.RotatePointAroundPivot(pos, offset.position, -offset.eulerAngles.y * Vector3.up);
            pos = VectorHelper.RotatePointAroundPivot(pos, offset.position, -offset.eulerAngles.x * Vector3.right);
            pos = VectorHelper.RotatePointAroundPivot(pos, offset.position, -offset.eulerAngles.z * Vector3.forward);

            pos -= offset.position;
        }
        VRSimulatorInputInterface.SetControllerTransform(left, pos, Quaternion.Euler(rot));
    }
Ejemplo n.º 2
0
    //Function: InitInputSystem
    //Initializes the required input actions found in <inputActions> and sets event callbacks.
#if USE_INPUT_SYSTEM
    void InitInputSystem()
    {
        inputActions.Enable();
        inputActions.FindActionMap("Rig").FindAction("Look").started                    += context => { looking = true; };
        inputActions.FindActionMap("Rig").FindAction("Look").canceled                   += context => { looking = false; };
        inputActions.FindActionMap("Rig").FindAction("Move").started                    += context => { moving = true; };
        inputActions.FindActionMap("Rig").FindAction("Move").canceled                   += context => { moving = false; };
        inputActions.FindActionMap("Controller").FindAction("Move").started             += context => { controllerMoving = true; };
        inputActions.FindActionMap("Controller").FindAction("Move").canceled            += context => { controllerMoving = false; };
        inputActions.FindActionMap("Controller").FindAction("ToggleRotation").performed += context => { toggleRotation = !toggleRotation; };
        inputActions.FindActionMap("Controller").FindAction("Reset").performed          += context => { simulator.ResetControllers(); };

        inputActions.FindActionMap("Controller").FindAction("SwitchController").performed += context => {
            switchController     = !switchController;
            simulator.switchHand = switchController;
        };

        inputActions.FindActionMap("Controller").FindAction("ToggleController").performed += context => {
            controllersActive     = !controllersActive;
            simulator.handsActive = controllersActive;
        };

        inputActions.FindActionMap("Controller").FindAction("SwitchAxis").started += context => {
            switchAxis = true;
            simulator.switchHandAxis = switchAxis;
        };

        inputActions.FindActionMap("Controller").FindAction("SwitchAxis").canceled += context => {
            switchAxis = false;
            simulator.switchHandAxis = switchAxis;
        };

        inputActions.FindActionMap("XRInput").FindAction("Trigger").started  += context => { VRSimulatorInputInterface.SetTriggerState(switchController, true); };
        inputActions.FindActionMap("XRInput").FindAction("Trigger").canceled += context => { VRSimulatorInputInterface.SetTriggerState(switchController, false); };

        inputActions.FindActionMap("XRInput").FindAction("Grip").started  += context => { VRSimulatorInputInterface.SetGripState(switchController, true); };
        inputActions.FindActionMap("XRInput").FindAction("Grip").canceled += context => { VRSimulatorInputInterface.SetGripState(switchController, false); };

        inputActions.FindActionMap("XRInput").FindAction("PrimaryButton").started  += context => { VRSimulatorInputInterface.SetPrimaryState(switchController, true); };
        inputActions.FindActionMap("XRInput").FindAction("PrimaryButton").canceled += context => { VRSimulatorInputInterface.SetPrimaryState(switchController, false); };

        inputActions.FindActionMap("XRInput").FindAction("SecondaryButton").started  += context => { VRSimulatorInputInterface.SetSecondaryState(switchController, true); };
        inputActions.FindActionMap("XRInput").FindAction("SecondaryButton").canceled += context => { VRSimulatorInputInterface.SetSecondaryState(switchController, false); };

        inputActions.FindActionMap("XRInput").FindAction("Stick").started  += context => { stickActive = true; };
        inputActions.FindActionMap("XRInput").FindAction("Stick").canceled += context => {
            stickActive = false;
            VRSimulatorInputInterface.SetPrimary2D(switchController, Vector2.zero);
        };
    }
Ejemplo n.º 3
0
    //Function: UpdateInteraction
    //Update function for handling controller interaction input (buttons etc.).
    void UpdateInteraction()
    {
#if USE_INPUT_SYSTEM
        if (stickActive)
        {
            VRSimulatorInputInterface.SetPrimary2D(switchController, inputActions.FindActionMap("XRInput").FindAction("Stick").ReadValue <Vector2>());
        }
        //others handled directly with events
#elif ENABLE_LEGACY_INPUT_MANAGER
        #region
        if (Input.GetKeyDown(assignedKeys.interactionKeys.grip))
        {
            VRSimulatorInputInterface.SetGripState(switchController, true);
        }
        else if (Input.GetKeyUp(assignedKeys.interactionKeys.grip))
        {
            VRSimulatorInputInterface.SetGripState(switchController, false);
        }

        if (Input.GetKeyDown(assignedKeys.interactionKeys.trigger))
        {
            VRSimulatorInputInterface.SetTriggerState(switchController, true);
        }
        else if (Input.GetKeyUp(assignedKeys.interactionKeys.trigger))
        {
            VRSimulatorInputInterface.SetTriggerState(switchController, false);
        }

        if (Input.GetKeyDown(assignedKeys.interactionKeys.primaryButton))
        {
            VRSimulatorInputInterface.SetPrimaryState(switchController, true);
        }
        else if (Input.GetKeyUp(assignedKeys.interactionKeys.primaryButton))
        {
            VRSimulatorInputInterface.SetPrimaryState(switchController, false);
        }

        if (Input.GetKeyDown(assignedKeys.interactionKeys.secondaryButton))
        {
            VRSimulatorInputInterface.SetSecondaryState(switchController, true);
        }
        else if (Input.GetKeyUp(assignedKeys.interactionKeys.secondaryButton))
        {
            VRSimulatorInputInterface.SetSecondaryState(switchController, false);
        }

        Vector2 stickValue = Vector2.zero;
        if (Input.GetKey(assignedKeys.interactionKeys.stickUp))
        {
            stickValue.y += 1;
        }

        if (Input.GetKey(assignedKeys.interactionKeys.stickDown))
        {
            stickValue.y -= 1;
        }

        if (Input.GetKey(assignedKeys.interactionKeys.stickRight))
        {
            stickValue.x += 1;
        }

        if (Input.GetKey(assignedKeys.interactionKeys.stickLeft))
        {
            stickValue.x -= 1;
        }

        VRSimulatorInputInterface.SetPrimary2D(switchController, stickValue.normalized);

        #endregion
#endif
    }