OpenVRHelpers.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using UnityEngine;
  7. namespace Unity.XR.OpenVR
  8. {
  9. public class OpenVRHelpers
  10. {
  11. public static bool IsUsingSteamVRInput()
  12. {
  13. return DoesTypeExist("SteamVR_Input");
  14. }
  15. public static bool DoesTypeExist(string className, bool fullname = false)
  16. {
  17. return GetType(className, fullname) != null;
  18. }
  19. public static Type GetType(string className, bool fullname = false)
  20. {
  21. Type foundType = null;
  22. if (fullname)
  23. {
  24. foundType = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
  25. from type in assembly.GetTypes()
  26. where type.FullName == className
  27. select type).FirstOrDefault();
  28. }
  29. else
  30. {
  31. foundType = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
  32. from type in assembly.GetTypes()
  33. where type.Name == className
  34. select type).FirstOrDefault();
  35. }
  36. return foundType;
  37. }
  38. public static string GetActionManifestPathFromPlugin()
  39. {
  40. Type steamvrInputType = GetType("SteamVR_Input");
  41. MethodInfo getPathMethod = steamvrInputType.GetMethod("GetActionsFilePath");
  42. object path = getPathMethod.Invoke(null, new object[] { false });
  43. return (string)path;
  44. }
  45. public static string GetActionManifestNameFromPlugin()
  46. {
  47. Type steamvrInputType = GetType("SteamVR_Input");
  48. MethodInfo getPathMethod = steamvrInputType.GetMethod("GetActionsFileName");
  49. object path = getPathMethod.Invoke(null, null);
  50. return (string)path;
  51. }
  52. public static string GetEditorAppKeyFromPlugin()
  53. {
  54. Type steamvrInputType = GetType("SteamVR_Input");
  55. MethodInfo getPathMethod = steamvrInputType.GetMethod("GetEditorAppKey");
  56. object path = getPathMethod.Invoke(null, null);
  57. return (string)path;
  58. }
  59. }
  60. }