Reality Composer – 无法让通知触发器工作

Posted

技术标签:

【中文标题】Reality Composer – 无法让通知触发器工作【英文标题】:Reality Composer – Failed to get the Notify trigger working 【发布时间】: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) 
    

【问题讨论】:

【参考方案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 中)。

【讨论】:

以上是关于Reality Composer – 无法让通知触发器工作的主要内容,如果未能解决你的问题,请参考以下文章

我如何在RealityKit中访问Reality Composer的模型组件?

Reality Capture 输出文件以伪造查看器

无法将图像文件添加到新的照片场景 [autodesk-forge] API Reality Capture

composer无法self-update

PHP Composer更新“无法分配内存”错误(使用Laravel 4)

自定义包的 Composer 安装路径