Attribute Macro auto_init_resource

Source
#[auto_init_resource]
Expand description

Automatically initializes a resource in the Bevy App.

§Example (without generics)

use bevy::prelude::*;
use bevy_auto_plugin::auto_plugin::*;

#[auto_plugin(init_name=init)]
pub mod my_plugin {
    use super::*;

    #[auto_init_resource]
    #[derive(Resource, Default, Reflect)]
    #[reflect(Resource)]
    struct FooResource;

    // code gen:
    pub(super) fn init(app: &mut App) {  
        app.init_resource::<FooResource>();
    }
}

fn plugin(app: &mut App) {
    app.add_plugin(my_plugin::init)
}

§Example (with generics)

use bevy::prelude::*;
use bevy_auto_plugin::auto_plugin::*;

#[auto_plugin(init_name=init)]
pub mod my_plugin {
    use super::*;

    #[auto_init_resource(FooResourceWithGeneric<bool>)]
    #[derive(Resource, Default, Reflect)]
    #[reflect(Resource)]
    struct FooResourceWithGeneric<T>(T);

    // code gen:
    pub(super) fn init(app: &mut App) {  
        app.init_resource::<FooResourceWithGeneric<bool>>();
    }
}

fn plugin(app: &mut App) {
    app.add_plugin(my_plugin::init)
}