✂️
[Bevy] たくさんのコンポーネントをまとめる
Bevyでたくさんのコンポーネントを定義して、いろいろなところにコンポーネントがバラけてしまったので、一箇所にまとめるためにextra.rsというモジュールにコンポーネントを切り分けました。
main.rsでモジュールを登録しておけば、あとはhoge.rsでuseを使ってextra.rsで定義したコンポーネントを使えます。
変数でも定数でも構造体でもenumでも同じように切り分けられます。
extra.rs
#[derive(Component)]
pub struct Hoge1;
#[derive(Component)]
pub struct Hoge2;
#[derive(Component)]
pub struct Hoge3;
#[derive(Component)]
pub struct Hoge4;
// ...
main.rs
mod extra;
mod hoge;
hoge.rs
use crate::extra::{Hoge1, Hoge2, Hoge3, Hoge4};
// Do something with Hoge component
src
|- main.rs
|- hoge.rs
|- extra.rs
Discussion