Search Unity

Some questions about Native VR input...

Discussion in 'VR' started by Alverik, Aug 17, 2018.

  1. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Sorry, bit of a noob question... I need to create my own input manager which uses native Unity (2018.1+) input for both Rift and Vive (no third party plugins), but I find myself a bit confused about how to get the inputs using just Unity API (my hope is to setup everything in script). I checked the manual but it's a little vague (no code examples.. just tells you to use the Input class) https://docs.unity3d.com/Manual/OpenVRControllers.html

    Am I supposed to simply use the Input.GetButton("buttonName")? Do I have no choice other than adding Axes to the input manager manually? (I far prefer keyCodes usually...). Normally I would just try it and see but I have some problems with my PC and I won't be able to use the headset for a few weeks so I'm a bit in the dark (since I can't test it and I hate not knowing if something works or not).

    If anyone would be so kind as to provide me some pointers I'd really appreciate it a lot...
     
    Last edited: Aug 19, 2018
  2. SiliconDroid

    SiliconDroid

    Joined:
    Feb 20, 2017
    Posts:
    302
    I worked through a similar issue (daydream / gearvr)

    I don't think Unity standard input will cover all your bases, and XR.Input is a work in progress for now it seems.

    Ended up making a c# baseclass MyInput (derived from MonoBehavior) that provides the functions my game requires:
    bool GetTrigger()
    Vector2 GetTouchPos()
    Quaternion GetControllerOrientation()
    etc...

    Then derived 2 new classes from MyInput, one for GearVR and one for Daydream.
    Each derived class overrides the baseclass access functions.

    You instantiate the relevant derived class during game init depending on what's in your player settings XR list:

    Code (CSharp):
    1. string[] asDevices = UnityEngine.XR.XRSettings.supportedDevices;
    This way after init you simply call MyInput functions without having to worry about any conditional code during runtime.

    Also you will be able to add other XR platforms or even joypads etc without having to wade through your game code.
     
    Last edited: Aug 26, 2018
    Alverik likes this.