This is my animation playback method, there are two issues.
1.How to make the animation stop until the last frame after playing once when isLoop=false?
- When I specify the name of an animClipName animation clip, I cannot play the corresponding animation name. How do I set it up?
The animation structure is shown in the figure.
PlayAnim(animEntityName: "Book",animClipName: "Open",isLoop: false)
private func PlayAnim(animEntityName: String,animClipName: String? = nil,isLoop:Bool = true,transitionDuration: Double = 0.5){
guard let XR = XR else { return }
guard let entity = XR.findEntity(named: animEntityName) else {
return
}
let availableAnims = entity.availableAnimations
let targetAnimResource: AnimationResource?
if let clipName = animClipName {
targetAnimResource = availableAnims.first(where: { $0.name == clipName })
} else {
targetAnimResource = availableAnims.first
}
guard let animClip = targetAnimResource else {
return
}
let anim = animClip.repeat(count: isLoop ? 0 : 1)
entity.playAnimation(anim,transitionDuration: transitionDuration)
}