Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/app/plugin_group.rs
6592 views
1
//! Demonstrates the creation and registration of a custom plugin group.
2
//! [`PluginGroup`]s are a way to group sets of plugins that should be registered together.
3
4
use bevy::{app::PluginGroupBuilder, prelude::*};
5
6
fn main() {
7
App::new()
8
.add_plugins((
9
// Two PluginGroups that are included with bevy are DefaultPlugins and MinimalPlugins
10
DefaultPlugins,
11
// Adding a plugin group adds all plugins in the group by default
12
HelloWorldPlugins,
13
))
14
// You can also modify a PluginGroup (such as disabling plugins) like this:
15
// .add_plugins(
16
// HelloWorldPlugins
17
// .build()
18
// .disable::<PrintWorldPlugin>()
19
// .add_before::<PrintHelloPlugin>(
20
// bevy::diagnostic::LogDiagnosticsPlugin::default(),
21
// ),
22
// )
23
.run();
24
}
25
26
/// A group of plugins that produce the "hello world" behavior
27
pub struct HelloWorldPlugins;
28
29
impl PluginGroup for HelloWorldPlugins {
30
fn build(self) -> PluginGroupBuilder {
31
PluginGroupBuilder::start::<Self>()
32
.add(PrintHelloPlugin)
33
.add(PrintWorldPlugin)
34
}
35
}
36
37
struct PrintHelloPlugin;
38
39
impl Plugin for PrintHelloPlugin {
40
fn build(&self, app: &mut App) {
41
app.add_systems(Update, print_hello_system);
42
}
43
}
44
45
fn print_hello_system() {
46
info!("hello");
47
}
48
49
struct PrintWorldPlugin;
50
51
impl Plugin for PrintWorldPlugin {
52
fn build(&self, app: &mut App) {
53
app.add_systems(Update, print_world_system);
54
}
55
}
56
57
fn print_world_system() {
58
info!("world");
59
}
60
61