Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added visionOS snippets to README #26

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 59 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,36 @@ RealityUI also has a collection of components for interfacing with any Entity th

## Requirements

- iOS 13 or macOS 10.15
- Swift 5.4
- Xcode 12
- iOS 13, macOS 10.15 or visionOS 1.0
- Swift 5.8
- Xcode 13

## Content

- [Installation](#installation)
- [Usage](#usage)
- [Control Entities](#control-entities)
- [Gestures](#gestures)
- [Animations](#animations)
- [Text](#text)
- [More](#more)
- [RealityUI Wiki](https://github.com/maxxfrazer/RealityUI/wiki)
- [Documentation](https://maxxfrazer.github.io/RealityUI/documentation/realityui/)
- [Example Project](https://github.com/maxxfrazer/RealityUI/tree/main/RealityUI%2BExamples)
- [RealityUI](#realityui)
- [Requirements](#requirements)
- [Content](#content)
- [Installation](#installation)
- [Swift Package Manager](#swift-package-manager)
- [Usage](#usage)
- [Registering RealityUI Components](#registering-realityui-components)
- [Activating Gestures](#activating-gestures)
- [visionOS](#visionos)
- [iOS/macOS](#iosmacos)
- [Control Entities](#control-entities)
- [RUISwitch](#ruiswitch)
- [RUIStepper](#ruistepper)
- [RUISlider](#ruislider)
- [RUIButton](#ruibutton)
- [Gestures](#gestures)
- [Drag](#drag)
- [Turn](#turn)
- [Tap](#tap)
- [Animations](#animations)
- [Spin](#spin)
- [Shake](#shake)
- [Text](#text)
- [More](#more)

## Installation

Expand All @@ -68,6 +82,38 @@ All components used in RealityUI must be registered before they are used, simply

#### Activating Gestures

##### visionOS

With visionOS, gestures can be enabled on a RealityView using `View/addRUIDragGesture()` or `View/addRUITapGesture()` modifiers, or by adding the gestures directly with `.gesture(RUIDragGesture())` or `.gesture(RUITapGesture())`. The RealityView might look something like this:

```swift
RealityView { content in
let swtch = RUISwitch()
swtch.scale = .init(repeating: 0.1)
content.add(swtch)
}.addRUIDragGesture()
```

> The above snippet adds an interactive switch/toggle to the scene.

This gesture works for any entity with RUIDragComponent, for example:

```swift
RealityView { content in
let movable = try! await ModelEntity(named: "toy_biplane")
movable.generateCollisionShapes(recursive: false)

movable.components.set(RUIDragComponent(type: .move(nil)))
movable.components.set(InputTargetComponent())

content.add(movable)
}.addRUIDragGesture()
```

![moving a biplane around in vision pro simulator](media/biplane_drag.gif)

##### iOS/macOS

Enabling RealityUI gestures can be doen by calling `RealityUI.enableGestures(.all, on: ARView)`, with `ARView` being your instance of an [ARView](https://developer.apple.com/documentation/realitykit/arview) object.

RUISlider, RUISwitch, RUIStepper and RUIButton all use ``RUIDragComponent``, which requires `.ruiDrag`. If you are adding elements that use the component `RUITapComponent` you can use the gesture `.tap`.
Expand Down
Binary file added media/biplane_drag.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.