Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dokumen ini menjelaskan cara memigrasikan game yang ada dari SDK game v1
ke SDK game v2.
Plugin Layanan Game Play untuk Unity, versi 10 dan yang lebih lama, menggunakan SDK game v1.
Sebelum memulai
Pastikan Anda telah menyiapkan Konsol Play dan menginstal Unity Hub.
Download plugin Google Play Game untuk Unity
Untuk mendapatkan manfaat dari fitur terbaru di Layanan Game Play, download dan
instal versi plugin terbaru. Download dari repositori
GitHub.
Hapus folder yang ditandai di project Unity Anda
(klik untuk memperbesar).
Impor plugin baru ke project Unity Anda
Untuk mengimpor plugin ke project Unity Anda, ikuti langkah-langkah berikut:
Buka project game Anda.
Di Unity Hub, klik Assets > Import Package > Custom Package
untuk mengimpor file
unitypackage
yang didownload ke aset project Anda.
Pastikan platform build Anda saat ini disetel ke Android.
Di menu utama, klik File > Build Settings.
Pilih Android lalu klik Switch Platform.
Harus ada item menu baru di bagian Window > Google Play Game. Jika
tidak ada, muat ulang aset dengan mengklik Assets > Refresh, lalu
coba tetapkan platform build lagi.
Di Unity Hub, klik
File > Build Settings > Player Settings > Other Settings.
Di kotak Target API level, pilih versi.
Di kotak Scripting backend, masukkan IL2CPP.
Di kotak Target architectures, pilih nilai.
Catat nama paket package_name.Anda dapat menggunakan informasi ini nanti.
Ganti class inisialisasi PlayGamesClientConfiguration dengan class PlayGamesPlatform.Instance.Authenticate().
Inisialisasi dan aktivasi
PlayGamesPlatform
tidak diperlukan. Memanggil PlayGamesPlatform.Instance.Authenticate() akan mengambil
hasil login otomatis.
C#
Di Unity Hub, temukan file dengan class
PlayGamesClientConfiguration.
usingGooglePlayGames;usingGooglePlayGames.BasicApi;usingUnityEngine.SocialPlatforms;publicvoidStart(){PlayGamesClientConfigurationconfig=newPlayGamesClientConfiguration.Builder()// Enables saving game progress.EnableSavedGames()// Requests the email address of the player be available// will bring up a prompt for consent.RequestEmail()// Requests a server auth code be generated so it can be passed to an// associated backend server application and exchanged for an OAuth token.RequestServerAuthCode(false)// Requests an ID token be generated. This OAuth token can be used to// identify the player to other services such as Firebase..RequestIdToken().Build();PlayGamesPlatform.InitializeInstance(config);// recommended for debugging:PlayGamesPlatform.DebugLogEnabled=true;// Activate the Google Play Games platformPlayGamesPlatform.Activate();}
Lalu, perbarui menjadi:
usingGooglePlayGames;publicvoidStart(){PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);}internalvoidProcessAuthentication(SignInStatusstatus){if(status==SignInStatus.Success){// Continue with Play Games Services}else{// Disable your integration with Play Games Services or show a login// button to ask users to sign-in. Clicking it should call// PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).}}
Pop-up, papan peringkat, dan pencapaian ditampilkan dengan benar dan
konsisten pada berbagai ukuran dan orientasi layar di
antarmuka pengguna (UI) Layanan game Play.
Opsi logout tidak terlihat di UI Layanan game Play.
Pastikan Anda dapat mengambil ID Pemain dengan berhasil, dan jika berlaku, kemampuan sisi server berfungsi seperti yang diharapkan.
Jika game menggunakan autentikasi sisi server, uji alur
requestServerSideAccess secara menyeluruh. Pastikan server menerima kode autentikasi
dan dapat menukarnya dengan token akses.
Uji skenario keberhasilan dan kegagalan untuk error jaringan, skenario client ID yang tidak valid.
Jika game Anda menggunakan salah satu fitur berikut, uji fitur tersebut untuk memastikan bahwa fitur tersebut berfungsi sama seperti sebelum migrasi:
Papan Peringkat: Kirim skor dan lihat papan peringkat. Periksa peringkat dan tampilan nama serta skor pemain yang benar.
Pencapaian: Buka kunci pencapaian dan verifikasi bahwa pencapaian tersebut dicatat dan ditampilkan dengan benar di UI Play Game.
Game Tersimpan: Jika game menggunakan game tersimpan, pastikan penyimpanan dan pemuatan progres game berfungsi dengan lancar. Hal ini sangat penting untuk diuji di beberapa perangkat dan setelah update aplikasi.
Tugas pascamigrasi
Selesaikan langkah-langkah berikut setelah Anda bermigrasi ke SDK game v2.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# Migrate to Play Games Services v2 (Unity)\n\nThis document describes how to migrate existing games from the [games v1\nSDK](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/package-summary)\nto the [games v2\nSDK](https://developers.google.com/android/reference/com/google/android/gms/games/package-summary).\nThe Play Games plugin for Unity, versions 10 and earlier, uses the games v1 SDK.\n\nBefore you begin\n----------------\n\n- Make sure that you have already set up Play Console and installed the Unity Hub.\n\nDownload the Google Play Games plugin for Unity\n-----------------------------------------------\n\nTo benefit from the latest features in the Play Games Services, download and\ninstall the latest plugin version. Download it from the [gitHub\nrepository](https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/current-build).\n\nRemove the old plugin\n---------------------\n\nIn the Unity Hub, remove the following folders or files. \n\n```text\nAssets/GooglePlayGames\n\nAssets/GeneratedLocalRepo/GooglePlayGames\n\nAssets/Plugins/Android/GooglePlayGamesManifest.androidlib\n\nAssets/Plugins/Android\n```\n[](/static/images/games/pgs/unityfolders.png) Remove the highlighted folders in your Unity project (click to enlarge).\n\nImport the new plugin to your Unity project\n-------------------------------------------\n\nTo import the plugin to your Unity project, follow these steps:\n\n1. Open your game project.\n2. In the Unity Hub, click **Assets \\\u003e Import Package \\\u003e Custom Package** to import the downloaded [`unitypackage`](https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/current-build) file into your project's assets.\n3. Make sure that your current build platform is set to **Android**.\n\n 1. In the main menu, click **File \\\u003e Build Settings**.\n\n 2. Select **Android** and click **Switch Platform**.\n\n 3. There should be a new menu item under **Window \\\u003e Google Play Games** . If\n there isn't, refresh the assets by clicking **Assets \\\u003e Refresh** and\n then try setting the build platform again.\n\n4. In the Unity Hub, click\n **File \\\u003e Build Settings \\\u003e Player Settings \\\u003e Other Settings**.\n\n5. In the **Target API level** box, select a version.\n\n6. In the **Scripting backend** box, enter `IL2CPP`.\n\n7. In the **Target architectures** box, select a value.\n\n8. Note the package name \u003cvar translate=\"no\"\u003epackage_name\u003c/var\u003e.You can use this information\n later.\n\n The player settings in your Unity project.\n9. [Copy the Android resources from Play Console](/games/pgs/unity/unity-start#copy-android-resources)\n\n10. [Add the Android resources to your Unity project](/games/pgs/unity/unity-start#set-up-unity-project)\n\nUpdate automatic sign-in code\n-----------------------------\n\nReplace the `PlayGamesClientConfiguration` initialization class with the\n`PlayGamesPlatform.Instance.Authenticate()` class.\nThe initialization and activation of\n[`PlayGamesPlatform`](/games/services/unity/v2/api/class/google-play-games/play-games-platform)\nis not required. Calling `PlayGamesPlatform.Instance.Authenticate()` fetches the\nresult of automatic sign-in. \n\n### C#\n\nIn the Unity Hub, locate the files with\n`PlayGamesClientConfiguration` class. \n\n using GooglePlayGames;\n using GooglePlayGames.BasicApi;\n using UnityEngine.SocialPlatforms;\n\n public void Start() {\n PlayGamesClientConfiguration config =\n new PlayGamesClientConfiguration.Builder()\n // Enables saving game progress\n .EnableSavedGames()\n // Requests the email address of the player be available\n // will bring up a prompt for consent\n .RequestEmail()\n // Requests a server auth code be generated so it can be passed to an\n // associated backend server application and exchanged for an OAuth token\n .RequestServerAuthCode(false)\n // Requests an ID token be generated. This OAuth token can be used to\n // identify the player to other services such as Firebase.\n .RequestIdToken()\n .Build();\n\n PlayGamesPlatform.InitializeInstance(config);\n // recommended for debugging:\n PlayGamesPlatform.DebugLogEnabled = true;\n // Activate the Google Play Games platform\n PlayGamesPlatform.Activate();\n }\n\nAnd update it to this: \n\n using GooglePlayGames;\n\n public void Start() {\n PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);\n }\n\n internal void ProcessAuthentication(SignInStatus status) {\n if (status == SignInStatus.Success) {\n // Continue with Play Games Services\n } else {\n // Disable your integration with Play Games Services or show a login\n // button to ask users to sign-in. Clicking it should call\n // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).\n }\n }\n\nChoose a social platform\n------------------------\n\nTo choose a social platform, see\n[choose a social platform](/games/pgs/unity/unity-start#choose-social-platform).\n\nRetrieve server authentication codes\n------------------------------------\n\nTo get server side access codes,\nsee [retrieve server authentication codes](/games/pgs/unity/unity-start#retrieve_server_authentication_codes).\n\nRemove sign-out code\n--------------------\n\nRemove the code for sign-out. Play Games Services no longer requires an in-game\nsign-out button.\n\nRemove the code shown in the following example: \n\n### C#\n\n // sign out\n PlayGamesPlatform.Instance.SignOut();\n\nTest your game\n--------------\n\nEnsure your game functions as designed by testing it. The tests you perform\ndepend on your game's features.\n\nThe following is a list of common tests to run.\n\n1. **Successful sign-in**.\n\n 1. Automatic sign-in works. The user should be signed in to\n Play Games Services upon launching the game.\n\n 2. The welcome popup is displayed.\n\n\n [](/static/images/games/pgs/welcometoast.png) Sample welcome popup (click to enlarge).\n\n \u003cbr /\u003e\n\n 3. Successful log messages are displayed. Run the following\n command in the terminal:\n\n ```bash\n adb logcat | grep com.google.android.\n ```\n\n A successful log message is shown in the following example: \n\n ```bash\n [$PlaylogGamesSignInAction$SignInPerformerSource@e1cdecc\n number=1 name=GAMES_SERVICE_BROKER\u003e], returning true for shouldShowWelcomePopup.\n [CONTEXT service_id=1 ]\n ```\n2. **Ensure UI component consistency**.\n\n 1. Pop ups, leaderboards, and achievements display correctly and\n consistently on various screen sizes and orientations in the\n Play Games Services user interface (UI).\n\n 2. Sign-out option is not visible in the Play Games Services\n UI.\n\n 3. Make sure you can successfully retrieve Player ID, and if applicable,\n server-side capabilities work as expected.\n\n 4. If the game uses server-side authentication, thoroughly test the\n `requestServerSideAccess` flow. Ensure the server receives the auth code\n and can exchange it for an access token.\n Test both success and failure scenarios for network errors, invalid\n `client ID` scenarios.\n\nIf your game was using any of the following features, test them to ensure that\nthey work the same as before the migration:\n\n- **Leaderboards**: Submit scores and view leaderboards. Check for the correct ranking and display of player names and scores.\n- **Achievements**: Unlock achievements and verify they are correctly recorded and displayed in the Play Games UI.\n- **Saved Games**: If the game uses saved games, ensure that saving and loading the game progress works flawlessly. This is particularly critical to test across multiple devices and after app updates.\n\nPost migration tasks\n--------------------\n\nComplete the following steps after you have migrated to games v2 SDK.\n\n1. [Use Play App Signing](/games/pgs/unity/unity-start#create-test-release)\n\n2. [Create an AAB file](/games/pgs/unity/unity-start#create_an_aab_file)\n\n3. [Create an internal testing release](/games/pgs/unity/unity-start#create_an_internal_testing_release)\n\n4. [Verify your App signing credentials](/games/pgs/unity/unity-start#set-up-app-signin)"]]