친구 목록

친구 목록은 플레이어의 사회화 능력을 향상시켜 주는 훌륭한 기능입니다. 쉽게 작동하고 사용자의 순위표를 훨씬 더 재미 있게 만들 수 있습니다.

필수 조건

SDK: Unity

  • 타이틀 ID는 PlayFabSharedSettings 개체에서 설정합니다.
  • 프로젝트는 사용자를 성공적으로 로그인할 수 있습니다.
  • 타이틀에는 최소한 2명 이상의 등록된 사용자가 포함됩니다.

친구 정보

타이틀의 모든 플레이어는 타이틀 내에서 다른 플레이어와 친구가 될 수 있습니다. 특히 PlayFab에서 친구 관계는 일방적으로 수행됩니다.

AlbertBob을 친구로 추가할 때 Bob이 이를 승인하는 프로세스가 없습니다. 실제로 Bob이 그러한 사실을 모를 수도 있습니다.

친구 관계가 상호적이 되기 위해서는 BobAlbert를 별도로 추가해야 합니다. 상호성 규칙을 적용하고 싶으면 사용자 지정 게임 서버에 이러한 조건 또는 CloudScript 논리(필요한 경우)를 타이틀이 직접 적용해야 합니다.

플레이어가 자신의 Steam, Facebook 또는 Xbox Live 계정을 연결한 경우에는 같은 타이틀을 플레이하는 해당 플랫폼의 친구들도 표시될 수 있습니다.

친구 지정

이 예제 코드는 앱 UI의 프록시로 DisplayFriends()DisplayError(string error) 함수를 사용합니다. 이를 편집기에 붙여 넣어서 추가 노력 없이 작동되도록 하거나, 호출을 자신의 고유 코드로 대체합니다.

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 API 호출을 사용합니다.
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 결과에는 FriendInfo 개체의 목록인 매개 변수 친구가 포함됩니다.

  1. 플레이어의 친구 목록에 친구를 추가하려면 AddFriend API 호출을 사용합니다.
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);
}
  1. 플레이어의 친구 목록에서 플레이어를 제거하려면 RemoveFriend API 호출을 사용합니다.
// 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에서 검색된 FriendInfo 개체에는 친구에 대한 태그 목록이 포함되어 있습니다. 목록을 업데이트할 때는 이 목록에서 항목을 추가하거나 제거하고 아래 표시된 것처럼 API 호출에 이를 포함할 수 있습니다.

// 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는 이를 기준으로 필터링을 수행하지 않으므로, 작업이 로컬로 수행되어야 합니다.

시스템에서 발생하는 성능 영향을 고려할 때 이를 주의해야 합니다.