Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Play Games Services plugin for Godot Game Engine - Android

License

NotificationsYou must be signed in to change notification settings

cgisca/PGSGP

Repository files navigation

This is an Android Play Games Services plugin for Godot Game Engine 3.2.2+.

AndroidGodotPGSMIT license

If you want to use the old plugin version visitOld README file.

Supported features:

  • Sign-in/Sign out
  • Achievements
  • Leaderboards
  • Events
  • Player Stats
  • Player Info
  • Saved Games

Getting started

Before using this plugin please follow instructions onSetting Up Google Play Games Services official guide.

Set up

  • DownloadGodotPlayGamesServices.release.aar andGodotPlayGamesServices.gdap fromreleases page.
  • 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 accessingProject ->Export, Plugins section. Follow theimage.
  • Go to res://android/build directory. Add below lines toAndroidManifest.xml:
    <meta-dataandroid:name="com.google.android.gms.games.APP_ID"android:value="@string/app_id" />      <meta-dataandroid: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) createres ->values ->Strings.xml. Add below lines toStrings.xml:
<?xml version="1.0" encoding="utf-8"?><resources>    <stringname="app_id">ADD_YOUR_APP_ID</string></resources>

Replace ADD_YOUR_APP_ID with the app id that was generated after following instructions onSetting 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.

Generate plugin .aar file

If there is no release for your Godot version, you need to generate new plugin .aar file.
Follow these instruction: official documentation.

In short follow these steps:

  1. Download AAR library for Android plugins.

  2. Copy .aar file togodot-lib.release/ and rename it togodot-lib.release.aar

  3. Compile the project:

    Open command window andcd intoPGSGP direcory and run command below

    • Windows:

      gradlew.bat assembleRelease

    • Linux:

      ./gradlew assembleRelease

  4. Copy the newly created .aar file to your plugin directory:

app/build/outputs/aar/GodotPlayGamesServices.release.aar to[your godot project]/android/plugins/

How to use

First step is plugin initialization

varplay_games_services# Check if plugin was added to the projectifEngine.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-upsvarshow_popups:=trueplay_games_services.init(show_popups)# For enabling saved games functionality use below initialization instead# play_games_services.initWithSavedGames(show_popups, "SavedGamesName")# Connect callbacks (Use only those that you need)play_games_services.connect("_on_sign_in_success",self,"_on_sign_in_success")# account_id: Stringplay_games_services.connect("_on_sign_in_failed",self,"_on_sign_in_failed")# error_code: intplay_games_services.connect("_on_sign_out_success",self,"_on_sign_out_success")# no paramsplay_games_services.connect("_on_sign_out_failed",self,"_on_sign_out_failed")# no paramsplay_games_services.connect("_on_achievement_unlocked",self,"_on_achievement_unlocked")# achievement: Stringplay_games_services.connect("_on_achievement_unlocking_failed",self,"_on_achievement_unlocking_failed")# achievement: Stringplay_games_services.connect("_on_achievement_revealed",self,"_on_achievement_revealed")# achievement: Stringplay_games_services.connect("_on_achievement_revealing_failed",self,"_on_achievement_revealing_failed")# achievement: Stringplay_games_services.connect("_on_achievement_incremented",self,"_on_achievement_incremented")# achievement: Stringplay_games_services.connect("_on_achievement_incrementing_failed",self,"_on_achievement_incrementing_failed")# achievement: Stringplay_games_services.connect("_on_achievement_info_loaded",self,"_on_achievement_info_loaded")# achievements_json : Stringplay_games_services.connect("_on_achievement_info_load_failed",self,"_on_achievement_info_load_failed")play_games_services.connect("_on_leaderboard_score_submitted",self,"_on_leaderboard_score_submitted")# leaderboard_id: Stringplay_games_services.connect("_on_leaderboard_score_submitting_failed",self,"_on_leaderboard_score_submitting_failed")# leaderboard_id: Stringplay_games_services.connect("_on_game_saved_success",self,"_on_game_saved_success")# no paramsplay_games_services.connect("_on_game_saved_fail",self,"_on_game_saved_fail")# no paramsplay_games_services.connect("_on_game_load_success",self,"_on_game_load_success")# data: Stringplay_games_services.connect("_on_game_load_fail",self,"_on_game_load_fail")# no paramsplay_games_services.connect("_on_create_new_snapshot",self,"_on_create_new_snapshot")# name: Stringplay_games_services.connect("_on_player_info_loaded",self,"_on_player_info_loaded")# json_response: Stringplay_games_services.connect("_on_player_info_loading_failed",self,"_on_player_info_loading_failed")play_games_services.connect("_on_player_stats_loaded",self,"_on_player_stats_loaded")# json_response: Stringplay_games_services.connect("_on_player_stats_loading_failed",self,"_on_player_stats_loading_failed")

After what plugin was initialized you can use supported features

Sign-in / Sign out

Sign-in
play_games_services.signIn()# Callbacks:func_on_sign_in_success(account_id:String)->void:passfunc_on_sign_in_failed(error_code:int)->void:pass
Sign out
play_games_services.signOut()# Callbacks:func_on_sign_out_success():passfunc_on_sign_out_failed():pass
Check if signed in
varis_signed_in:bool=play_games_services.isSignedIn()

Achievements

Unlock Achievement
play_games_services.unlockAchievement("ACHIEVEMENT_ID")# Callbacks:func_on_achievement_unlocked(achievement:String):passfunc_on_achievement_unlocking_failed(achievement:String):pass
Increment Achievement
varstep=1play_games_services.incrementAchievement("ACHIEVEMENT_ID",step)# Callbacks:func_on_achievement_incremented(achievement:String):passfunc_on_achievement_incrementing_failed(achievement:String):pass
Set Achievement Steps
varsteps=3play_games_services.setAchievementSteps("ACHIEVEMENT_ID",steps)# Callbacks:func_on_achievement_steps_set(achievement:String):passfunc_on_achievement_steps_setting_failed(achievement:String):pass
Reveal Achievement
play_games_services.revealAchievement("ACHIEVEMENT_ID")# Callbacks:func_on_achievement_revealed(achievement:String):passfunc_on_achievement_revealing_failed(achievement:String):pass
Show Achievements List
play_games_services.showAchievements()
Load Achievement info
play_games_services.loadAchievementInfo(false)# forceReload# Callbacks:func_on_achievement_info_load_failed(event_id:String):passfunc_on_achievement_info_loaded(achievements_json:String):varachievements=parse_json(achievements_json)# The returned JSON contains an array of achievement info items.# Use the following keys to access the fieldsforainachievements:a["id"]# Achievement IDa["name"]a["description"]a["state"]# unlocked=0, revealed=1, hidden=2 (for the current player)a["type"]# standard=0, incremental=1a["xp"]# Experience gain when unlocked# Steps only available for incremental achievementsifa["type"]==1:a["current_steps"]# Users current progressa["total_steps"]# Total steps to unlock achievement

Leaderboards

Submit leaderboard score
varscore=1234play_games_services.submitLeaderBoardScore("LEADERBOARD_ID",score)# Callbacks:func_on_leaderboard_score_submitted(leaderboard_id:String):passfunc_on_leaderboard_score_submitting_failed(leaderboard_id:String):pass
Show leaderboard
play_games_services.showLeaderBoard("LEADERBOARD_ID")play_games_services.showAllLeaderBoards()

Events

Submit event
varincrement_by:=2play_games_services.submitEvent("EVENT_ID",increment_by)# Callbacks:func_on_event_submitted(event_id:String):passfunc_on_event_submitted_failed(event_id:String):pass
Load events
# Load all eventsplay_games_services.loadEvents()# Or load events by given idsplay_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_jsonvaravailable_events=parse_json(events_array)# Iterate through the events_list to retrieve data for specific eventsforeventinavailable_events:varevent_id=event["id"]# you can get event id using 'id' keyvarevent_name=event["name"]# you can get event name using 'name' keyvarevent_desc=event["description"]# you can get event name using 'description' keyvarevent_img=event["imgUrl"]# you can get event name using 'imgUrl' keyvarevent_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

Player Stats

varforce_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):varstats_dictionary:Dictionary=parse_json(stats)# Using below keys you can retrieve data about a player’s in-game activitystats_dictionary["avg_session_length"]# Average session lengthstats_dictionary["days_last_played"]# Days since last playedstats_dictionary["purchases"]# Number of purchasesstats_dictionary["sessions"]# Number of sessionsstats_dictionary["session_percentile"]# Session percentilestats_dictionary["spend_percentile"]# Spend percentilefunc_on_player_stats_loading_failed():pass

Player Info

play_games_services.loadPlayerInfo()# Callbacks:func_on_player_info_loaded(info):varinfo_dictionary:Dictionary=parse_json(info)# Using below keys you can retrieve player’s infoinfo_dictionary["display_name"]info_dictionary["name"]info_dictionary["title"]info_dictionary["player_id"]info_dictionary["hi_res_image_url"]info_dictionary["icon_image_url"]info_dictionary["banner_image_landscape_url"]info_dictionary["banner_image_portrait_url"]# Also you can get level info for the playervarlevel_info_dictionary=info_dictionary["level_info"]level_info_dictionary["current_xp_total"]level_info_dictionary["last_level_up_timestamp"]varcurrent_level_dictionary=level_info_dictionary["current_level"]current_level_dictionary["level_number"]current_level_dictionary["max_xp"]current_level_dictionary["min_xp"]varnext_level_dictionary=level_info_dictionary["next_level"]next_level_dictionary["level_number"]next_level_dictionary["max_xp"]next_level_dictionary["min_xp"]func_on_player_info_loading_failed():pass

Saved Games

Save game snapshot
vardata_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():passfunc_on_game_saved_fail():pass
Load game snapshot
play_games_services.loadSnapshot("SNAPSHOT_NAME")# Callbacks:func_on_game_load_success(data):vargame_data:Dictionary=parse_json(data)varname=game_data["name"]varage=game_data["age"]#...func_on_game_load_fail():pass
Show saved snapshots screen
varallow_add_button:=truevarallow_delete_button:=truevarmax_saved_games_snapshots:=5varsaved_games_screen_title:="TITLE"play_games_services.showSavedGames(saved_games_screen_title,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):vargame_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")

Troubleshooting

Checkadb logcat for debuging.To filter only Godot messages use next command:adb logcat -s godot


[8]ページ先頭

©2009-2025 Movatter.jp