问题
In the SpriteKit editor, I can assign a custom class to an SKNode, like so:
However, I can't seem to find the equivalent functionality in the SceneKit editor. Does it even exist? And if I can't set a custom class for an SCNNode, is there a reason the feature isn't there, or has the Xcode team just not gotten around to it? (In other words, should I file a radar?)
回答1:
You can't do it in the scene editor. And you probably shouldn't do it at all. You'll have to implement your own serialization code (so that SCNScene
loading works correctly). And all of the methods for searching nodes (by name, hit test, within a volume) return SCNNode
, so you'll be forever casting your results.
Per Apple developers, SCNScene
is not meant to be subclassed, and I think that extends to SCNNode
. Write an extension instead.
See:
- Trouble subclassing SCNScene
- Subclassing SCNNode
- Subclassing SCNScene and SceneKit Editor
来源:https://stackoverflow.com/questions/44921638/scenekit-editor-set-custom-class-for-node