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.

65 lines
3.1 KiB

  1. // Oculus Defines|SDK_Oculus|001
  2. namespace VRTK
  3. {
  4. using System;
  5. using System.Reflection;
  6. /// <summary>
  7. /// Handles all the scripting define symbols for the Oculus and Avatar SDKs.
  8. /// </summary>
  9. public static class SDK_OculusDefines
  10. {
  11. /// <summary>
  12. /// The scripting define symbol for the Oculus SDK.
  13. /// </summary>
  14. public const string ScriptingDefineSymbol = SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "SDK_OCULUS";
  15. /// <summary>
  16. /// The scripting define symbol for the Oculus Avatar SDK.
  17. /// </summary>
  18. public const string AvatarScriptingDefineSymbol = SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "SDK_OCULUS_AVATAR";
  19. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, "Standalone")]
  20. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, "Android")]
  21. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "OCULUS_UTILITIES_1_12_0_OR_NEWER", "Standalone")]
  22. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "OCULUS_UTILITIES_1_12_0_OR_NEWER", "Android")]
  23. private static bool IsUtilitiesVersion1120OrNewer()
  24. {
  25. Version wrapperVersion = GetOculusWrapperVersion();
  26. return wrapperVersion != null && wrapperVersion >= new Version(1, 12, 0);
  27. }
  28. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, "Standalone")]
  29. [SDK_ScriptingDefineSymbolPredicate(ScriptingDefineSymbol, "Android")]
  30. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "OCULUS_UTILITIES_1_11_0_OR_OLDER", "Standalone")]
  31. [SDK_ScriptingDefineSymbolPredicate(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix + "OCULUS_UTILITIES_1_11_0_OR_OLDER", "Android")]
  32. private static bool IsUtilitiesVersion1110OrOlder()
  33. {
  34. Version wrapperVersion = GetOculusWrapperVersion();
  35. return wrapperVersion != null && wrapperVersion < new Version(1, 12, 0);
  36. }
  37. [SDK_ScriptingDefineSymbolPredicate(AvatarScriptingDefineSymbol, "Standalone")]
  38. [SDK_ScriptingDefineSymbolPredicate(AvatarScriptingDefineSymbol, "Android")]
  39. private static bool IsAvatarAvailable()
  40. {
  41. return (IsUtilitiesVersion1120OrNewer() || IsUtilitiesVersion1110OrOlder())
  42. && VRTK_SharedMethods.GetTypeUnknownAssembly("OvrAvatar") != null;
  43. }
  44. private static Version GetOculusWrapperVersion()
  45. {
  46. Type pluginClass = VRTK_SharedMethods.GetTypeUnknownAssembly("OVRPlugin");
  47. if (pluginClass == null)
  48. {
  49. return null;
  50. }
  51. FieldInfo versionField = pluginClass.GetField("wrapperVersion", BindingFlags.Public | BindingFlags.Static);
  52. if (versionField == null)
  53. {
  54. return null;
  55. }
  56. return (Version)versionField.GetValue(null);
  57. }
  58. }
  59. }