เอกสารนี้อธิบายวิธีย้ายข้อมูลเกมที่มีอยู่จาก SDK v1 ของ Games
ไปยัง SDK v2 ของ Games
ปลั๊กอิน Play Games สำหรับ Unity เวอร์ชัน 10 และก่อนหน้าใช้ SDK v1 ของ Games
ก่อนเริ่มต้น
ตรวจสอบว่าคุณได้ตั้งค่า Play Console และ
ติดตั้ง Unity Hub แล้ว
ดาวน์โหลดปลั๊กอิน Google Play Games สำหรับ Unity
หากต้องการใช้ประโยชน์จากฟีเจอร์ล่าสุดในบริการเกม Play ให้ดาวน์โหลดและ
ติดตั้งปลั๊กอินเวอร์ชันล่าสุด ดาวน์โหลดได้จากที่เก็บ gitHub
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();}
และอัปเดตเป็น
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).}}
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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)"]]