Social.localUser.LoadFriends((success)=>{Debug.Log("Friends loaded OK: "+ok));foreach(IUserProfilepinSocial.localUser.friends){Debug.Log(p.userName+" is a friend");}
PlayGamesPlatform.Instance.GetLastLoadFriendsStatus((status)=>{// Check for consentif(status==LoadFriendsStatus.ResolutionRequired){// Ask for resolution.}});
PlayGamesPlatform.Instance.AskForLoadFriendsResolution((result)=>{if(result==UIStatus.Valid){// User agreed to share friends with the game. Reload friends.}else{// User doesn’t agree to share the friends list.}});
PlayGamesPlatform.Instance.LoadFriends(pageSize,forceReload,(status)=>{// Check if the call is successful and if there are more friends to load.});PlayGamesPlatform.Instance.LoadMoreFriends(pageSize,(status)=>{// Check if there are more friends to load.});
[[["易于理解","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"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Friends in Unity games\n\nPlay Games Friends allows players to create and maintain a cross-games friends\nlist. You can request access to this friends list to help your players play your\ngame with their friends. See the\n[Friends concept page](https://developers.google.com/games/services/common/concepts/friends)\nfor more details on the friends system.\n\nBefore you start\n----------------\n\n- Set up your project and the Google Play Games plugin for Unity. For details, see\n the [Get started guide](/games/pgs/unity/unity-start).\n\n- See the [best practices guidelines](/games/pgs/quality#friends) for\n instructions on the best way to implement these APIs.\n\nSee the\n[best practices guidelines](/games/pgs/quality#friends) for instructions on the\nbest way to implement these APIs.\n\nEnable friends\n--------------\n\nTo enable friends, use the following functions:\n\n- [View friends](https://github.com/playgameservices/play-games-plugin-for-unity#view-friends):\n Request access to a player's friends list, so you can add their play games\n friends to your in-game friends list.\n\n- [View a player profile](https://github.com/playgameservices/play-games-plugin-for-unity#view-a-player-profile):\n Let a player view the Play Games profile of another player. This is\n essential so a player knows who their friends are, and can connect to other\n Play Games players in your game. This will need to be tied to a UI element to\n trigger the popup. See the\n [friends guidelines](https://developers.google.com/games/services/checklist#friends)\n for details.\n\nView friends\n------------\n\nThere are two ways to load friends, either using the `ISocial` framework or\ndirectly with [PlayGamesPlatform](/games/services/unity/v2/api/class/google-play-games/play-games-platform).\n\n### Load friends with the ISocial framework\n\n Social.localUser.LoadFriends((success) =\u003e {\n Debug.Log(\"Friends loaded OK: \" + ok));\n foreach(IUserProfile p in Social.localUser.friends) {\n Debug.Log(p.userName + \" is a friend\");\n }\n\nHowever, this call will fail if the current player has not yet granted\npermission to the game to access this information. Use\n`GetLastLoadFriendsStatus` to check if `LoadFriends` failed due to missing\nconsent. \n\n PlayGamesPlatform.Instance.GetLastLoadFriendsStatus((status) =\u003e {\n // Check for consent\n if (status == LoadFriendsStatus.ResolutionRequired) {\n // Ask for resolution.\n }\n });\n\nA game can ask the current player to share the friends list by calling\n`AskForLoadFriendsResolution`. \n\n PlayGamesPlatform.Instance.AskForLoadFriendsResolution((result) =\u003e {\n if (result == UIStatus.Valid) {\n // User agreed to share friends with the game. Reload friends.\n } else {\n // User doesn't agree to share the friends list.\n }\n });\n\nThis function will show the appropriate platform-specific friends sharing UI.\nThis UI asks the player if they want to share their friends with the game.\n\n### Load friends with PlayGamesPlatform\n\nAnother way of loading friends is to use `LoadFriends` and `LoadMoreFriends`: \n\n PlayGamesPlatform.Instance.LoadFriends(pageSize, forceReload, (status) =\u003e {\n // Check if the call is successful and if there are more friends to load.\n });\n\n PlayGamesPlatform.Instance.LoadMoreFriends(pageSize, (status) =\u003e {\n // Check if there are more friends to load.\n });\n\nThe `pageSize` param represents the number of entries to request for this page.\nNote that if cached data already exists, the returned buffer may contain more\nthan this size. The buffer is guaranteed to contain at least this many entries\nif the collection contains enough records. If `forceReload` is set to `true`,\nthis call will clear any locally-cached data and attempt to fetch the latest\ndata from the server. This would commonly be used for actions like a user-\ninitiated refresh. Normally, this should be set to `false` to gain the\nadvantages of data caching.\n\nIf the callback returns `LoadFriendsStatus.LoadMore`, then there are more\nfriends to load. `LoadFriendsStatus.ResolutionRequired` signals that the user\nhas not shared the friends list and you can directly call\n`PlayGamesPlatform.Instance.AskForLoadFriendsResolution`.\n\n### Determine friends list visibility\n\nUse `PlayGamesPlatform.Instance.GetFriendsListVisibility` to check if the user\nhas shared the friends list with the game. Possible return statuses are:\n\n- `FriendsListVisibilityStatus.RequestRequired` indicates you must ask for\n consent.\n\n- `FriendsListVisibilityStatus.Visible` indicates that loading the friends list\n should succeed.\n\n- `FriendsListVisibilityStatus.Unknown` generally shouldn't happen. You can set\n `forceReload` to true to refresh the data.\n\n PlayGamesPlatform.Instance.GetFriendsListVisibility(forceReload, (friendsListVisibilityStatus) =\u003e {});\n\nView a player profile\n---------------------\n\nTo add or remove a player as a friend, use the show and compare profile\nfunction. This function triggers a bottom sheet dialog showing the Play Games\nprofile of the user; call the function with the player Id of the requested\nplayer. If the player and friend have in-game nicknames, use them in the call to\nadd more context to the profile UI: \n\n PlayGamesPlatform.Instance.ShowCompareProfileWithAlternativeNameHintsUI(\n mFirstFriendId, /* otherPlayerInGameName= */ null, /* currentPlayerInGameName= */ null,\n (result) =\u003e {\n // Profile comparison view has closed.\n });"]]