// // RedSpheresImmersiveView.swift // TestFlickeringBetweenImmersiveSpaces // import SwiftUI import RealityKit import RealityKitContent struct RedSpheresImmersiveView: View { @Environment(AppModel.self) var appModel var body: some View { RealityView { content, attachments in // Add the initial RealityKit content if let immersiveContentEntity = try? await Entity(named: "RedSpheres", in: realityKitContentBundle) { immersiveContentEntity.position = [0.0, 0.1, -2.5] content.add(immersiveContentEntity) guard let showYellowSpheresButton = attachments.entity(for: "ShowYellowSpheres") else { assertionFailure("missing attachment") return } showYellowSpheresButton.position = [0.0, 1, -2.5] showYellowSpheresButton.scale = scaleForAttachements content.add(showYellowSpheresButton) } } update: { content, attachments in } placeholder: { ProgressView() } attachments: { Attachment(id: "ShowYellowSpheres") { Button { // dismissCurrnt and open next immersive space appModel.immersiveSpaceID = "YellowSpheres" } label: { Text("Show YellowSpheres") } } } } } #Preview(immersionStyle: .mixed) { RedSpheresImmersiveView() .environment(AppModel()) }