Advertisement
salahzar

Controller

May 17th, 2020
1,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.XR;
  6.  
  7. public class Controller : MonoBehaviour
  8. {
  9.    
  10.     public float speed = 1;
  11.     [Tooltip("Testo da cambiare")]
  12.     public Text textObject;
  13.  
  14.  
  15.     // Start is called before the first frame update
  16.     void Start()
  17.     {
  18.  
  19.     }
  20.     string GetButtons()
  21.     {
  22.         // get the device we want to check
  23.         List<InputDevice> devices = null;
  24.         InputDevices.GetDevicesWithRole(InputDeviceRole.RightHanded, devices);
  25.  
  26.         // go through our devices
  27.         var list = new List<(string, InputFeatureUsage<bool>)> {
  28.             ("triggerButton",CommonUsages.triggerButton),
  29.             ("gripButton",CommonUsages.gripButton) ,
  30.             ("thumbrest", CommonUsages.thumbrest) ,
  31.             ("primary2DAxisClick",CommonUsages.primary2DAxisClick) ,
  32.             ("primary2DAxisTouch",CommonUsages.primary2DAxisTouch) ,
  33.             ("menuButton",CommonUsages.menuButton) ,
  34.             ("secondaryButton",CommonUsages.secondaryButton) ,
  35.             ("secondaryTouch",CommonUsages.secondaryTouch) ,
  36.             ("primaryButton",CommonUsages.primaryButton) ,
  37.             ("primaryTouch",CommonUsages.primaryTouch) };
  38.  
  39.         string ret = "";
  40.         foreach (InputDevice device in devices)
  41.         {
  42.  
  43.             foreach ((string name, InputFeatureUsage<bool> selectedFeature) in list)
  44.             {
  45.                 bool value;
  46.                 device.TryGetFeatureValue(selectedFeature, out value);
  47.                 ret += "\n" + name + ":" + value;
  48.             }
  49.  
  50.         }
  51.         return ret;
  52.     }
  53.  
  54.     // Update is called once per frame
  55.     void Update()
  56.     {
  57.  
  58.         string buttons = GetButtons();
  59.         textObject.text = buttons;
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement