SvrManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using UnityEngine.Rendering;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Runtime.InteropServices;
  8. namespace Ximmerse.XR
  9. {
  10. public class SvrManager : MonoBehaviour
  11. {
  12. public static SvrManager Instance
  13. {
  14. get
  15. {
  16. if (instance == null) instance = FindObjectOfType<SvrManager>();
  17. if (instance == null) Debug.LogError("SvrManager object component not found");
  18. return instance;
  19. }
  20. }
  21. private static SvrManager instance;
  22. [Serializable]
  23. public class SvrSettings
  24. {
  25. public enum eVSyncCount
  26. {
  27. k1 = 1,
  28. k2 = 2,
  29. };
  30. public enum eMasterTextureLimit
  31. {
  32. k0 = 0, // full size
  33. k1 = 1, // half size
  34. k2 = 2, // quarter size
  35. k3 = 3, // ...
  36. k4 = 4 // ...
  37. };
  38. public enum ePerfLevel
  39. {
  40. Minimum = 1,
  41. Medium = 2,
  42. Maximum = 3
  43. };
  44. [Flags] public enum eOptionFlags
  45. {
  46. ProtectedContent = (1 << 0),
  47. MotionAwareFrames = (1 << 1),
  48. FoveationSubsampled = (1 << 2),
  49. EnableCameraLayer = (1 << 3),
  50. Enable3drOcclusion = (1 << 4),
  51. }
  52. public enum eFoveationLevel
  53. {
  54. None = -1,
  55. Low = 0,
  56. Med = 1,
  57. High = 2
  58. }
  59. public enum eCameraPassThruVideo
  60. {
  61. Disabled = 0,
  62. Enabled = 1,
  63. }
  64. public enum eTrackingRecenterMode
  65. {
  66. Disabled,
  67. Application,
  68. Device
  69. }
  70. [Tooltip("Select platform type")]
  71. public SvrPlugin.DeviceModel deviceModel = SvrPlugin.DeviceModel.Default;
  72. [Tooltip("Use position tracking (if available)")]
  73. public bool trackPosition = true;
  74. [Tooltip("Limit refresh rate")]
  75. public eVSyncCount vSyncCount = eVSyncCount.k1;
  76. [Tooltip("QualitySettings TextureQuality FullRes, HalfRes, etc.")]
  77. public eMasterTextureLimit masterTextureLimit = eMasterTextureLimit.k0;
  78. [Tooltip("CPU performance level")]
  79. public ePerfLevel cpuPerfLevel = ePerfLevel.Medium;
  80. [Tooltip("GPU performance level")]
  81. public ePerfLevel gpuPerfLevel = ePerfLevel.Medium;
  82. [Tooltip("Tracking recenter mode")]
  83. public eTrackingRecenterMode trackingRecenterMode = eTrackingRecenterMode.Application;
  84. }
  85. [SerializeField]
  86. public SvrSettings settings;
  87. private SvrPlugin plugin = null;
  88. public enum svrThermalLevel
  89. {
  90. kSafe,
  91. kLevel1,
  92. kLevel2,
  93. kLevel3,
  94. kCritical,
  95. kNumThermalLevels
  96. };
  97. public enum svrThermalZone
  98. {
  99. kCpu,
  100. kGpu,
  101. kSkin,
  102. kNumThermalZones
  103. };
  104. public struct svrEventData_Thermal
  105. {
  106. public svrThermalZone zone; //!< Thermal zone
  107. public svrThermalLevel level; //!< Indication of the current zone thermal level
  108. };
  109. public void Initialize()
  110. {
  111. Debug.Log("SvrManager.Initialize()");
  112. SvrPlugin.deviceModel = settings.deviceModel;
  113. plugin = SvrPlugin.Instance;
  114. Input.backButtonLeavesApp = true;
  115. Screen.sleepTimeout = SleepTimeout.NeverSleep;
  116. Application.targetFrameRate = -1;
  117. int trackingMode = (int)SvrPlugin.TrackingMode.kTrackingOrientation;
  118. if (settings.trackPosition)
  119. trackingMode |= (int)SvrPlugin.TrackingMode.kTrackingPosition;
  120. plugin.SetTrackingMode(trackingMode);
  121. plugin.SetPerformanceLevels((int)settings.cpuPerfLevel, (int)settings.gpuPerfLevel);
  122. plugin.SetVSyncCount((int)settings.vSyncCount);
  123. QualitySettings.vSyncCount = (int)settings.vSyncCount;
  124. }
  125. }
  126. }