- To create components, resources, states, and traits the following rules must be applied, or the engine won't detect them.
- All modules must be Directory modules. Modules files or nested modules within a file won't be detected by the engine.
Modules must be public.
- Use
component
, state
, and resource
to mark structs and enums to be used by the engine.
- Use the
trait_bound
attribute macro to mark traits.
- Use the
trait_for
macro to assign a component to a trait.
- Implement the
SharedBehavior
trait to a component so they can be used in a hierarchy.
#[derive(Resource, Default)]
pub struct Renderer2dData {
pub(crate) data: Option<(Receiver<UnsafeRenderPass>, Sender<()>)>,
}
#[derive(Component)]
pub struct Sprite2D {
offset: [f32; 2],
texture: Asset<TextureAsset>,
bind_group_layout_asset: Asset<BindGroupLayoutAsset>,
bind_group: BindGroup,
vertex_buffer: Buffer,
}
#[trait_bound]
pub trait Mesh2D {
fn draw(&self, render_pass: &mut RenderPass);
fn update(&self, render_pass: &mut RenderPass);
fn name<'a>(&self) -> &'a str;
fn get_bind_group_layout_desc(&self) -> &Asset<BindGroupLayoutAsset>;
}
trait_for!(trait Mesh2D => Sprite2D);