SvrManager.cs 3.8 KB

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