Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How to use Oculus Quest 2 X Y A B Keys in 2023?

Discussion in 'XR Interaction Toolkit and Input' started by kreekermartezoo, May 1, 2023.

  1. kreekermartezoo

    kreekermartezoo

    Joined:
    Jul 14, 2022
    Posts:
    1
    As the title says. Could you provide me with a simplest examples there could be? I googled here and there and found nothing up-to-date. How do i make something happen in script once i press one of those buttons?
    What i need precisely is switching between two diffrent skybox materials (mat1 assigned to button A and mat2 assigned to button B).

    Thank you all in advance!
     
  2. feathered_wing

    feathered_wing

    Joined:
    Dec 5, 2020
    Posts:
    20
    Assuming a script is a Singleton named XRInput, add the following content to it:
    Code (CSharp):
    1. public bool XButton;
    2. public Action XButtonDown;
    3. public Action XButtonUp;
    4.  
    5. [SerializeField]
    6.     InputActionProperty m_XButtonAction;
    7.     public InputActionProperty XButtonAction
    8.     {
    9.         get => m_XButtonAction;
    10.         set => SetInputActionProperty(ref m_XButtonAction, value);
    11.     }
    12.  
    13.  
    14. private void Awake()
    15.     {
    16.         XButtonAction.action.performed += p =>
    17.         {
    18.             XButton = true;
    19.             XButtonDown?.Invoke();
    20.         };
    21.         XButtonAction.action.canceled += p =>
    22.         {
    23.             XButton = false;
    24.             XButtonUp?.Invoke();
    25.         };
    26. }
    open your XRI Default Input Actions
    upload_2023-5-5_17-45-7.png
    upload_2023-5-5_17-46-23.png

    when you used:
    Code (CSharp):
    1. //other script:
    2. public void Start()
    3. {
    4. XRInput.instance.XButtonDown += () =>
    5. {
    6.     // your code
    7. };
    8. }
     

    Attached Files:

    tamarziv_unity likes this.
  3. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    255
    Thank you for that answer @wechat_os_Qy02HOgoFEbliwS1tdgrvdoEM, that is a good answer for quick and easy implementation. There are a couple of other things that also might be helpful. If you plan to use OpenXR (and we highly recommend it from the Unity side), you should check out the more generic mappings against the XYAB buttons to provide a more cross-platform solution.

    You can also check out the XRI Default Input Actions in the XR Interaction Toolkit > Starter Assets sample package. The combination of the XR Controller (Action-based) and the inputactions asset should be a good starting point.
    upload_2023-5-8_9-54-16.png

    If you want something even more straight-forward, the OpenXR package's Controller sample package is another good starting point.
    upload_2023-5-8_9-52-18.png