2021-07-27 20:21:06 +00:00
|
|
|
use crate::App;
|
2020-01-21 04:10:40 +00:00
|
|
|
use std::any::Any;
|
|
|
|
|
2022-04-05 22:36:02 +00:00
|
|
|
/// A collection of Bevy app logic and configuration.
|
2020-08-09 23:13:04 +00:00
|
|
|
///
|
2022-04-05 22:36:02 +00:00
|
|
|
/// Plugins configure an [`App`]. When an [`App`] registers a plugin,
|
|
|
|
/// the plugin's [`Plugin::build`] function is run.
|
2020-08-08 03:22:17 +00:00
|
|
|
pub trait Plugin: Any + Send + Sync {
|
2022-01-06 23:16:47 +00:00
|
|
|
/// Configures the [`App`] to which this plugin is added.
|
2021-07-27 20:21:06 +00:00
|
|
|
fn build(&self, app: &mut App);
|
2022-04-05 22:36:02 +00:00
|
|
|
/// Configures a name for the [`Plugin`] which is primarily used for debugging.
|
2020-04-05 21:12:14 +00:00
|
|
|
fn name(&self) -> &str {
|
2020-05-01 08:02:13 +00:00
|
|
|
std::any::type_name::<Self>()
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
2020-01-21 04:10:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 22:36:02 +00:00
|
|
|
/// A type representing an unsafe function that returns a mutable pointer to a [`Plugin`].
|
|
|
|
/// It is used for dynamically loading plugins.
|
|
|
|
///
|
|
|
|
/// See `bevy_dynamic_plugin/src/loader.rs#dynamically_load_plugin`.
|
2020-08-08 03:22:17 +00:00
|
|
|
pub type CreatePlugin = unsafe fn() -> *mut dyn Plugin;
|