Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

XR Input - Help; Need Direct Access to "Data"

Discussion in 'Input System' started by Rickmc3280, Mar 30, 2021.

  1. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    192
    Problem: Created a set of scripts a year ago that poll the XR System for inputs. Does not work in 2020, however I can see controller data streaming in the debugger. How do I get access to those memory locations directly?

    I can see that there is a column that is called offset, which leads me to believe that there is an Array somewhere and the offset is used to get the data that I need. for example. GetTrigger(IndexControllerRawData[offset])
    GetPrimary(IndexControllerRawData[offset])
    etc etc...

    1) I would be perfectly fine with letting Unity poll the data, as that is what my VR Input script does... Then it fires events... But it is all done through code and I have hundreds of scripts that require it... so I dont want to do a full rewrite...

    2) I have custom events that use single, double, triple clicks and it is not something commonly supported in VR, but works great... but now I cant use it with 2020 due to the whole XR/Steam/HTC, whatever problem.

    Desired Solution: Get Access to the stream data using C# script. Also possibly redo some of the system to detect which XR controller for which player since the new system allows multiple players (which is a nice feature).


    Also **** FEATURE REQUEST ****

    Add Functions to get the data fast... I would visualize it something like this. Obviously this is not correct but a quick and dirty to show what I mean.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public delegate void XRInputEvent();
    5. public class Test : MonoBehaviour
    6. {
    7.     public XRSystemInUse xrSystemInUse;
    8.     public XRHandDeviceInUse xrHandDeviceInUse;
    9.     public byte[] RawInputStream;
    10.     public byte[] LastFrame;
    11.  
    12.     public bool SetupSuccess;
    13.     public bool LeftControllerTracking;
    14.     public bool RightControllerTracking;
    15.  
    16.     public event XRInputEvent LeftTriggerDown;
    17.     public event XRInputEvent RightTriggerDown;
    18.  
    19.     private static byte TRUE;
    20.     private static byte FALSE;
    21.    
    22.  
    23.     public void Setup()
    24.     {
    25.         xrSystemInUse = XR.System.ActiveSystem;
    26.         xrHandDeviceInUse = XR.System.DetectedControllerInUse;
    27.  
    28.         RawInputStream = XR.System.GetRawData(xrSystemInUse, xrHandDeviceInUse);
    29.  
    30.         if (RawInputStream.Length > 0)
    31.         {
    32.             SetupSuccess = true;
    33.         }
    34.         else SetupSuccess = false;
    35.     }
    36.  
    37.     public void Update()
    38.     {
    39.         if (SetupSuccess)
    40.         {
    41.             if (LeftControllerTracking)
    42.             {
    43.                 LeftControllerDataProcessor();
    44.             }
    45.             if (RightControllerTracking)
    46.             {
    47.                 RightControllerDataProcessor();
    48.             }
    49.         }
    50.         else
    51.         {
    52.             Setup();
    53.         }
    54.     }
    55.  
    56.     public void LeftControllerDataProcessor()
    57.     {
    58.         if (RawInputStream[10] == TRUE && LastFrame[1] == FALSE)
    59.         {
    60.             if (LeftTriggerDown != null)
    61.             {
    62.                 LeftTriggerDown.Invoke();
    63.             }
    64.         }
    65.     }
    66.     public void RightControllerDataProcessor()
    67.     {
    68.         if (RawInputStream[11] == TRUE && LastFrame[2] == FALSE)
    69.         {
    70.             if (RightTriggerDown != null)
    71.             {
    72.                 RightTriggerDown.Invoke();
    73.             }
    74.         }
    75.     }
    76. }
    77.  
    78. public struct VRButtonProcessor
    79. {
    80. }
    81. public struct VRAxisProcessor
    82. {
    83. }
    84. public struct VRVectorProcessor
    85. {
    86. }
    87.  
    88.  
    89. public enum XRHandDeviceInUse
    90. {
    91.     VIVEWAND,
    92.     INDEXCONTROLLER,
    93.     OCCULUS
    94. }
    95. public enum XRSystemInUse
    96. {
    97.     VIVE,
    98.     VIVEPRO,
    99.     INDEX,
    100.     OCCULUS
    101. }
    102.  
     
    Last edited: Mar 30, 2021