pub trait Schematic: Reflect + Typed {
type Input: FromReflect + GetTypeRegistration;
// Required methods
fn apply(input: &Self::Input, context: &mut SchematicContext<'_, '_>);
fn remove(input: &Self::Input, context: &mut SchematicContext<'_, '_>);
// Provided method
fn preload_dependencies(
input: &mut Self::Input,
dependencies: &mut DependenciesBuilder<'_, '_>,
) { ... }
}
Expand description
Trait used to create a prototype schematic for modifying an entity (or the world in general).
This trait can either be manually implemented or derived.
See the module-level documentation for details.
§Example
use bevy::prelude::{Component, Reflect};
use bevy_proto_backend::schematics::{Schematic, SchematicContext};
#[derive(Component, Reflect)]
struct PlayerId(usize);
impl Schematic for PlayerId {
type Input = Self;
fn apply(input: &Self::Input, context: &mut SchematicContext) {
entity.insert(Self(input.0));
}
fn remove(input: &Self::Input, context: &mut SchematicContext) {
entity.remove::<Self>();
}
}
Required Associated Types§
Sourcetype Input: FromReflect + GetTypeRegistration
type Input: FromReflect + GetTypeRegistration
The input type to this schematic.
This acts as an intermediate between serialized schematic information and the actual schematic instance.
For types that don’t need an intermediate type, this can just be
set to Self
.
Required Methods§
Sourcefn apply(input: &Self::Input, context: &mut SchematicContext<'_, '_>)
fn apply(input: &Self::Input, context: &mut SchematicContext<'_, '_>)
Controls how this schematic is applied to the given entity.
Sourcefn remove(input: &Self::Input, context: &mut SchematicContext<'_, '_>)
fn remove(input: &Self::Input, context: &mut SchematicContext<'_, '_>)
Controls how this schematic is removed from the given entity.
Provided Methods§
Sourcefn preload_dependencies(
input: &mut Self::Input,
dependencies: &mut DependenciesBuilder<'_, '_>,
)
fn preload_dependencies( input: &mut Self::Input, dependencies: &mut DependenciesBuilder<'_, '_>, )
Allows dependency assets to be loaded when this schematic is loaded.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.