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.

113 lines
2.2 KiB

  1. namespace Oculus.Platform.Samples.VrBoardGame
  2. {
  3. using UnityEngine;
  4. using Oculus.Platform;
  5. using Oculus.Platform.Models;
  6. // Top level class for initializing the Oculus Platform SDK. It also performs
  7. // and entitlement check and returns information about the logged-in user.
  8. public class PlatformManager : MonoBehaviour
  9. {
  10. private static PlatformManager s_instance;
  11. // my Application-scoped Oculus ID
  12. private ulong m_myID;
  13. // my Oculus user name
  14. private string m_myOculusID;
  15. #region Initialization and Shutdown
  16. void Awake()
  17. {
  18. // make sure only one instance of this manager ever exists
  19. if (s_instance != null)
  20. {
  21. Destroy(gameObject);
  22. return;
  23. }
  24. s_instance = this;
  25. DontDestroyOnLoad(gameObject);
  26. Core.Initialize();
  27. }
  28. void Start()
  29. {
  30. // First thing we should do is perform an entitlement check to make sure
  31. // we successfully connected to the Oculus Platform Service.
  32. Entitlements.IsUserEntitledToApplication().OnComplete(IsEntitledCallback);
  33. }
  34. void IsEntitledCallback(Message msg)
  35. {
  36. if (msg.IsError)
  37. {
  38. TerminateWithError(msg);
  39. return;
  40. }
  41. // Next get the identity of the user that launched the Application.
  42. Users.GetLoggedInUser().OnComplete(GetLoggedInUserCallback);
  43. }
  44. void GetLoggedInUserCallback(Message<User> msg)
  45. {
  46. if (msg.IsError)
  47. {
  48. TerminateWithError(msg);
  49. return;
  50. }
  51. m_myID = msg.Data.ID;
  52. m_myOculusID = msg.Data.OculusID;
  53. Debug.Log(" I am " + m_myOculusID);
  54. }
  55. // In this example, for most errors, we terminate the Application. A full App would do
  56. // something more graceful.
  57. public static void TerminateWithError(Message msg)
  58. {
  59. Debug.Log("Error: " + msg.GetError().Message);
  60. UnityEngine.Application.Quit();
  61. }
  62. #endregion
  63. #region Properties
  64. public static ulong MyID
  65. {
  66. get
  67. {
  68. if (s_instance != null)
  69. {
  70. return s_instance.m_myID;
  71. }
  72. else
  73. {
  74. return 0;
  75. }
  76. }
  77. }
  78. public static string MyOculusID
  79. {
  80. get
  81. {
  82. if (s_instance != null && s_instance.m_myOculusID != null)
  83. {
  84. return s_instance.m_myOculusID;
  85. }
  86. else
  87. {
  88. return string.Empty;
  89. }
  90. }
  91. }
  92. #endregion
  93. }
  94. }