Created
December 4, 2025 19:23
-
-
Save arthurschiller/d8011e8656414b4d09518e888f0375bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Odd Manipulation Component Behaviors | |
| struct ImmersiveView: View { | |
| var body: some View { | |
| RealityView { content in | |
| let box1 = ModelEntity( | |
| mesh: .generateBox(size: 0.5, cornerRadius: 0.01), | |
| materials: [ | |
| SimpleMaterial(color: .blue, isMetallic: true) | |
| ] | |
| ) | |
| box1.position = .init(x: 0, y: 1.2, z: -1.5) | |
| box1.name = "box1" | |
| content.add(box1) | |
| let box2 = ModelEntity( | |
| mesh: .generateBox(size: 0.5, cornerRadius: 0.01), | |
| materials: [ | |
| SimpleMaterial(color: .blue, isMetallic: true) | |
| ] | |
| ) | |
| box2.position = .init(x: 1.2, y: 1.2, z: -0.5) | |
| box2.name = "box2" | |
| content.add(box2) | |
| // Assigning a Manipulation Component to an entity will trigger SceneEvents.WillRemoveEntity which can't be intended?! | |
| // Observe the behavior below: | |
| // Immersive Space is opened -> Entity is added to scene -> ManipulationComponent get's asssigned -> SceneEvents.WillRemoveEntity is called for the entity that got the ManipulationComponent | |
| let _ = content.subscribe(to: SceneEvents.WillRemoveEntity.self) { event in | |
| print("Will Remove: \(event.entity.name)") | |
| } | |
| // weirdly this event subscription will be trigger for both of the entites with ManipulationComponent, not just the source entity (box1) | |
| let _ = content.subscribe(to: ManipulationEvents.WillBegin.self, on: box1) { event in | |
| print("Manipulation Will Begin: \(event.entity.name)") | |
| } | |
| ManipulationComponent.configureEntity(box1, allowedInputTypes: .all) | |
| box1.components.set(ManipulationComponent()) | |
| ManipulationComponent.configureEntity(box2, allowedInputTypes: .all) | |
| box2.components.set(ManipulationComponent()) | |
| print("Set Manipulation component!") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment