質問編集履歴

1

コードを簡易化しました。わかりづらくてすみません。。

2018/10/01 07:44

投稿

zzzzzz_la
zzzzzz_la

スコア8

test CHANGED
File without changes
test CHANGED
@@ -6,59 +6,7 @@
6
6
 
7
7
  ```C#
8
8
 
9
- using System.Collections;
10
-
11
- using System.Collections.Generic;
12
-
13
- using UnityEngine;
14
-
15
- using UnityEngine.XR.iOS;
16
-
17
-
18
-
19
- public class GenerateObjectAnchor : MonoBehaviour
20
-
21
- {
22
-
23
-
24
-
25
- [SerializeField]
26
-
27
- // これをつけておくことでUnity内に編集可能なフィールドとして出せる。
28
-
29
- // 用途はpublicと同じだが、SerializeFieldは他からの編集を受け付け無い。ミスを防ぐ。
30
-
31
- private ARReferenceObjectAsset referenceObjectAsset;
32
-
33
-
34
-
35
- [SerializeField]
36
-
37
- private GameObject prefabToGenerate;
38
-
39
-
40
-
41
- private GameObject objectAnchorGO;
42
-
43
-
44
-
45
- // Use this for initialization
46
-
47
- void Start () {
48
-
49
- UnityARSessionNativeInterface.ARObjectAnchorAddedEvent += AddObjectAnchor;
50
-
51
- UnityARSessionNativeInterface.ARObjectAnchorUpdatedEvent += UpdateObjectAnchor;
52
-
53
- UnityARSessionNativeInterface.ARImageAnchorRemovedEvent += RemoveObjectAnchor;
54
-
55
-
56
-
57
- }
58
-
59
-
60
-
61
- void AddObjectAnchor(ARObjectAnchor arObjectAnchor)
9
+ void AddObjectAnchor(ARObjectAnchor arObjectAnchor)
62
10
 
63
11
  {
64
12
 
@@ -86,74 +34,6 @@
86
34
 
87
35
 
88
36
 
89
- void UpdateObjectAnchor(ARObjectAnchor arObjectAnchor)
90
-
91
- {
92
-
93
- Debug.Log ("object anchor added");
94
-
95
- if (arObjectAnchor.referenceObjectName == referenceObjectAsset.objectName) {
96
-
97
- objectAnchorGO.transform.position = UnityARMatrixOps.GetPosition (arObjectAnchor.transform);
98
-
99
- // Vectorをメソッドとして扱うときはnewを忘れずに!
100
-
101
- objectAnchorGO.transform.rotation = UnityARMatrixOps.GetRotation (arObjectAnchor.transform);
102
-
103
- }
104
-
105
-
106
-
107
- }
108
-
109
-
110
-
111
- void RemoveObjectAnchor(ARImageAnchor arImageAnchor)
112
-
113
- {
114
-
115
- Debug.Log ("object anchor removed");
116
-
117
- if (objectAnchorGO) {
118
-
119
- GameObject.Destroy (objectAnchorGO);
120
-
121
- }
122
-
123
-
124
-
125
- }
126
-
127
-
128
-
129
- void OnDestroy()
130
-
131
- {
132
-
133
- UnityARSessionNativeInterface.ARObjectAnchorAddedEvent -= AddObjectAnchor;
134
-
135
- UnityARSessionNativeInterface.ARObjectAnchorUpdatedEvent -= UpdateObjectAnchor;
136
-
137
- UnityARSessionNativeInterface.ARImageAnchorRemovedEvent -= RemoveObjectAnchor;
138
-
139
-
140
-
141
- }
142
-
143
-
144
-
145
- // Update is called once per frame
146
-
147
- void Update () {
148
-
149
-
150
-
151
- }
152
-
153
- }
154
-
155
-
156
-
157
37
  ```
158
38
 
159
39