# Objective
```rust
// Currently:
builder.add_after::<FooPlugin, _>(BarPlugin);
// After this PR:
builder.add_after::<FooPlugin>(BarPlugin);
```
This removes some weirdness and better parallels the rest of the
`PluginGroupBuilder` API.
## Solution
Define a helper method `type_id_of_val` to use in `.add_before` and
`.add_after` instead of `TypeId::of::<T>` (which requires the plugin
type to be nameable, preventing `impl Plugin` from being used).
## Testing
Ran `cargo run -p ci lints` successfully.
## Migration Guide
Removed second generic from `PluginGroupBuilder` methods: `add_before`
and `add_after`.
```rust
// Before:
DefaultPlugins
.build()
.add_before::<WindowPlugin, _>(FooPlugin)
.add_after::<WindowPlugin, _>(BarPlugin)
// After:
DefaultPlugins
.build()
.add_before::<WindowPlugin>(FooPlugin)
.add_after::<WindowPlugin>(BarPlugin)
```
---------
Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
//! Demonstrates the creation and registration of a custom plugin group.
|
|
//! [`PluginGroup`]s are a way to group sets of plugins that should be registered together.
|
|
|
|
use bevy::{app::PluginGroupBuilder, prelude::*};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
// Two PluginGroups that are included with bevy are DefaultPlugins and MinimalPlugins
|
|
DefaultPlugins,
|
|
// Adding a plugin group adds all plugins in the group by default
|
|
HelloWorldPlugins,
|
|
))
|
|
// You can also modify a PluginGroup (such as disabling plugins) like this:
|
|
// .add_plugins(
|
|
// HelloWorldPlugins
|
|
// .build()
|
|
// .disable::<PrintWorldPlugin>()
|
|
// .add_before::<PrintHelloPlugin>(
|
|
// bevy::diagnostic::LogDiagnosticsPlugin::default(),
|
|
// ),
|
|
// )
|
|
.run();
|
|
}
|
|
|
|
/// A group of plugins that produce the "hello world" behavior
|
|
pub struct HelloWorldPlugins;
|
|
|
|
impl PluginGroup for HelloWorldPlugins {
|
|
fn build(self) -> PluginGroupBuilder {
|
|
PluginGroupBuilder::start::<Self>()
|
|
.add(PrintHelloPlugin)
|
|
.add(PrintWorldPlugin)
|
|
}
|
|
}
|
|
|
|
struct PrintHelloPlugin;
|
|
|
|
impl Plugin for PrintHelloPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(Update, print_hello_system);
|
|
}
|
|
}
|
|
|
|
fn print_hello_system() {
|
|
info!("hello");
|
|
}
|
|
|
|
struct PrintWorldPlugin;
|
|
|
|
impl Plugin for PrintWorldPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(Update, print_world_system);
|
|
}
|
|
}
|
|
|
|
fn print_world_system() {
|
|
info!("world");
|
|
}
|