-
Notifications
You must be signed in to change notification settings - Fork 36
Control Entities
For the sake of all these examples, the Simple heading will create an Entity with no custom properties or callbacks, and for Functional, imagine there is a ModelEntity
in the scene which we can reference from the variable adjustmentCuboid
.
By default all RealityUI Entities are quite large. This is used to standardize the sizes so that you always know what to expect. For example, all UI thumbs are spheres with a diameter of 1 meter, which is 1 unit in RealityKit, ± any padding adjustments. All RealityUI Entities face [0, 0, -1]
by default. To have them point at the user camera, or .zero
, you can use the .look(at:,from:,relativeTo:)
method like so: .look(at: .zero, from: [0, 0, 1])
. Or if you want it to turn around straight away if you've positioned it at [0, 0, -1]
, set the orientation to simd_quatf(angle: .pi, axis: [0, 1, 0])
. Using the .look() method works here by setting the at:
value to the direction the button should be used from.
Add a 3D toggle to your RealityKit app, to easily toggle something on or off in your scene.
let newSwitch = RUISwitch()
let newSwitch = RUISwitch(
RUI: RUIComponent(respondsToLighting: true),
changedCallback: { mySwitch in
differentEntity.model?.materials = [
SimpleMaterial(
color: mySwitch.isOn ? .green : .red,
isMetallic: false
)
]
}
)
RUIStepper is used to increment or decrement a value.
let stepper = RUIStepper(upTrigger: { _ in
print("positive tapped")
}, downTrigger: { _ in
print("negative tapped")
})
An interactive track to represent an interpolated value.
let newSlider = RUISlider()
let newSlider = RUISlider(
slider: SliderComponent(startingValue: 0.9, isContinuous: true)
) { (slider, _) in
differentEntity.scale.x = slider.value + 0.1
}
RUIButton is used to initiate a specified action. The action here will only trigger if the gesture begins on a button, and also ends on the same button. This is similar to the touchUpInside UIControl Event.
let button = RUIButton(updateCallback: { myButton in
myButton.buttonColor = .systemGreen
})