2个不稳定版本
0.2.0 | 2024年7月5日 |
---|---|
0.1.0 | 2024年6月10日 |
在游戏开发中排名第1706
每月下载量:128次
17KB
150 代码行
bevy_activation
一个简单的HTTP客户端Bevy插件,适用于原生和WASM。
示例
use std::time::Duration;
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy_activation::{ActivationPlugin, ActiveState, TimeoutEvent};
fn main() {
App::new().add_plugins(MinimalPlugins.set(bevy::app::ScheduleRunnerPlugin::run_loop(
Duration::from_secs_f64(1.0 / 60.0),
)))
.add_plugins(LogPlugin::default())
.add_plugins(ActivationPlugin)
.add_systems(Startup, setup)
.add_systems(Update, (check_active, timeout_event, reactive_idle.run_if(time_passed(5.0))))
.run();
}
#[derive(Component)]
struct TestAlive(pub &'static str);
fn setup(mut commands: Commands) {
// this entity always active
commands.spawn((TestAlive("always alive component"), ActiveState::default()));
// this entity will be active for 2 seconds
commands.spawn((TestAlive("ttl 2 secs component"), ActiveState::new(Duration::from_secs(2))));
}
fn check_active(q: Query<(&TestAlive, &ActiveState)>) {
for (TestAlive(name), active_state) in q.iter() {
info!("'{}' active: {}", name, active_state.is_active());
}
}
fn timeout_event(mut timeout_event: EventReader<TimeoutEvent>) {
for timeout_ev in timeout_event.read() {
warn!("entity {:?} is idle", timeout_ev.0);
}
}
fn reactive_idle(mut q_idle: Query<&mut ActiveState>) {
for mut active_state in q_idle.iter_mut() {
if active_state.is_idle() {
active_state.toggle();
}
}
}
fn time_passed(t: f32) -> impl FnMut(Local<f32>, Res<Time>) -> bool {
move |mut timer: Local<f32>, time: Res<Time>| {
// Tick the timer
*timer += time.delta_seconds();
// Return true if the timer has passed the time
*timer >= t
}
}
支持的版本
bevy | bevy_activation |
---|---|
0.14 | 0.2 |
0.13 | 0.1 |
许可协议
双重许可,任选其一
这意味着当您在游戏中使用此crate时,您可以选择使用哪个许可证。
除非您明确声明,否则您有意提交给作品以包含在内的任何贡献,根据Apache-2.0许可证定义,将按上述方式双重许可,没有任何附加条款或条件。
依赖项
~12MB
~200K SLoC