我有一个SCNNode的子类“ExSCNNode”来向SCNNode添加更多属性和行为.
class ExSCNNode : SCNNode { ... }
我比使用ExSCNNode构建一个场景.
let testnode = ExSCNNode()
当测试场景时:
// check what nodes are tapped let p = gestureRecognize.location(in: scnView) let hitResults = scnView.hitTest(p,options: [:]) // check that we clicked on at least one object if hitResults.count > 0 { for hit in hitResults { let hitnode = hit.node ...
hitnode是SCNNode而不是ExSCNNode.
但我想让ExSCNNode访问高级功能.
如何访问子类而不是SCNNode类?
解决方法
只需将对象强制转换为子类:
// check what nodes are tapped let p = gestureRecognize.location(in: scnView) let hitResults = scnView.hitTest(p,options: [:]) for hit in hitResults { if let hitnode = hit.node as? ExSCNNode { … }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。