Search Unity

Question Oculus Quest Action-Based Controller Input

Discussion in 'XR Interaction Toolkit and Input' started by jthiess, Apr 21, 2021.

  1. jthiess

    jthiess

    Joined:
    Nov 5, 2018
    Posts:
    31
    Hello all,

    I have been doing a lot of research trying to find an effective/efficient way to add Oculus Quest controller input using the Action Based XR Rig. I can't really find anything that doesn't require complete customization with code.
    Is there a baseline functional controller I can start at? Or some more concise way to create interaction?

    I basically want to make the trigger produce a laser pointer from the controller. Joystick right to change some materials on an object. And joystick up to scale up an object.

    Any tutorial, more clear documentation, or straight up support would be appreciated!
     
  2. jthiess

    jthiess

    Joined:
    Nov 5, 2018
    Posts:
    31
    Or is there an example project that I could deconstruct that has these elements functioning?
     
  3. jthiess

    jthiess

    Joined:
    Nov 5, 2018
    Posts:
    31
    Update:
    I have built the following code that takes a public Input Action reference
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6.  
    7. public class EnvironmentLibraryXR : MonoBehaviour
    8. {
    9.     public InputActionReference sceneForward = null;
    10.     public InputActionReference sceneBack = null;
    11.  
    12.     //public MaterialController controller;
    13.     public Material[] materials;
    14.     private int whichMaterial = 0; // can make public to debug
    15.     Renderer rend;
    16.  
    17.     void Start()
    18.     {
    19.         rend = GetComponent<Renderer>();
    20.         rend.enabled = true;
    21.         rend.sharedMaterial = materials[0];
    22.  
    23.         sceneForward.action.started += Forward;
    24.         sceneBack.action.started += Back;
    25.     }
    26.  
    27.     private void Forward(InputAction.CallbackContext context)
    28.     {
    29.         whichMaterial++;
    30.         rend.sharedMaterial = materials[Mathf.Abs(whichMaterial % materials.Length)];
    31.         Debug.Log("Next Image");
    32.     }
    33.  
    34.     private void Back(InputAction.CallbackContext context)
    35.     {
    36.         whichMaterial--;
    37.         rend.sharedMaterial = materials[Mathf.Abs(whichMaterial % materials.Length)];
    38.         Debug.Log("Previous Image");
    39.     }
    40. }
    Here are the two actions it uses:
    upload_2021-4-22_15-45-20.png

    The Forward uses an "East" direction, while the Back uses "West"
    upload_2021-4-22_15-46-22.png

    For the moment this seems to work. But is there a more efficient way? Is there a way to use one action that detects two Interactions, East and West, and does the action acordingly?