質問するログイン新規登録

質問編集履歴

1

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

2018/10/01 07:44

投稿

zzzzzz_la
zzzzzz_la

スコア8

title CHANGED
File without changes
body CHANGED
@@ -2,33 +2,7 @@
2
2
  例えば、(0f, 0f, 0f)から(0f, 0.46f, 0f)まで移動させたいとき下記にどのようなスクリプトを組み込めばいいか教えてください!
3
3
 
4
4
  ```C#
5
- using System.Collections;
6
- using System.Collections.Generic;
7
- using UnityEngine;
8
- using UnityEngine.XR.iOS;
9
-
10
- public class GenerateObjectAnchor : MonoBehaviour
11
- {
12
-
13
- [SerializeField]
14
- // これをつけておくことでUnity内に編集可能なフィールドとして出せる。
15
- // 用途はpublicと同じだが、SerializeFieldは他からの編集を受け付け無い。ミスを防ぐ。
16
- private ARReferenceObjectAsset referenceObjectAsset;
17
-
18
- [SerializeField]
19
- private GameObject prefabToGenerate;
20
-
21
- private GameObject objectAnchorGO;
22
-
23
- // Use this for initialization
24
- void Start () {
25
- UnityARSessionNativeInterface.ARObjectAnchorAddedEvent += AddObjectAnchor;
26
- UnityARSessionNativeInterface.ARObjectAnchorUpdatedEvent += UpdateObjectAnchor;
27
- UnityARSessionNativeInterface.ARImageAnchorRemovedEvent += RemoveObjectAnchor;
28
-
29
- }
30
-
31
- void AddObjectAnchor(ARObjectAnchor arObjectAnchor)
5
+ void AddObjectAnchor(ARObjectAnchor arObjectAnchor)
32
6
  {
33
7
  Debug.Log ("object anchor added");
34
8
  if (arObjectAnchor.referenceObjectName == referenceObjectAsset.objectName) {
@@ -42,40 +16,6 @@
42
16
  }
43
17
  }
44
18
 
45
- void UpdateObjectAnchor(ARObjectAnchor arObjectAnchor)
46
- {
47
- Debug.Log ("object anchor added");
48
- if (arObjectAnchor.referenceObjectName == referenceObjectAsset.objectName) {
49
- objectAnchorGO.transform.position = UnityARMatrixOps.GetPosition (arObjectAnchor.transform);
50
- // Vectorをメソッドとして扱うときはnewを忘れずに!
51
- objectAnchorGO.transform.rotation = UnityARMatrixOps.GetRotation (arObjectAnchor.transform);
52
- }
53
-
54
- }
55
-
56
- void RemoveObjectAnchor(ARImageAnchor arImageAnchor)
57
- {
58
- Debug.Log ("object anchor removed");
59
- if (objectAnchorGO) {
60
- GameObject.Destroy (objectAnchorGO);
61
- }
62
-
63
- }
64
-
65
- void OnDestroy()
66
- {
67
- UnityARSessionNativeInterface.ARObjectAnchorAddedEvent -= AddObjectAnchor;
68
- UnityARSessionNativeInterface.ARObjectAnchorUpdatedEvent -= UpdateObjectAnchor;
69
- UnityARSessionNativeInterface.ARImageAnchorRemovedEvent -= RemoveObjectAnchor;
70
-
71
- }
72
-
73
- // Update is called once per frame
74
- void Update () {
75
-
76
- }
77
- }
78
-
79
19
  ```
80
20
 
81
21
  よろしくお願いします!