如何正确获取子链接以访问 rcproject 中的文本实体?

问题描述 投票:0回答:1

我有一个包含文本实体的现实作曲家项目:

 '' : ScreenObject, children: 1
  ⟐ Transform
  ⟐ SynchronizationComponent
  ⟐ AnchoringComponent
  ▿ '' : AnchorEntity, children: 2
    ⟐ Transform
    ⟐ SynchronizationComponent
    ⟐ AnchoringComponent
    ▿ '' : Entity, children: 3
      ⟐ Transform
      ⟐ SynchronizationComponent
      ▿ 'textE' : Entity, children: 1
        ⟐ Transform
        ⟐ SynchronizationComponent
        ▿ 'EE1CDC29-88C9-4144-80EB-A2D03F51A8AC' : Entity, children: 1
          ⟐ Transform
          ⟐ SynchronizationComponent
          ▿ 'simpBld_root' : Entity, children: 1
            ⟐ Transform
            ⟐ SynchronizationComponent
            ▿ 'simpBld_text' : ModelEntity
              ⟐ Transform
              ⟐ ModelComponent
              ⟐ SynchronizationComponent
      ▿ 'imageE' : Entity, children: 1
        ⟐ Transform
        ⟐ SynchronizationComponent
        ▿ 'simpBld_root' : ModelEntity
          ⟐ Transform
          ⟐ ModelComponent
          ⟐ SynchronizationComponent
      ▿ 'screenE' : Entity, children: 1
        ⟐ Transform
        ⟐ SynchronizationComponent
        ▿ 'simpBld_root' : ModelEntity
          ⟐ Transform
          ⟐ ModelComponent
          ⟐ CollisionComponent
          ⟐ SynchronizationComponent
    ▿ 'Ground Plane' : Entity
      ⟐ PhysicsBodyComponent
      ⟐ Transform
      ⟐ CollisionComponent
      ⟐ SynchronizationComponent

在学习了各种教程、Apple Docs 和 Stackoverflow 查询(例如 Andy Jazz 的答案)之后,我可以访问项目中 textE 实体的一些属性:

override func viewDidLoad() {
    super.viewDidLoad()
    
    if let screenAnchor = try? Experience.loadScreenObject() {
        print(screenAnchor)
        
        let textEntity = screenAnchor.findEntity(named: "textE")
       
        print(textEntity!.scale)
     
        arView.scene.anchors.append(screenAnchor)
    }
}

但是文本内容似乎没有属性。我还找到了使用子链接来获取文本内容部分的教材 - 但是 - 我找不到教材来教我有关此子链接过程的知识: 我需要有多少个孩子来到我的文本实体,为什么? 我什么时候需要为 [孩子] 0 或 1?为什么?

如果有人能给我一些教材以及它与我上面的场景有何关系,我将不胜感激!

swift entity augmented-reality children realitykit
1个回答
0
投票

好的,我找到了这个问题的答案。一些相关但旧的答案明确指出该场景正在使用枚举结构。这帮助我了解了枚举结构中的层次结构

我需要的所有信息实际上都在我发布的 ScreenObject 枚举层次结构的输出中。

如果层次结构中的某个步骤只有 1 个子级,那么我使用 Children[0] 进入下一级;如果有 2 个孩子,那么我必须使用 Children[0] 或 Children[1] 等访问我需要的孩子。

尝试类似问题的旧答案时,我也感到困惑,但我的场景层次结构当然不同,或者现实作曲家中的实体结构也发生了变化。

所以现在我只是检查打印的层次结构,并小心地沿着树向下走,直到到达组件节点,然后可以访问 ModelComponent。

很可能这对大多数人来说都是微不足道的,对我来说也很尴尬,但我发布了答案,以防这个领域还有另一个初学者。

© www.soinside.com 2019 - 2024. All rights reserved.