Reality Composerで名前をつける
表示するオブジェクトをダブルクリックして設定画面を表示し名前をつける。下図の場合「hako」という名前をつけている。
Swiftで名前を得る
オブジェクトをタップするとデバッグ画面に「hako」と表示される。
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
boxAnchor.actions.tapped.onAction=clickEvent(_:)
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
func clickEvent(_ entity: Entity?) {
guard let entity = entity else { return }
print(entity.name)
}
}
「tapped」はReality Composerで付けたビヘイビア。