質問編集履歴
2
誤字を直しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -156,7 +156,7 @@
|
|
156
156
|
|
157
157
|
追記:AddObjectAnchor(ARObjectAnchor arObjectAnchor)内の
|
158
158
|
|
159
|
-
objectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position, rotation);をobjectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position
|
159
|
+
objectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position, rotation);をobjectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position + Vector3.up * 2, rotation);に変えても生成されるオブジェクトの位置が変わりませんでした。。
|
160
160
|
|
161
161
|
|
162
162
|
|
1
記載コードを増やしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,144 @@
|
|
1
1
|
```C#
|
2
2
|
|
3
|
+
using System.Collections;
|
4
|
+
|
5
|
+
using System.Collections.Generic;
|
6
|
+
|
7
|
+
using UnityEngine;
|
8
|
+
|
9
|
+
using UnityEngine.XR.iOS;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
public class GenerateObjectAnchor : MonoBehaviour
|
14
|
+
|
15
|
+
{
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
[SerializeField]
|
20
|
+
|
21
|
+
private ARReferenceObjectAsset referenceObjectAsset;
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
[SerializeField]
|
26
|
+
|
27
|
+
private GameObject prefabToGenerate;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
private GameObject objectAnchorGO;
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
// Use this for initialization
|
36
|
+
|
37
|
+
void Start () {
|
38
|
+
|
39
|
+
UnityARSessionNativeInterface.ARObjectAnchorAddedEvent += AddObjectAnchor;
|
40
|
+
|
41
|
+
UnityARSessionNativeInterface.ARObjectAnchorUpdatedEvent += UpdateObjectAnchor;
|
42
|
+
|
43
|
+
UnityARSessionNativeInterface.ARImageAnchorRemovedEvent += RemoveObjectAnchor;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
void AddObjectAnchor(ARObjectAnchor arObjectAnchor)
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
Debug.Log ("object anchor added");
|
56
|
+
|
57
|
+
if (arObjectAnchor.referenceObjectName == referenceObjectAsset.objectName) {
|
58
|
+
|
3
|
-
Vector3 position = UnityARMatrixOps.GetPosition (arObjectAnchor.transform);
|
59
|
+
Vector3 position = UnityARMatrixOps.GetPosition (arObjectAnchor.transform);
|
60
|
+
|
61
|
+
//ARObjectAnchorからpositionを取得する
|
4
62
|
|
5
63
|
Quaternion rotation = UnityARMatrixOps.GetRotation (arObjectAnchor.transform);
|
6
64
|
|
65
|
+
//ARObjectAnchorからrotationを取得する
|
66
|
+
|
67
|
+
|
68
|
+
|
7
69
|
objectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position, rotation);
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
void UpdateObjectAnchor(ARObjectAnchor arObjectAnchor)
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
Debug.Log ("object anchor added");
|
82
|
+
|
83
|
+
if (arObjectAnchor.referenceObjectName == referenceObjectAsset.objectName) {
|
84
|
+
|
85
|
+
objectAnchorGO.transform.position = UnityARMatrixOps.GetPosition (arObjectAnchor.transform);
|
86
|
+
|
87
|
+
objectAnchorGO.transform.rotation = UnityARMatrixOps.GetRotation (arObjectAnchor.transform);
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
void RemoveObjectAnchor(ARImageAnchor arImageAnchor)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
Debug.Log ("object anchor removed");
|
102
|
+
|
103
|
+
if (objectAnchorGO) {
|
104
|
+
|
105
|
+
GameObject.Destroy (objectAnchorGO);
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
void OnDestroy()
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
UnityARSessionNativeInterface.ARObjectAnchorAddedEvent -= AddObjectAnchor;
|
120
|
+
|
121
|
+
UnityARSessionNativeInterface.ARObjectAnchorUpdatedEvent -= UpdateObjectAnchor;
|
122
|
+
|
123
|
+
UnityARSessionNativeInterface.ARImageAnchorRemovedEvent -= RemoveObjectAnchor;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
// Update is called once per frame
|
132
|
+
|
133
|
+
void Update () {
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
8
142
|
|
9
143
|
```
|
10
144
|
|
@@ -20,4 +154,10 @@
|
|
20
154
|
|
21
155
|
|
22
156
|
|
157
|
+
追記:AddObjectAnchor(ARObjectAnchor arObjectAnchor)内の
|
158
|
+
|
159
|
+
objectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position, rotation);をobjectAnchorGO = Instantiate<GameObject> (prefabToGenerate, position, rotation) + Vector3.up * 2;に変えても生成されるオブジェクトの位置が変わりませんでした。。
|
160
|
+
|
161
|
+
|
162
|
+
|
23
163
|
よろしくお願いします!
|