我有一个SCNNode的子类“SCNNode”来向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类?
发布于 2017-05-05 11:08:34
只需将对象强制转换为您的子类:
// 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 {
…
}https://stackoverflow.com/questions/43792213
复制相似问题