如何检查父 SCNNode 是否包含子 SCNNode

How to check if a parent SCNNode contains a child SCNNode

在 UIKit 中,我可以检查一个视图是否是另一个视图的子视图:

if !childView.isDescendant(of: parentView) {

    parentView.addSubview(childView)

} else {

    childView.removeFromSuperview()
}

对于 SCNNode 什么是 .isDescendant(of: ) 的等价物,所以我可以用 SCNNode 做同样的事情:

if !childNode.???(of: parentNode) {

    parentNode.addChildNode(childNode)

} else {

    childNode.removeFromParentNode()
}

它是 childNodes.contains(),你可以像这样使用它:

if !parentNode.childNodes.contains(yourChildNode) {

    parentNode.addChildNode(yourChildNode)

} else {

    yourChildNode.removeFromParentNode()
}