Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.0 KiB

  1. // SteamVR Defines|SDK_SteamVR|001
  2. namespace VRTK
  3. {
  4. using System;
  5. using System.Reflection;
  6. /// <summary>
  7. /// Handles all the scripting define symbols for the SteamVR SDK.
  8. /// </summary>
  9. public static class SDK_SteamVRDefines
  10. {
  11. /// <summary>
  12. /// The scripting define symbol for the SteamVR SDK.
  13. /// </summary>
  14. public const string ScriptingDefineSymbol = SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "SDK_STEAMVR";
  15. private const string BuildTargetGroupName = "Standalone";
  16. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, BuildTargetGroupName)]
  17. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "STEAMVR_PLUGIN_1_2_2_OR_NEWER", BuildTargetGroupName)]
  18. private static bool IsPluginVersion122OrNewer()
  19. {
  20. Type controllerManagerClass = VRTK_SharedMethods.GetTypeUnknownAssembly("SteamVR_ControllerManager");
  21. if (controllerManagerClass == null)
  22. {
  23. return false;
  24. }
  25. return controllerManagerClass.GetMethod("SetUniqueObject", BindingFlags.NonPublic | BindingFlags.Instance) != null;
  26. }
  27. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, BuildTargetGroupName)]
  28. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "STEAMVR_PLUGIN_1_2_1_OR_NEWER", BuildTargetGroupName)]
  29. private static bool IsPluginVersion121OrNewer()
  30. {
  31. Type eventClass = VRTK_SharedMethods.GetTypeUnknownAssembly("SteamVR_Events");
  32. if (eventClass == null)
  33. {
  34. return false;
  35. }
  36. MethodInfo systemMethod = eventClass.GetMethod("System", BindingFlags.Public | BindingFlags.Static);
  37. if (systemMethod == null)
  38. {
  39. return false;
  40. }
  41. ParameterInfo[] systemMethodParameters = systemMethod.GetParameters();
  42. if (systemMethodParameters.Length != 1)
  43. {
  44. return false;
  45. }
  46. return systemMethodParameters[0].ParameterType == VRTK_SharedMethods.GetTypeUnknownAssembly("Valve.VR.EVREventType");
  47. }
  48. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, BuildTargetGroupName)]
  49. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "STEAMVR_PLUGIN_1_2_0", BuildTargetGroupName)]
  50. private static bool IsPluginVersion120()
  51. {
  52. Type eventClass = VRTK_SharedMethods.GetTypeUnknownAssembly("SteamVR_Events");
  53. if (eventClass == null)
  54. {
  55. return false;
  56. }
  57. MethodInfo systemMethod = eventClass.GetMethod("System", BindingFlags.Public | BindingFlags.Static);
  58. if (systemMethod == null)
  59. {
  60. return false;
  61. }
  62. ParameterInfo[] systemMethodParameters = systemMethod.GetParameters();
  63. if (systemMethodParameters.Length != 1)
  64. {
  65. return false;
  66. }
  67. return systemMethodParameters[0].ParameterType == typeof(string);
  68. }
  69. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, BuildTargetGroupName)]
  70. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "STEAMVR_PLUGIN_1_1_1_OR_OLDER", BuildTargetGroupName)]
  71. private static bool IsPluginVersion111OrOlder()
  72. {
  73. Type utilsClass = VRTK_SharedMethods.GetTypeUnknownAssembly("SteamVR_Utils");
  74. if (utilsClass == null)
  75. {
  76. return false;
  77. }
  78. Type eventClass = VRTK_SharedMethods.GetNestedType(utilsClass, "Event");
  79. if (eventClass == null)
  80. {
  81. return false;
  82. }
  83. return eventClass.GetMethod("Listen", BindingFlags.Public | BindingFlags.Static) != null;
  84. }
  85. }
  86. }