SwiftUI и RealityKit запускают действие из Reality Composer - PullRequest
1 голос
/ 12 января 2020

Я пытаюсь обновить информацию о ТЕКСТЕ после касания из реальности Composer. func textTouch() работает, я получаю распечатку при отладке.

self.newText = "new info"

Как я могу обновить представление? Почему переменная состояния остается только внутри структуры?

import SwiftUI
import RealityKit

struct ContentView : View {

    @State var newText: String = "Touch add more info"

    var body: some View {

        return VStack {
            ARViewContainer().edgesIgnoringSafeArea(.all)
            Text(newText)
        }
    }
}

struct ARViewContainer: UIViewRepresentable {

    func makeUIView(context: Context) -> ARView {

        let arView = ARView(frame: .zero)

        // Load the "Box" scene from the Reality File
        let birdAnchor = try! Cube.loadCube()

       let sunInfoAction = birdAnchor.actions.allActions.filter({$0.identifier == "cubeTap"}).first
       sunInfoAction?.onAction = { entity in

            self.textTouch()  
        }     
        arView.scene.anchors.append(birdAnchor)
        return arView 
    }

    func updateUIView(_ uiView: ARView, context: Context) {}

    func textTouch()  {
        print("working")
        self.newText = "new info"  
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif
...