5个不稳定版本
| 0.3.1 | 2022年11月25日 | 
|---|---|
| 0.3.0 | 2022年11月25日 | 
| 0.2.0 | 2022年8月23日 | 
| 0.1.1 | 2022年6月14日 | 
| 0.1.0 | 2022年6月14日 | 
#45 in #bevy-ui
450KB
bevy_ui_pointer_capture_detector
一个检测鼠标指针是否位于Bevy UI节点上的插件。
- 支持Bevy 0.9
用法
在你的Cargo.toml文件中,在[dependencies]部分添加
bevy_ui_pointer_capture_detector = "0.3"
这个例子绘制了一个红色的UI节点。每次更新时,它根据鼠标指针是否在红色节点上设置背景颜色
use bevy::prelude::*;
use bevy_ui_pointer_capture_detector::*;
fn setup(
    mut commands: Commands
) {
    commands
        .spawn(Camera2dBundle::default())
        .commands()
        .spawn(NodeBundle {
            style: Style {
                margin: UiRect { 
                    left: Val::Px(100.0), 
                    bottom: Val::Px(100.0), 
                    right: Val::Auto, 
                    top: Val::Auto 
                },
                size: Size { 
                    width: Val::Px(100.0), 
                    height: Val::Px(100.0) 
                },
                ..Default::default()
            },
            background_color: BackgroundColor(Color::RED),
            ..Default::default()
        });
}
fn is_pointer_captured(
    capture: Res<UiPointerCaptureStatus>,
    mut clear_color: ResMut<ClearColor>,
) {
    clear_color.0 = if capture.is_captured() {
            Color::DARK_GRAY
        } else {
            Color::WHITE
        };
}
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(BevyUiPointerCaptureDetectorPlugin)
        .add_startup_system(setup)
        .add_system(is_pointer_captured)
        .run();
}
示例
cargo run --example example
cargo run --example minimal
依赖关系
~18–34MB
~523K SLoC