SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.1 KiB

4 years ago
  1. using System.Runtime.InteropServices;
  2. using Unity.Collections;
  3. using UnityEngine.Scripting;
  4. using UnityEngine.XR.ARSubsystems;
  5. namespace UnityEngine.XR.ARKit
  6. {
  7. /// <summary>
  8. /// The ARKit implementation of the <c>XRAnchorSubsystem</c>. Do not create this directly.
  9. /// Use the <c>SubsystemManager</c> instead.
  10. /// </summary>
  11. [Preserve]
  12. public sealed class ARKitAnchorSubsystem : XRAnchorSubsystem
  13. {
  14. protected override Provider CreateProvider() => new ARKitProvider();
  15. class ARKitProvider : Provider
  16. {
  17. public override void Start() => UnityARKit_refPoints_onStart();
  18. public override void Stop() => UnityARKit_refPoints_onStop();
  19. public override void Destroy() => UnityARKit_refPoints_onDestroy();
  20. public override unsafe TrackableChanges<XRAnchor> GetChanges(
  21. XRAnchor defaultAnchor,
  22. Allocator allocator)
  23. {
  24. void* addedPtr, updatedPtr, removedPtr;
  25. int addedCount, updatedCount, removedCount, elementSize;
  26. var context = UnityARKit_refPoints_acquireChanges(
  27. out addedPtr, out addedCount,
  28. out updatedPtr, out updatedCount,
  29. out removedPtr, out removedCount,
  30. out elementSize);
  31. try
  32. {
  33. return new TrackableChanges<XRAnchor>(
  34. addedPtr, addedCount,
  35. updatedPtr, updatedCount,
  36. removedPtr, removedCount,
  37. defaultAnchor, elementSize,
  38. allocator);
  39. }
  40. finally
  41. {
  42. UnityARKit_refPoints_releaseChanges(context);
  43. }
  44. }
  45. public override bool TryAddAnchor(Pose pose, out XRAnchor anchor)
  46. {
  47. return UnityARKit_refPoints_tryAdd(pose, out anchor);
  48. }
  49. public override bool TryAttachAnchor(
  50. TrackableId trackableToAffix,
  51. Pose pose,
  52. out XRAnchor anchor)
  53. {
  54. return UnityARKit_refPoints_tryAttach(trackableToAffix, pose, out anchor);
  55. }
  56. public override bool TryRemoveAnchor(TrackableId anchorId)
  57. {
  58. return UnityARKit_refPoints_tryRemove(anchorId);
  59. }
  60. [DllImport("__Internal")]
  61. static extern void UnityARKit_refPoints_onStart();
  62. [DllImport("__Internal")]
  63. static extern void UnityARKit_refPoints_onStop();
  64. [DllImport("__Internal")]
  65. static extern unsafe void UnityARKit_refPoints_onDestroy();
  66. [DllImport("__Internal")]
  67. static extern unsafe void* UnityARKit_refPoints_acquireChanges(
  68. out void* addedPtr, out int addedCount,
  69. out void* updatedPtr, out int updatedCount,
  70. out void* removedPtr, out int removedCount,
  71. out int elementSize);
  72. [DllImport("__Internal")]
  73. static extern unsafe void UnityARKit_refPoints_releaseChanges(void* changes);
  74. [DllImport("__Internal")]
  75. static extern bool UnityARKit_refPoints_tryAdd(
  76. Pose pose,
  77. out XRAnchor anchor);
  78. [DllImport("__Internal")]
  79. static extern bool UnityARKit_refPoints_tryAttach(
  80. TrackableId trackableToAffix,
  81. Pose pose,
  82. out XRAnchor anchor);
  83. [DllImport("__Internal")]
  84. static extern bool UnityARKit_refPoints_tryRemove(TrackableId anchorId);
  85. }
  86. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
  87. static void RegisterDescriptor()
  88. {
  89. #if UNITY_IOS && !UNITY_EDITOR
  90. var cinfo = new XRAnchorSubsystemDescriptor.Cinfo
  91. {
  92. id = "ARKit-Anchor",
  93. subsystemImplementationType = typeof(ARKitAnchorSubsystem),
  94. supportsTrackableAttachments = true
  95. };
  96. XRAnchorSubsystemDescriptor.Create(cinfo);
  97. #endif
  98. }
  99. }
  100. }