【问题标题】:Reality Composer – Failed to get the Notify trigger workingReality Composer – 无法让通知触发器工作
【发布时间】:2022-01-22 07:02:27
【问题描述】:

当我点击我在 Reality Composer 中创建的 Reality 文件中的对象时,只需尝试打印一个 hello。无法设置通知和应用内操作之间的链接。

import SwiftUI
import RealityKit

struct ContentView: View {
    var body: some View {
        ZStack{
            ARViewContainer()
            Text("Level 1")
        }
    }
}

struct ARViewContainer : UIViewRepresentable {
    func makeUIView(context: Context) -> ARView {
        let arView = ARView(frame: .zero)
        let yellowEntity = try! ModelEntity.load(named: "Yellow")
        let anchorEntity = AnchorEntity(plane: .horizontal)
        anchorEntity.addChild(yellowEntity)
        arView.scene.addAnchor(anchorEntity)
        yellowEntity.actions.Yellowtapped.onAction = handleTap(_:)
        func handleTap(_entity: Entity?){
            guard let entity = entity else {return}
            print("Hello")
        }
        return arView
    }
    func updateUIView(_ uiView: ARView, context: Context) {
    }
}

【问题讨论】:

    标签: swift swiftui augmented-reality realitykit reality-composer


    【解决方案1】:

    如果你使用.rcproject 一切都很好:

    struct ARViewContainer: UIViewRepresentable {
        
        func makeUIView(context: Context) -> ARView {
            
            let arView = ARView(frame: .zero)
            let scene = try! Experience.loadBox()
            
            scene.actions.notifier.onAction = printer
            
            let anchor = AnchorEntity(plane: .horizontal)
            anchor.addChild(scene)
            arView.scene.addAnchor(anchor)
            return arView
        }
        func updateUIView(_ uiView: ARView, context: Context) { }
        
        func printer(_ entity: Entity?) -> Void { print("Hello") }
    }
    

    附言

    不要忘记将 2 个动作合并在一起(在 Reality Composer 中)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 2021-08-28
      • 2023-02-02
      • 2013-12-25
      • 2021-07-31
      • 2015-09-30
      • 2013-11-04
      相关资源
      最近更新 更多