banner
[面包]MrTwoC

[面包]MrTwoC

你好,欢迎来到这个基于区块链的个人博客 名字:面包 / MrTwoc 爱好:跑步(5/10KM)、咖啡、游戏(MMORPG、FPS、Minecraft、Warframe) 兴趣方向:Rust、区块链、网络安全、量子信息(量子计算)、游戏设计与开发
bilibili
steam
email
github

[0x05]Bevy-Plugin

Reference Article
One of Bevy's core principles is modularity. All Bevy engine features are implemented as plugins - collections of code used to modify applications. This includes internal features such as renderers, but the game itself is also implemented as a plugin! This allows developers to choose the features they want. Don't need UI? Don't register the UiPlugin. Want to build a headless server? Don't register the RenderPlugin.
This also means that you are free to replace any components you don't like. If you feel it's necessary, you are welcome to build your own UiPlugin, but if you think it's useful, consider contributing it to Bevy!
Those that are not contributed to Bevy but released separately are third-party plugins. These are useful and easy-to-use plugins created by other developers that can help you avoid reinventing the wheel. To use them, all you have to do is:

  1. Find third-party Bevy plugins (such as those on the assets page).
  2. Add them as dependencies to your Cargo.toml [dependencies].
  3. Import code definitions from the crate (like ) to add items to your workspace. use third_party::prelude::*;
  4. Add the plugins to your app (e.g. ). app.add_plugins(third_party_plugin)

However, most developers don't need a customized experience, they just need an easy "full engine" experience. For this, Bevy provides a set of DefaultPlugins.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .run();
}
cargo run

image.png
Next, implement a plugin yourself and print "Hello World!"

use bevy::prelude::*;

// To better organize, let's move all the "hello" logic into a plugin. To create a plugin, we just need to implement the Plugin interface. Add the following code to your file: main.rs
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Startup, hello_world);

    }
}

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, HelloPlugin))
        .run();
}

fn hello_world() {
    println!("HelloWorld!")
}
cargo run

image.png

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.