pub trait Condition<Marker>: Condition<Marker> {
// Provided methods
fn and_then<M, C>(
self,
and_then: C
) -> CombinatorSystem<AndThenMarker, Self::System, <C as IntoSystem<(), bool, M>>::System>
where C: Condition<M> { ... }
fn or_else<M, C>(
self,
or_else: C
) -> CombinatorSystem<OrElseMarker, Self::System, <C as IntoSystem<(), bool, M>>::System>
where C: Condition<M> { ... }
}
Expand description
A system that determines if one or more scheduled systems should run.
Implemented for functions and closures that convert into System<In=(), Out=bool>
with read-only parameters.
Provided Methods§
fn and_then<M, C>(
self,
and_then: C
) -> CombinatorSystem<AndThenMarker, Self::System, <C as IntoSystem<(), bool, M>>::System>where
C: Condition<M>,
fn and_then<M, C>( self, and_then: C ) -> CombinatorSystem<AndThenMarker, Self::System, <C as IntoSystem<(), bool, M>>::System>where C: Condition<M>,
Returns a new run condition that only returns true
if both this one and the passed and_then
return true
.
The returned run condition is short-circuiting, meaning
and_then
will only be invoked if self
returns true
.
Examples
ⓘ
use bevy_ecs::prelude::*;
#[derive(Resource, PartialEq)]
struct R(u32);
app.add_system(
// The `resource_equals` run condition will panic since we don't initialize `R`,
// just like if we used `Res<R>` in a system.
my_system.run_if(resource_equals(R(0))),
);
Use .and_then()
to avoid checking the condition.
app.add_system(
// `resource_equals` will only get run if the resource `R` exists.
my_system.run_if(resource_exists::<R>().and_then(resource_equals(R(0)))),
);
Note that in this case, it’s better to just use the run condition resource_exists_and_equals
.
fn or_else<M, C>(
self,
or_else: C
) -> CombinatorSystem<OrElseMarker, Self::System, <C as IntoSystem<(), bool, M>>::System>where
C: Condition<M>,
fn or_else<M, C>( self, or_else: C ) -> CombinatorSystem<OrElseMarker, Self::System, <C as IntoSystem<(), bool, M>>::System>where C: Condition<M>,
Returns a new run condition that returns true
if either this one or the passed or_else
return true
.
The returned run condition is short-circuiting, meaning
or_else
will only be invoked if self
returns false
.
Examples
use bevy_ecs::prelude::*;
#[derive(Resource, PartialEq)]
struct A(u32);
#[derive(Resource, PartialEq)]
struct B(u32);
app.add_system(
// Only run the system if either `A` or `B` exist.
my_system.run_if(resource_exists::<A>().or_else(resource_exists::<B>())),
);