OVRBoundary.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. public class OVRBoundary
  5. {
  6. public bool GetConfigured()
  7. {
  8. return OVRPlugin.GetBoundaryConfigured();
  9. }
  10. public OVRBoundary.BoundaryTestResult TestNode(OVRBoundary.Node node, OVRBoundary.BoundaryType boundaryType)
  11. {
  12. OVRPlugin.BoundaryTestResult boundaryTestResult = OVRPlugin.TestBoundaryNode((OVRPlugin.Node)node, (OVRPlugin.BoundaryType)boundaryType);
  13. return new OVRBoundary.BoundaryTestResult
  14. {
  15. IsTriggering = (boundaryTestResult.IsTriggering == OVRPlugin.Bool.True),
  16. ClosestDistance = boundaryTestResult.ClosestDistance,
  17. ClosestPoint = boundaryTestResult.ClosestPoint.FromFlippedZVector3f(),
  18. ClosestPointNormal = boundaryTestResult.ClosestPointNormal.FromFlippedZVector3f()
  19. };
  20. }
  21. public OVRBoundary.BoundaryTestResult TestPoint(Vector3 point, OVRBoundary.BoundaryType boundaryType)
  22. {
  23. OVRPlugin.BoundaryTestResult boundaryTestResult = OVRPlugin.TestBoundaryPoint(point.ToFlippedZVector3f(), (OVRPlugin.BoundaryType)boundaryType);
  24. return new OVRBoundary.BoundaryTestResult
  25. {
  26. IsTriggering = (boundaryTestResult.IsTriggering == OVRPlugin.Bool.True),
  27. ClosestDistance = boundaryTestResult.ClosestDistance,
  28. ClosestPoint = boundaryTestResult.ClosestPoint.FromFlippedZVector3f(),
  29. ClosestPointNormal = boundaryTestResult.ClosestPointNormal.FromFlippedZVector3f()
  30. };
  31. }
  32. public void SetLookAndFeel(OVRBoundary.BoundaryLookAndFeel lookAndFeel)
  33. {
  34. OVRPlugin.BoundaryLookAndFeel boundaryLookAndFeel = new OVRPlugin.BoundaryLookAndFeel
  35. {
  36. Color = lookAndFeel.Color.ToColorf()
  37. };
  38. OVRPlugin.SetBoundaryLookAndFeel(boundaryLookAndFeel);
  39. }
  40. public void ResetLookAndFeel()
  41. {
  42. OVRPlugin.ResetBoundaryLookAndFeel();
  43. }
  44. public Vector3[] GetGeometry(OVRBoundary.BoundaryType boundaryType)
  45. {
  46. int num = 0;
  47. if (OVRPlugin.GetBoundaryGeometry2((OVRPlugin.BoundaryType)boundaryType, IntPtr.Zero, ref num))
  48. {
  49. int num2 = num * OVRBoundary.cachedVector3fSize;
  50. if (OVRBoundary.cachedGeometryNativeBuffer.GetCapacity() < num2)
  51. {
  52. OVRBoundary.cachedGeometryNativeBuffer.Reset(num2);
  53. }
  54. int num3 = num * 3;
  55. if (OVRBoundary.cachedGeometryManagedBuffer.Length < num3)
  56. {
  57. OVRBoundary.cachedGeometryManagedBuffer = new float[num3];
  58. }
  59. if (OVRPlugin.GetBoundaryGeometry2((OVRPlugin.BoundaryType)boundaryType, OVRBoundary.cachedGeometryNativeBuffer.GetPointer(0), ref num))
  60. {
  61. Marshal.Copy(OVRBoundary.cachedGeometryNativeBuffer.GetPointer(0), OVRBoundary.cachedGeometryManagedBuffer, 0, num3);
  62. Vector3[] array = new Vector3[num];
  63. for (int i = 0; i < num; i++)
  64. {
  65. array[i] = new OVRPlugin.Vector3f
  66. {
  67. x = OVRBoundary.cachedGeometryManagedBuffer[3 * i],
  68. y = OVRBoundary.cachedGeometryManagedBuffer[3 * i + 1],
  69. z = OVRBoundary.cachedGeometryManagedBuffer[3 * i + 2]
  70. }.FromFlippedZVector3f();
  71. }
  72. return array;
  73. }
  74. }
  75. return new Vector3[0];
  76. }
  77. public Vector3 GetDimensions(OVRBoundary.BoundaryType boundaryType)
  78. {
  79. return OVRPlugin.GetBoundaryDimensions((OVRPlugin.BoundaryType)boundaryType).FromVector3f();
  80. }
  81. public bool GetVisible()
  82. {
  83. return OVRPlugin.GetBoundaryVisible();
  84. }
  85. public void SetVisible(bool value)
  86. {
  87. OVRPlugin.SetBoundaryVisible(value);
  88. }
  89. private static int cachedVector3fSize = Marshal.SizeOf(typeof(OVRPlugin.Vector3f));
  90. private static OVRNativeBuffer cachedGeometryNativeBuffer = new OVRNativeBuffer(0);
  91. private static float[] cachedGeometryManagedBuffer = new float[0];
  92. public enum Node
  93. {
  94. HandLeft = 3,
  95. HandRight,
  96. Head = 9
  97. }
  98. public enum BoundaryType
  99. {
  100. OuterBoundary = 1,
  101. PlayArea = 256
  102. }
  103. public struct BoundaryTestResult
  104. {
  105. public bool IsTriggering;
  106. public float ClosestDistance;
  107. public Vector3 ClosestPoint;
  108. public Vector3 ClosestPointNormal;
  109. }
  110. public struct BoundaryLookAndFeel
  111. {
  112. public Color Color;
  113. }
  114. }