フレンド リスト

フレンド リストは、プレイヤーの交流機能を強化するための優れた機能です。 操作は簡単で、ユーザーの熱意を高めるようにランキングを作成できます。

前提条件

SDK: Unity

  • タイトル ID が PlayFabSharedSettings オブジェクトに設定されている。
  • プロジェクトが正常にユーザーをログインできる。
  • タイトルに少なくとも 2 人のユーザーが登録されている。

フレンドについて

タイトルのどのプレイヤーも、タイトルの他の任意のプレイヤーとフレンドになることができます。 なお、PlayFab でのフレンドのつながりは一方通行です。

AlbertBob をフレンドとして追加した場合、Bob の側に承認プロセスはありません。 実際、Bob は気付かない場合があります。

フレンドのつながりが相互となるには、Bob が別個に Albert を追加する必要があります。 相互関係のルールを希望する場合、タイトルごとに必要に応じてカスタム ゲーム サーバーや CloudScript ロジックでこれらの条件を適用する責任があります。

プレイヤーが Steam、Facebook、Xbox Live アカウントをリンクした場合、そのプラットフォーム固有のフレンドも表示できます (フレンドもタイトルをプレイしている場合)。

フレンドを作成する

サンプル コードでは、関数 DisplayFriends() および DisplayError(string error) をアプリの UI のプロキシとして使います。 特別な作業を行わなくてもこれらのコードをエディターに貼り付けると動作します。または、呼び出しを独自のコードに置き換えることができます。

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 は、タグに基づいてフィルター処理できないため、ローカルで実行する必要があります。

このシステムによるパフォーマンスへの影響を考慮するときは、この点に留意してください。