我尝试在摄像机看不到ARImageAnchor时获取焦点实体,并在摄像机看到ARImageAnchor后移除,当摄像机未看到锚点时再次获取焦点。我使用了arView.session.delegate,但委托方法可能会调用一次,我不知道。怎么做呢?祝你今天愉快!
final class CameraViewController: UIViewController {
var focusEntity: FocusEntity! // (FocusEntity: Entity, HasAnchoring)
override func viewDidLoad() {
super.viewDidLoad()
// ...
focusEntity = FocusEntity(on: arView, style: .classic(color: .systemGray4))
arView.session.delegate = self
}
}
extension CameraViewController: ARSessionDelegate {
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
for anchor in anchors {
if let imageAnchor = anchor as? ARImageAnchor {
focusEntity.destroy()
focusEntity = nil
//... Obtain entity to image anchor
}
}
}
func session(_ session: ARSession, didUpdate frame: ARFrame) {
//... ???
}
}发布于 2021-09-27 08:40:49
我将创建一个AnchorEntity,它使用ARImageAnchor作为它的锚。然后,订阅AnchoredStateChanged事件,根据锚定状态打开和关闭FocusEntity。
我在这里写了关于订阅这样的活动的文章:
https://maxxfrazer.medium.com/realitykit-events-97964fa5b5c7
顺便说一句,如果您希望焦点实体重新出现,您可能希望在该实体上设置isEnabled,而不是每次都销毁并重新创建它。
https://stackoverflow.com/questions/69151189
复制相似问题