This is an Android Play Games Services plugin for Godot Game Engine 3.2.2+.
If you want to use the old plugin version visit Old README file.
- Sign-in/Sign out
- Achievements
- Leaderboards
- Events
- Player Stats
- Saved Games
Before using this plugin please follow instructions on Setting Up Google Play Games Services official guide.
- Download
GodotPlayGamesServices.release.aar
andGodotPlayGamesServices.gdap
from releases section. - Move the plugin configuration file (
GodotPlayGamesServices.gdap
) and the binary (GodotPlayGamesServices.release.aar
) downloaded from the previous step to the Godot project's res://android/plugins directory. - Enable plugin by accessing
Project
->Export
, Plugins section. Follow the image. - Go to res://android/build directory. Add below lines to
AndroidManifest.xml
:
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
- In the same res://android/build directory,(if it is not already created) create
res
->values
->Strings.xml
. Add below lines toStrings.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_id">ADD_YOUR_APP_ID</string>
</resources>
Replace ADD_YOUR_APP_ID with the app id that was generated after following instructions on Setting Up Google Play Games Services
Check demo project. In order demo project to work, replace ADD_YOUR_APP_ID with your own app id, and in Main.gd add your ids for achievements and leaderboards.
First step is plugin initialization
var play_games_services
# Check if plugin was added to the project
if Engine.has_singleton("GodotPlayGamesServices"):
play_games_services = Engine.get_singleton("GodotPlayGamesServices")
# Initialize plugin by calling init method and passing to it a boolean to enable/disable displaying game pop-ups
var enable_save_games := true # If you want to enable Saved Games functionality. true for enabling it. If enabled, it will require additional Google Drive API permission from the user.
play_games_services.init(show_popups)
# For enabling saved games functionality use below initialization instead
# play_games_services.initWithSavedGames(show_popups, "SavedGamesName")
After what plugin was initialized you can use supported features
play_games_services.signIn()
# Callbacks:
func _on_sign_in_success(account_id: String) -> void:
pass
func _on_sign_in_failed(error_code: int) -> void:
pass
play_games_services.signOut()
# Callbacks:
func _on_sign_out_success():
pass
func _on_sign_out_failed():
pass
play_games_services.unlockAchievement("ACHIEVEMENT_ID")
# Callbacks:
func _on_achievement_unlocked(achievement: String):
pass
func _on_achievement_unlocking_failed(achievement: String):
pass
var step = 1
play_games_services.incrementAchievement("ACHIEVEMENT_ID", step)
# Callbacks:
func _on_achievement_incremented(achievement: String):
pass
func _on_achievement_incrementing_failed(achievement: String):
pass
play_games_services.revealAchievement("ACHIEVEMENT_ID")
# Callbacks:
func _on_achievement_revealed(achievement: String):
pass
func _on_achievement_revealing_failed(achievement: String):
pass
play_games_services.showAchievements()
var score = 1234
play_games_services.submitLeaderBoardScore("LEADERBOARD_ID", score)
# Callbacks:
func _on_leaderboard_score_submitted(leaderboard_id: String):
pass
func _on_leaderboard_score_submitting_failed(leaderboard_id: String):
pass
play_games_services.showLeaderBoard("LEADERBOARD_ID")
play_games_services.showAllLeaderBoards()
var increment_by := 2
play_games_services.submitEvent("EVENT_ID", increment_by)
# Callbacks:
func _on_event_submitted(event_id: String):
pass
func _on_event_submitted_failed(event_id: String):
pass
# Load all events
play_games_services.loadEvents()
# Or load events by given ids
play_games_services.loadEventsById(["EVENT_ID_1", "EVENT_ID_2", ...])
# Callbacks:
# If there is at least one event, following callback will be triggered:
func _on_events_loaded(events_array):
# Parse received string json of events using parse_json
var available_events = parse_json(events_array)
# Iterate through the events_list to retrieve data for specific events
for event in available_events:
var event_id = event["id"] # you can get event id using 'id' key
var event_name = event["name"] # you can get event name using 'name' key
var event_desc = event["description"] # you can get event name using 'description' key
var event_img = event["imgUrl"] # you can get event name using 'imgUrl' key
var event_value = event["value"] # you can get event name using 'value' key
# Triggered if there are no events:
func _on_events_empty():
pass
# Triggered if something went wrong:
func _on_events_loading_failed():
pass
var force_refresh := true # If true, this call will clear any locally cached data and attempt to fetch the latest data from the server.
play_games_services.loadPlayerStats(force_refresh)
# Callbacks:
func _on_player_stats_loaded(stats):
var stats_dictionary: Dictionary = parse_json(stats)
# Using below keys you can retrieve data about a player’s in-game activity
stats_dictionary["avg_session_length"] # Average session length
stats_dictionary["days_last_played"] # Days since last played
stats_dictionary["purchases"] # Number of purchases
stats_dictionary["sessions"] # Number of sessions
stats_dictionary["session_percentile"] # Session percentile
stats_dictionary["spend_percentile"] # Spend percentile
func _on_player_stats_loading_failed():
pass
var data_to_save: Dictionary = {
"name": "John",
"age": 22,
"height": 1.82,
"is_gamer": true
}
play_games_services.saveSnapshot("SNAPSHOT_NAME", to_json(data_to_save), "DESCRIPTION")
# Callbacks:
func _on_game_saved_success():
pass
func _on_game_saved_fail():
pass
play_games_services.loadSnapshot("SNAPSHOT_NAME")
# Callbacks:
func _on_game_load_success(data):
var game_data: Dictionary = parse_json(data)
var name = game_data["name"]
var age = game_data["age"]
#...
func _on_game_load_fail():
pass
var allow_add_button := true
var allow_delete_button := true
var max_saved_games_snapshots := 5
play_games_services.showSavedGames("SNAPSHOT_NAME", allow_add_button, allow_delete_button, max_saved_games_snapshots)
#Godot callback
# If user clicked on add new snapshot button on the screen with all saved snapshots, below callback will be triggered:
func _on_create_new_snapshot(name):
var game_data_to_save: Dictionary = {
"name": "John",
"age": 22,
"height": 1.82,
"is_gamer": true
}
play_games_services.save_snapshot(name, to_json(game_data_to_save), "DESCRIPTION")
Check adb logcat
for debuging.
To filter only Godot messages use next command:
adb logcat -s godot