NxrInstantNativeApi.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace Nxr.Internal
  5. {
  6. public class NxrInstantNativeApi
  7. {
  8. #region Struct
  9. [StructLayout(LayoutKind.Sequential)]
  10. public struct Nibiru_Pose
  11. {
  12. public Vector3 position;
  13. public Quaternion rotation;
  14. }
  15. [StructLayout(LayoutKind.Sequential)]
  16. public struct Nibiru_ControllerStates
  17. {
  18. public uint battery; // 电量
  19. public uint connectStatus;//连接状态 : hmd/left/right
  20. public uint buttons;//手柄按键
  21. public uint hmdButtons;// 一体机按键:上,下,左,右,确认
  22. public uint touches;//手柄触摸
  23. public Vector2 touchpadAxis;//触摸坐标
  24. }
  25. [StructLayout(LayoutKind.Sequential)]
  26. public struct Nibiru_Config
  27. {
  28. public uint controllerType; //0=nolo,2=3dof,3=none
  29. public float ipd;
  30. public float near;
  31. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
  32. public float[] eyeFrustumParams;//Left 4, Right 4 (left,right,bottom,top)
  33. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
  34. public uint[] textureSize; // width, height
  35. }
  36. public struct NvrInitParams
  37. {
  38. public int renderWidth;
  39. public int renderHeight;
  40. public int bitRate;
  41. }
  42. [StructLayout(LayoutKind.Sequential)]
  43. public struct DebugInfo
  44. {
  45. public int frameIndex;
  46. }
  47. #endregion
  48. public enum NibiruDeviceType
  49. {
  50. Hmd = 0,
  51. LeftController,
  52. RightController,
  53. None=3
  54. }
  55. // 手柄类型
  56. public enum NibiruControllerId
  57. {
  58. // 0=NOLO,1=...,2=3DOF Controller,3=NONE
  59. NOLO, EXPAND, NORMAL_3DOF, NONE
  60. }
  61. public enum RenderEvent
  62. {
  63. SubmitFrame = 1
  64. };
  65. public static bool Inited = false;
  66. public static int nativeApiVersion = -1;
  67. public static int driverVersion = -1;
  68. #if UNITY_STANDALONE_WIN || ANDROID_REMOTE_NRR
  69. internal const string dllName = "NvrPluginNative";
  70. [DllImport(dllName)]
  71. public static extern void SetVersionInfo(int apiVersion, string unity_version_str, int unity_version_length);
  72. [DllImport(dllName)]
  73. public static extern bool Init(NvrInitParams args);
  74. [DllImport(dllName)]
  75. public static extern IntPtr GetRenderEventFunc();
  76. [DllImport(dllName)]
  77. public static extern void SetFrameTexture(IntPtr texturePointer);
  78. [DllImport(dllName)]
  79. public static extern void Cleanup();
  80. [DllImport(dllName)]
  81. public static extern Nibiru_Config GetNibiruConfig();
  82. // 手柄Pose
  83. [DllImport(dllName)]
  84. public static extern Nibiru_Pose GetPoseByDeviceType(NibiruDeviceType type);
  85. [DllImport(dllName)]
  86. public static extern Nibiru_ControllerStates GetControllerStates(NibiruDeviceType type);
  87. [DllImport(dllName)]
  88. public static extern void SetNibiruConfigCallback(NxrViewer.NibiruConfigCallback callback);
  89. //---------------------New Api----V1-----------------
  90. [DllImport(dllName)]
  91. public static extern void GetVersionInfo(ref int apiVersion, ref int driverVersion);
  92. [DllImport(dllName)]
  93. public static extern void SendFrame();
  94. [DllImport(dllName)]
  95. public static extern void GetTextureResolution(ref int width, ref int height);
  96. [DllImport(dllName)]
  97. public static extern DebugInfo GetDebugInfo();
  98. //---------------------New Api----V1-----------------
  99. [DllImport(dllName)]
  100. public static extern UInt32 GetDecodeRate();
  101. [DllImport(dllName)]
  102. public static extern UInt32 GetRefreshRate();
  103. [DllImport(dllName)]
  104. public static extern IntPtr GetLeapMotionData();
  105. //---------------------New Api----V2-----------------
  106. //---------------------New Api----V2-----------------
  107. #elif UNITY_ANDROID
  108. public static void SetVersionInfo(int apiVersion, string unity_version_str, int unity_version_length) { }
  109. public static bool Init(NvrInitParams args) { return false; }
  110. public static IntPtr GetRenderEventFunc() { return IntPtr.Zero; }
  111. public static void SetFrameTexture(IntPtr texturePointer) { }
  112. public static void Cleanup() { }
  113. public static Nibiru_Config GetNibiruConfig() { return new Nibiru_Config(); }
  114. // 手柄Pose
  115. public static Nibiru_Pose GetPoseByDeviceType(NibiruDeviceType type) { return new Nibiru_Pose(); }
  116. public static Nibiru_ControllerStates GetControllerStates(NibiruDeviceType type) { return new Nibiru_ControllerStates(); }
  117. public static void SetNibiruConfigCallback(NxrViewer.NibiruConfigCallback callback) { }
  118. //---------------------New Api----V1-----------------
  119. public static void GetVersionInfo(ref int apiVersion, ref int driverVersion) { }
  120. public static void SendFrame() { }
  121. public static void GetTextureResolution(ref int width, ref int height) { }
  122. public static DebugInfo GetDebugInfo() { return new DebugInfo(); }
  123. //---------------------New Api----V1-----------------
  124. public static IntPtr GetLeapMotionData() { return IntPtr.Zero; }
  125. public static UInt32 GetRefreshRate() { return 0; }
  126. public static UInt32 GetDecodeRate() { return 0; }
  127. //---------------------New Api----V2-----------------
  128. //---------------------New Api----V2-----------------
  129. #endif
  130. }
  131. }