Google Play Games plugin for Unity

repository·master·Indexed 25 days ago

https://github.com/playgameservices/play-games-plugin-for-unity

A plugin (version 2.1.0) that allows developers to integrate Google Play Games services, including achievements, leaderboards, cloud saves, events, and nearby connections, into Unity games via Unity's Social interface. It provides support for Android and includes guidance on Proguard configuration, Play Console project setup, and internal testing via Android App Bundles.

Tokens
1.4K
Snippets
1
Records
9
Agent score
87%

What's inside Google Play Games plugin for Unity

  1. Configure Google Play Games Plugin in Unity

    master

    Connect your Play Developer Console configuration to your Unity project using the following steps:

    1. Get AndroidManifest.xml: In the Play Developer Console, go to Grow > Play Games Services > Setup and Management > Configuration and copy the AndroidManifest.xml content.
    2. Android Setup: In Unity, go to Window > Google Play Games > Setup > Android Setup. Paste the XML into the provided text area.
    3. Constants Class: In the Constants class name field, enter the full namespace and class name (e.g., SmokeTest.Scripts.GPGSIds).
    4. Nearby Connections: Go to Window > Google Play games > Setup > Nearby Connections Setup and paste your package name.
  2. Configure Proguard to decrease APK size

    master

    You can reduce your APK size by using Proguard to remove unused Play Games Services code. This works alongside Unity's Managed Code Stripping.

    1. Navigate to File > Build Settings > Player Settings and select the Publishing Settings section.
    2. Set Minify > Release to Proguard.
    3. Enable User Proguard File.
    4. Copy the content from scripts/proguard.txt into Assets/Plugins/Android/proguard-user.txt.
  3. Use the plugin without overriding the default Social platform

    master

    By default, calling PlayGamesPlatform.Activate makes Google Play Games the implementation for all static calls to Social and Social.Active. If you need to access the original social platform implementation simultaneously (e.g., to submit achievements to two different platforms), follow these steps:

    1. Do not call PlayGamesPlatform.Activate.
    2. Instead of calling Social.MethodName, call PlayGamesPlatform.Instance.MethodName.
    3. Do not use Social.Active when interacting with Google Play Games; use PlayGamesPlatform.Instance instead.
        // Submit achievement to original default social platform
        Social.ReportProgress("MyAchievementIdHere", 100.0f, callback);
    
        // Submit achievement to Google Play
        PlayGamesPlatform.Instance.ReportProgress("MyGooglePlayAchievementIdHere", 100.0f, callback);
  4. Configure Unity Build Settings for Play Games Services

    master

    To ensure compatibility with the Google Play Games plugin, configure your Unity project with the following settings in the Build Settings and Player Settings menus:

    1. Platform: Open File > Build Settings, select Android, and click Switch Platform.
    2. Package Name: In Player Settings > Other Settings, set the Package Name to match your Play Developer Console package name.
    3. API Level: Select an appropriate Minimum API Level.
    4. Scripting Backend: Set Scripting Backend to IL2CPP.
    5. Architecture: Set Target Architectures to ARM64.
    6. Keystore & SHA1: In Player Settings > Publishing Settings, use the Keystore Manager to create or select a keystore. Ensure the SHA1 certificate from your keystore is pasted into the Credentials section of your Google Cloud Console project.
  5. Set up a Play Console Game Project for testing

    master

    To use the SmokeTest sample or any project with Play Games Services, you must first create a Play Console Project and a Google Cloud Project. After setup, you need to create specific resources in the Play Console to match the sample's requirements:

    Achievements

    Create the following four achievements with these exact names:

    1. achievementtoincrement: Must be an incremental achievement.
    2. achievementtounlock: Revealed and non-incremental.
    3. achievementtoreveal: Hidden and non-incremental.
    4. achievement_hidden_incremental: Hidden and incremental.

    Leaderboards

    • Create one leaderboard named leaders_in_smoketesting using default settings.

    Events

    • Create one event named smokingevent using default settings.
  6. Test Play Games Services via Internal Testing

    master

    To test your integration, you must register testers and upload an Android App Bundle (.aab):

    1. Register Testers: In the Play Developer Console, add tester email addresses under both:
      • Grow > Play Games Services > Setup and Management > Testers
      • Release > Testing > Internal Testing > Testers
    2. Build .aab: In Unity, go to File > Build Settings, check the box Build App Bundle (Google Play), and click Build.
    3. Upload: Upload the resulting .aab file to Release > Testing > Internal Testing in the Play Console.
  7. Select Snapshot UI Status Codes

    master

    When using the Play Games Services snapshot selection UI, the operation returns a status code. These codes correspond to the SelectUIStatus enum in the Unity ISavedGameClient.cs interface.

    Common status codes include:

    • 1 (SELECT_UI_STATUS_GAME_SELECTED): A game snapshot was successfully selected.
    • 2 (SELECT_UI_STATUS_USER_CLOSED_UI): The user closed the selection UI without selecting a snapshot.
    • -1 (SELECT_UI_STATUS_INTERNAL_ERROR): An internal error occurred.
    • -3 (SELECT_UI_STATUS_AUTHENTICATION_ERROR): An authentication error occurred (e.g., reconnection required).
    • -5 (SELECT_UI_STATUS_UI_BUSY): The UI is currently busy.