
bevy_platform_dirs
Expose the platform-dirs crate as a Bevy plugin.
Using standardized platform directories for your save data, cache files, generated configuration,
etc is both friendly to the user and makes an irrelevant decision easy.
Supported Bevy Versions
| Bevy |
bevy_platform_dirs |
| 0.18 |
0.18 |
Example
use bevy::prelude::*;
use bevy_platform_dirs::{PlatformDirs, PlatformDirsPlugin, PlatformDirsStep};
use std::fs;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(PlatformDirsPlugin::new("MyAppName"))
.add_systems(Startup, (setup_world.after(PlatformDirsStep::Startup), shutdown_test))
.run();
}
fn setup_world(dirs: Res<PlatformDirs>, mut commands: Commands) -> Result {
let mut path = dirs.app_dirs().state_dir.clone();
path.push("savefile.json");
let pos = if let Ok(fp) = fs::File::open(&path) {
serde_json::from_reader(fp)?
} else {
0.0
};
commands.spawn((Name::new("Player"), Transform::from_xyz(pos, pos, pos)));
Ok(())
}
fn shutdown_test(mut exit: MessageWriter<AppExit>) {
exit.write(AppExit::Success);
}