> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Friends lists

> Quickstart tutorial for building PlayFab friends lists in Unity, covering how to add, remove, and display friends plus link Steam, Facebook, and XBOX friends.

친구 목록은 플레이어가 서로 소통하는 능력을 향상시키는 훌륭한 기능입니다. 사용하기 쉽고 사용자에게 리더보드를 더욱 매력적으로 만들어 줍니다.

## 필수 구성 요소

### SDK: Unity

* `PlayFabSharedSettings` 개체에 타이틀 ID가 설정되어 있습니다.
* 프로젝트에서 사용자가 로그인할 수 있습니다.
* 타이틀에 등록된 사용자가 두 명 이상 있습니다.

## 친구 정보

타이틀의 모든 플레이어는 타이틀의 다른 어떤 플레이어와도 친구가 될 수 있습니다. 특히, PlayFab의 친구 관계는 일방향입니다.

**Albert**가 **Bob**을 친구로 추가하는 경우, **Bob**에게는 *어떠한* 승인 절차도 없습니다. 사실 **Bob**은 이를 알지 못할 수도 있습니다.

친구 관계가 *상호적*이려면 **Bob**도 별도로 **Albert**를 추가해야 합니다. 상호 규칙을 두고 싶다면, 필요한 경우 사용자 지정 게임 서버나 CloudScript 로직을 사용해 이러한 조건을 강제하는 것은 여러분 타이틀의 책임입니다.

플레이어가 Steam, Facebook 또는 XBOX Live 계정을 연결한 경우, 해당 플랫폼별 친구들도 해당 친구들이 여러분 타이틀을 플레이한다면 함께 표시될 수 있습니다.

## 친구 맺기

예제 코드는 앱 UI의 대리로 `DisplayFriends()`와 `DisplayError(string error)` 함수를 사용합니다. 이를 편집기에 붙여넣으면 별도 작업 없이 동작하도록 할 수 있으며, 원하는 경우 여러분의 코드로 호출을 대체할 수도 있습니다.

```csharp theme={null}
void DisplayFriends(List<FriendInfo> friendsCache) { friendsCache.ForEach(f => Debug.Log(f.FriendPlayFabId)); }
void DisplayPlayFabError(PlayFabError error) { Debug.Log(error.GenerateErrorReport()); }
void DisplayError(string error) { Debug.LogError(error); }
```

1. 플레이어가 로그인하면 친구 UI에 접근할 수 있습니다. 이 기능에는 일반적으로 최소한 친구 추가, 삭제, 표시가 포함됩니다.
2. 플레이어의 현재 친구 목록을 가져오려면 [GetFriendsList](xref:titleid.playfabapi.com.client.friendlistmanagement.getfriendslist) API 호출을 사용합니다.

```csharp theme={null}
List<FriendInfo> _friends = null;

void GetFriends() {
    PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest {
        IncludeSteamFriends = false,
        IncludeFacebookFriends = false,
        XboxToken = null
    }, result => {
        _friends = result.Friends;
        DisplayFriends(_friends); // triggers your UI
    }, DisplayPlayFabError);
}
```

[GetFriendsList](xref:titleid.playfabapi.com.client.friendlistmanagement.getfriendslist) 결과에는 [FriendInfo](xref:titleid.playfabapi.com.client.friendlistmanagement.getfriendslist#friendinfo) 개체 목록인 friends 매개 변수가 포함됩니다.

3. 플레이어의 친구 목록에 친구를 추가하려면 [AddFriend](xref:titleid.playfabapi.com.client.friendlistmanagement.addfriend) API 호출을 사용합니다.

```csharp theme={null}
enum FriendIdType { PlayFabId, Username, Email, DisplayName };

void AddFriend(FriendIdType idType, string friendId) {
    var request = new AddFriendRequest();
    switch (idType) {
        case FriendIdType.PlayFabId:
            request.FriendPlayFabId = friendId;
            break;
        case FriendIdType.Username:
            request.FriendUsername = friendId;
            break;
        case FriendIdType.Email:
            request.FriendEmail = friendId;
            break;
        case FriendIdType.DisplayName:
            request.FriendTitleDisplayName = friendId;
            break;
    }
    // Execute request and update friends when we are done
    PlayFabClientAPI.AddFriend(request, result => {
        Debug.Log("Friend added successfully!");
    }, DisplayPlayFabError);
}
```

4. 플레이어의 친구 목록에서 플레이어를 제거하려면 [RemoveFriend](xref:titleid.playfabapi.com.client.friendlistmanagement.removefriend) API 호출을 사용합니다.

```csharp theme={null}
// unlike AddFriend, RemoveFriend only takes a PlayFab ID
// you can get this from the FriendInfo object under FriendPlayFabId
void RemoveFriend(FriendInfo friendInfo) {
    PlayFabClientAPI.RemoveFriend(new RemoveFriendRequest {
        FriendPlayFabId = friendInfo.FriendPlayFabId
    }, result => {
        _friends.Remove(friendInfo);
    }, DisplayPlayFabError);
}
```

## 더 나아가기

친구 기능에서 추가, 삭제, 표시 외에도 할 수 있는 일이 있습니다.

### 친구 태그 지정

[GetFriendsList](xref:titleid.playfabapi.com.client.friendlistmanagement.getfriendslist)에서 가져온 [FriendInfo](xref:titleid.playfabapi.com.client.friendlistmanagement.getfriendslist#friendinfo) 개체에는 해당 친구에 대한 태그 목록이 포함되어 있습니다. 목록을 업데이트할 때는 이 목록에 태그를 추가하거나 제거한 다음, 아래와 같이 API 호출에 포함시켜야 합니다.

```csharp theme={null}
// this REPLACES the list of tags on the server
// for updates, make sure this includes the original tag list
void SetFriendTags(FriendInfo friend, List<string> newTags)
{
    // update the tags with the edited list
    PlayFabClientAPI.SetFriendTags(new SetFriendTagsRequest
    {
        FriendPlayFabId = friend.FriendPlayFabId,
        Tags = newTags
    }, tagresult => {
        // Make sure to save new tags locally. That way you do not have to hard-update friendlist
        friend.Tags = newTags;
    }, DisplayPlayFabError);
}
```

태그를 사용하여 매치메이킹을 조정하거나(예: 플레이어가 어려운 난이도에서 **2tuff**로 태그된 친구와 플레이하는 것을 좋아하지 않음), 친구 그룹을 구현하거나 — 필요한 경우 관계에 관련된 임의의 메타데이터를 저장하는 용도로 사용할 수 있습니다.

중요한 참고 사항은 PlayFab이 현재 이러한 태그를 어떤 방식으로도 인덱싱하지 않는다는 점입니다. [GetFriendsList](xref:titleid.playfabapi.com.client.friendlistmanagement.getfriendslist)는 태그로 필터링할 수 없으므로 로컬에서 처리해야 합니다.

이 시스템으로 인해 성능에 영향을 미칠 가능성을 고려할 때 이 점을 유념하세요.
