如何知道 AnchorEntity 动作序列何时完成?

How to know when an AnchorEntity Action Sequence is finished?

我有一个持续时间为 0.5 的 Action Sequence,然后在达到 0 秒时隐藏:

如何知道操作何时完成以便我可以将其从 scene 中删除? 无法做到这一点,我希望 AnchorEntity 有所不同。

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
    for anchor in anchors {
        if let anchorName = anchor.name, anchorName == "LaserBeam" {
            
            placeObject(named: anchorName, for: anchor)
        }
    }
}

func placeObject(named entityName: String, for anchor: ARAnchor) {
    do {
        
        let laserEntity = try ModelEntity.load(named: entityName)
        let anchorEntity = AnchorEntity(anchor: anchor)
        anchorEntity.addChild(laserEntity)

        arView.scene.addAnchor(anchorEntity)
        
    } catch let err as NSError {
        print(err.localizedDescription)
    }
}

您使用 subscribe(to:in:_:) or publisher(for:on: ) ) if you prefer Combine on your Scene and pass AnimationEvents.PlaybackCompleted 作为要订阅的事件。

此外,在使用 publisher 函数时,您可以使用任何 Combine 运算符,例如 filter(_:) 来订阅您想要的特定动画。