Crates.io | bevy_ui_3d |
lib.rs | bevy_ui_3d |
version | 0.2.0 |
source | src |
created_at | 2023-10-22 03:58:18.268062 |
updated_at | 2023-11-10 22:42:10.865459 |
description | A UI plugin to enable 3d interactions |
homepage | |
repository | https://github.com/jebradbury39/bevy_ui_extended |
max_upload_size | |
id | 1010384 |
size | 112,301 |
This library provides a simple way to tag game objects as UI elements. You can then write queries on UI interactions for these elements.
Bevy Version | bevy_ui_3d version |
---|---|
^0.11.3 | ^0.1.0 |
^0.12.0 | ^0.2.0 |
You can look at the examples folder for practical uses of this crate, but to get started, you can simply do the following when setting up your app and scene:
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use bevy_ui_3d::{Interaction3d, Ui3dElementBundle, Ui3dPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(Ui3dPlugin::default())
.add_startup_system(setup)
.run();
}
fn setup(mut commands: Commands) {
// ... other setup code
// add a 3d gameobject with UI interactions
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
Ui3dElementBundle {
// the collider is needed, since the interaction is detected via raycasting
collider: Collider::cuboid(0.5, 0.5, 0.5),
..default()
},
));
}
The plugin comes with some configuration options you can set on startup, since you may not be interested in all of the interaction types, and too many interactions can be noisy.
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use bevy_ui_3d::{Interaction3d, Ui3dElementBundle, Ui3dPlugin, PluginConfig};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(Ui3dPlugin {
config: PluginConfig {
hover_enabled: false,
hover_point_enabled: false,
press_enabled: true,
press_point_enabled: false,
}
})
.add_startup_system(setup)
.run();
}