API_SVR.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class API_SVR {
  6. public enum TrackMode {
  7. Mode_3Dof,
  8. Mode_6Dof,
  9. }
  10. ///API-No.1
  11. /// <summary>
  12. /// 设置眼镜进入模式,运行过程中可修改
  13. /// </summary>
  14. public static void SetTrackMode(TrackMode mode) {
  15. if(SvrManager.Instance != null) {
  16. SvrManager.Instance.settings.trackPosition = (mode == TrackMode.Mode_6Dof ? true : false);
  17. }
  18. }
  19. ///API-No.2
  20. /// <summary>
  21. /// Svr系统是否在运行
  22. /// </summary>
  23. /// <returns>true表示在运行,false表示未运行(Pause时为false)</returns>
  24. public static bool IsSvrRunning() {
  25. if(SvrManager.Instance != null) {
  26. return SvrManager.Instance.status.running;
  27. }
  28. return false;
  29. }
  30. ///API-No.3
  31. /// <summary>
  32. /// Svr系统是否初始化完成
  33. /// </summary>
  34. /// <returns></returns>
  35. public static bool IsSvrInitialized() {
  36. if(SvrManager.Instance != null) {
  37. return SvrManager.Instance.status.initialized;
  38. }
  39. return false;
  40. }
  41. ///API-No.4
  42. /// <summary>
  43. /// 设置Svr初始化完成时的回调
  44. /// </summary>
  45. /// <param name="action"></param>
  46. public static void AddInitializedCallBack(Action action) {
  47. SvrManager.Instance.SvrInitializedCallBack += action;
  48. }
  49. ///API-No.5
  50. public static void RemoveInitializedCallBack(Action action) {
  51. SvrManager.Instance.SvrInitializedCallBack -= action;
  52. }
  53. ///API-No.6
  54. /// <summary>
  55. /// 设置渲染帧率,只能在Start中调用
  56. /// </summary>
  57. /// <param name="frameRate">默认-1表示系统默认帧率,设置范围0-200</param>
  58. public static void SetRenderFrame(int frameRate = -1) {
  59. if(SvrManager.Instance != null) {
  60. if(frameRate == -1) {
  61. SvrManager.Instance.plugin.SetVSyncCount((int)(SvrManager.Instance.settings.vSyncCount = SvrManager.SvrSettings.eVSyncCount.k1));
  62. QualitySettings.vSyncCount = (int)(SvrManager.Instance.settings.vSyncCount = SvrManager.SvrSettings.eVSyncCount.k1);//Vsync
  63. } else {
  64. SvrManager.Instance.plugin.SetVSyncCount((int)(SvrManager.Instance.settings.vSyncCount = SvrManager.SvrSettings.eVSyncCount.k0));
  65. QualitySettings.vSyncCount = (int)(SvrManager.Instance.settings.vSyncCount = SvrManager.SvrSettings.eVSyncCount.k0);//Don't sync
  66. Application.targetFrameRate = (frameRate >= 0 && frameRate < 200) ? frameRate : 75;
  67. }
  68. }
  69. }
  70. ///API-No.7
  71. /// <summary>
  72. /// 获取左右眼摄像头
  73. /// </summary>
  74. /// <returns>List[0]左眼 List[1]右眼,空表示系统未启动完成</returns>
  75. public static List<Camera> GetEyeCameras() {
  76. List<Camera> cameraList = new List<Camera>(2);
  77. if(SvrManager.Instance != null && SvrManager.Instance.status.running == true) {
  78. cameraList.Add(SvrManager.Instance.leftCamera);
  79. cameraList.Add(SvrManager.Instance.rightCamera);
  80. }
  81. return cameraList;
  82. }
  83. ///API-No.8
  84. /// <summary>
  85. /// 获取左右眼渲染的画面,为获取当前帧的渲染结果,当前帧结束时调用
  86. /// </summary>
  87. /// <returns>List[0]左眼 List[1]右眼,空表示系统未启动完成</returns>
  88. public static List<RenderTexture> GetRenderTexure() {
  89. List<Camera> cameraList = GetEyeCameras();
  90. List<RenderTexture> RTList = new List<RenderTexture>(2);
  91. foreach(var item in cameraList) {
  92. RTList.Add(item.targetTexture);
  93. }
  94. return RTList;
  95. }
  96. ///API-No.9
  97. /// <summary>
  98. /// 获取头部物体,如果想获取头部的旋转移动等数据,在LateUpdate方法里调用
  99. /// </summary>
  100. /// <returns>空表示系统未启动完成</returns>
  101. public static Transform GetHead() {
  102. if(SvrManager.Instance != null && SvrManager.Instance.status.running == true) {
  103. return SvrManager.Instance.head;
  104. }
  105. return null;
  106. }
  107. ///API-No.10
  108. /// <summary>
  109. /// 设置瞳距,Awake时调用,Start后调用无效
  110. /// </summary>
  111. /// <param name="offset">瞳距的偏移量,单位米</param>
  112. public static void SetPD(float offset = 0) {
  113. if(SvrManager.Instance != null) {
  114. SvrManager.Instance.leftCameraOffsetPostion += offset / 2 * Vector3.left;
  115. SvrManager.Instance.rightCameraOffsetPostion += offset / 2 * Vector3.right;
  116. }
  117. }
  118. ///API-No.11
  119. /// <summary>
  120. /// 重定位,若无效果,表示系统初始化未完成,且只有在眼镜上有效
  121. /// </summary>
  122. public static void RecenterTracking() {
  123. if(SvrManager.Instance != null) {
  124. SvrManager.Instance.RecenterTracking();
  125. }
  126. }
  127. }