Пример #1
0
 // Updates button states from Web gamepad API.
 //instead we should just fire our buttons, right?
 private void UpdateButtons(WebVRControllerButton[] buttons)
 {
     for (int i = 0; i < buttons.Length; i++)
     {
         WebVRControllerButton button = buttons[i];
         foreach (WebVRControllerInput input in inputMap.inputs)
         {
             if (input.gamepadId == i)
             {
                 //SetButtonState(input.actionName, button.pressed, button.value);
                 //why not just do stuff here?
                 if (input.PreviousState != button.pressed)
                 {
                     //something has changed!
                     if (button.pressed)
                     {
                         //this means we were NOT PRESSED and now we are!
                         //this is DOWN
                         input.PreviousState = button.pressed;
                         input.OnDown.Invoke();
                     }
                     else
                     {
                         //this means we were PRESSED now we are NOT
                         //this is UP
                         input.PreviousState = button.pressed;
                         input.OnUp.Invoke();
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 // Updates button states from Web gamepad API.
 private void UpdateButtons(WebVRControllerButton[] buttons)
 {
     for (int i = 0; i < buttons.Length; i++)
     {
         WebVRControllerButton button = buttons[i];
         foreach (WebVRControllerInput input in inputMap.inputs)
         {
             if (input.gamepadId == i)
             {
                 SetButtonState(input.actionName, button.pressed, button.value);
             }
         }
     }
 }
    void Update()
    {
                #if UNITY_EDITOR
        // update controllers using Unity XR support when in editor.
        WebVRControllerButton[] buttons = new WebVRControllerButton[0];
        onControllerUpdate(
            0,
            "left",
            UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.LeftHand),
            UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.LeftHand),
            Matrix4x4.identity, buttons);

        onControllerUpdate(
            1,
            "right",
            UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.RightHand),
            UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.RightHand),
            Matrix4x4.identity, buttons);
                #endif
    }
Пример #4
0
 public void UpdateButtons(WebVRControllerButton[] buttons)
 {
     for (int i = 0; i < buttons.Length; i++)
     {
         WebVRControllerButton button = buttons[i];
         foreach (WebVRInputAction action in Enum.GetValues(typeof(WebVRInputAction)))
         {
             if (i == (int)action)
             {
                 if (buttonStates.ContainsKey(action))
                 {
                     buttonStates[action][0] = button.pressed;
                 }
                 else
                 {
                     buttonStates.Add(action, new bool[] { button.pressed, false });
                 }
             }
         }
     }
 }