-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathARObjectAnchor.cs
121 lines (87 loc) · 3.37 KB
/
ARObjectAnchor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.InteropServices;
using AOT;
namespace UnityEngine.XR.iOS
{
public struct UnityARObjectAnchorData
{
public IntPtr ptrIdentifier;
/**
The transformation matrix that defines the anchor's rotation, translation and scale in world coordinates.
*/
public UnityARMatrix4x4 transform;
public IntPtr referenceObjectNamePtr;
public IntPtr referenceObjectPtr;
};
public class ARObjectAnchor {
private UnityARObjectAnchorData objectAnchorData;
public ARObjectAnchor (UnityARObjectAnchorData uiad)
{
objectAnchorData = uiad;
}
public string identifier { get { return Marshal.PtrToStringAuto(objectAnchorData.ptrIdentifier); } }
public Matrix4x4 transform {
get {
Matrix4x4 matrix = new Matrix4x4 ();
matrix.SetColumn (0, objectAnchorData.transform.column0);
matrix.SetColumn (1, objectAnchorData.transform.column1);
matrix.SetColumn (2, objectAnchorData.transform.column2);
matrix.SetColumn (3, objectAnchorData.transform.column3);
return matrix;
}
}
public string referenceObjectName { get { return Marshal.PtrToStringAuto(objectAnchorData.referenceObjectNamePtr); } }
public IntPtr referenceObjectPtr { get { return objectAnchorData.referenceObjectPtr; } }
}
public partial class UnityARSessionNativeInterface
{
// Object Anchors
public delegate void ARObjectAnchorAdded(ARObjectAnchor anchorData);
public static event ARObjectAnchorAdded ARObjectAnchorAddedEvent;
public delegate void ARObjectAnchorUpdated(ARObjectAnchor anchorData);
public static event ARObjectAnchorUpdated ARObjectAnchorUpdatedEvent;
public delegate void ARObjectAnchorRemoved(ARObjectAnchor anchorData);
public static event ARObjectAnchorRemoved ARObjectAnchorRemovedEvent;
delegate void internal_ARObjectAnchorAdded(UnityARObjectAnchorData anchorData);
delegate void internal_ARObjectAnchorUpdated(UnityARObjectAnchorData anchorData);
delegate void internal_ARObjectAnchorRemoved(UnityARObjectAnchorData anchorData);
#if !UNITY_EDITOR && UNITY_IOS
#region Object Anchors
[MonoPInvokeCallback(typeof(internal_ARObjectAnchorAdded))]
static void _object_anchor_added(UnityARObjectAnchorData anchor)
{
if (ARObjectAnchorAddedEvent != null)
{
ARObjectAnchor arObjectAnchor = new ARObjectAnchor(anchor);
ARObjectAnchorAddedEvent(arObjectAnchor);
}
}
[MonoPInvokeCallback(typeof(internal_ARObjectAnchorUpdated))]
static void _object_anchor_updated(UnityARObjectAnchorData anchor)
{
if (ARObjectAnchorUpdatedEvent != null)
{
ARObjectAnchor arObjectAnchor = new ARObjectAnchor(anchor);
ARObjectAnchorUpdatedEvent(arObjectAnchor);
}
}
[MonoPInvokeCallback(typeof(internal_ARObjectAnchorRemoved))]
static void _object_anchor_removed(UnityARObjectAnchorData anchor)
{
if (ARObjectAnchorRemovedEvent != null)
{
ARObjectAnchor arObjectAnchor = new ARObjectAnchor(anchor);
ARObjectAnchorRemovedEvent(arObjectAnchor);
}
}
#endregion
[DllImport("__Internal")]
private static extern void session_SetObjectAnchorCallbacks(IntPtr nativeSession, internal_ARObjectAnchorAdded objectAnchorAddedCallback,
internal_ARObjectAnchorUpdated objectAnchorUpdatedCallback,
internal_ARObjectAnchorRemoved objectAnchorRemovedCallback);
#endif //!UNITY_EDITOR && UNITY_IOS
}
}