Hello everyone, I have just started learning the development and learning of visionPro app. I have a scene called Scene, and inside it is an object called Sphere. I want to add a drag animation to this Sphere alone. I follow the code below to achieve it. But my Sphere cannot actually be dragged in the Apple simulator. What is the reason?
struct ContentView: View {
@State var enlarge = false
@State var offset: Point3D = .zero
@State var sphereEntity: Entity?
var body: some View {
RealityView { content in
if let scene = try? await Entity(named: "Scene", in: realityKitContentBundle) {
content.add(scene)
sphereEntity = content.entities.first?.findEntity(named: "Sphere")
sphereEntity?.components.set(InputTargetComponent(allowedInputTypes: .all))
}
}.gesture(DragGesture().targetedToEntity(sphereEntity ?? Entity()).onChanged({ value in
print(value.location3D)
sphereEntity?.position = value.convert(value.location3D, from: .local, to: sphereEntity?.parent! ?? Entity())
}))
.gesture(SpatialTapGesture().targetedToAnyEntity().onEnded({ _ in
print("Ssssssss")
})) .onAppear() {
}
}
}
Post
Replies
Boosts
Views
Activity
I have no idea how to set the realityView at the bottom-trailing edge of the volume. Could someone help me?
var body: some View {
RealityView { content in
if let scene = try? await Entity(named: "Volume", in: realityKitContentBundle) {
content.add(scene)
bookEntity = scene.findEntity(named: "Book")
crossEntity = scene.findEntity(named: "Cross")
}
}
.toolbar {
if (isShowToolbar) {
ToolbarItemGroup(placement: .bottomOrnament) {
Text("The toolbar is shown")
}
}
}
.gesture(tapGesture())
}
I have tried several ways, but none work, including adding a zstack to align with the bottum.
For now, the bounds of my volume are as follows:
Can anyone tell me how to achieve the effect in the picture below. The two Views actually belong to the same Window, but they are separate effects instead of contained effects.