Crates.io | bevy_ios_gamecenter |
lib.rs | bevy_ios_gamecenter |
version | 0.2.0 |
source | src |
created_at | 2024-05-05 12:30:45.259057 |
updated_at | 2024-07-11 17:44:55.861892 |
description | Bevy Plugin and Swift Package to provide access to iOS native GameKit (Gamecenter) from inside Bevy Apps |
homepage | |
repository | https://github.com/rustunit/bevy_ios_gamecenter |
max_upload_size | |
id | 1230199 |
size | 33,374 |
Bevy Plugin and Swift Package to provide access to iOS native GameKit (Gamecenter) from inside Bevy Apps It uses Swift-Bridge to auto-generate the glue code and transport datatypes.
Demo from our game using this crate: zoolitaire.com
See also bevy_ios_iap, bevy_ios_notifications, bevy_ios_alerts, bevy_ios_review & bevy_ios_impact
Add GameKit
framework:
Go to File
-> Add Package Dependencies
and paste https://github.com/rustunit/bevy_ios_gamecenter.git
into the search bar on the top right:
Note:
The rust crate used must be exactly the same version as the Swift Package.
I suggest using a specific version (like 0.2.0
in the screenshot) to make sure to always use binary matching versions!
cargo add bevy_ios_gamecenter
or
# always pin to the same exact version you also of the Swift package
bevy_ios_gamecenter = { version = "=0.2.0" }
Initialize Bevy Plugin:
// request auth right on startup
app.add_plugins(IosGamecenterPlugin::new(true));
fn bevy_system() {
bevy_ios_gamecenter::achievements_reset();
// update achievement progress, 100 % will complete it
bevy_ios_gamecenter::achievement_progress("id".into(),100.);
bevy_ios_gamecenter::leaderboards_score(
"raking id".into(),
// score
1,
// context
2,
);
// open gamecenter view (leaderboard)
bevy_ios_gamecenter::trigger_view(view_states::LEADERBOARDS);
// save arbitrary binary buffer as a savegame
bevy_ios_gamecenter::save_game("test".into(), vec![1, 2, 3].as_slice());
// request list of `IosGCSaveGame`
bevy_ios_gamecenter::fetch_save_games();
// based on result of above `fetch_save_games` request
let save_game = IosGCSaveGame {..}
bevy_ios_gamecenter::load_game(save_game);
}
Process Response Events from iOS back to us in Rust:
fn process_gamecenter_events(
mut events: EventReader<IosGamecenterEvents>,
) {
for e in events.read() {
match e {
IosGamecenterEvents::SaveGames(response) => todo!(),
IosGamecenterEvents::Player(player) => todo!(),
IosGamecenterEvents::Authentication(response) => todo!(),
IosGamecenterEvents::SavedGame(response) => todo!(),
IosGamecenterEvents::LoadGame(response) => todo!(),
IosGamecenterEvents::AchievementProgress(response) => todo!(),
IosGamecenterEvents::AchievementsReset(response) => todo!(),
IosGamecenterEvents::LeaderboardScoreSubmitted(response) => todo!(),
}
}
}
bevy | bevy_ios_gamecenter |
---|---|
0.14 | 0.2,main |
0.13 | 0.1 |
All code in this repository is dual-licensed under either:
at your option. This means you can select the license you prefer.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.