본문 바로가기
개발/Playfab

유니티 플레이팹 친구 추가, 삭제하기 Playfab Friends Add, Delete 간단 사용법

by SPNK 2022. 7. 19.
반응형

플레이팹 로그인이 되었다는 가정하에 진행

 

유니티 플레이팹 게스트 로그인 Playfab Sign In with Guest Login 간단 사용법

코드 작성 using PlayFab; using PlayFab.ClientModels; using PlayFab.Json; using PlayFab.ProfilesModels; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using EntityKey = PlayFab.ProfilesMod

parksh3641.tistory.com

 


코드 작성

using System;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;

public class PlayfabManager : MonoBehaviour
{
    List<FriendInfo> friendsList = new List<FriendInfo>();

    private void DisplayPlayfabError(PlayFabError error) => Debug.LogError("error : " + error.GenerateErrorReport());

    public void GetFriendList()
    {
        List<string> friendsList = new List<string>();

        PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest
        {
            IncludeSteamFriends = false,
            IncludeFacebookFriends = true,
            ProfileConstraints = new PlayerProfileViewConstraints
            {
                ShowStatistics = true
            },
            XboxToken = null
        }, result =>
        {
            Debug.Log("Get FriendList successfully!");

            this.friendsList = result.Friends;

            for (int i = 0; i < this.friendsList.Count; i++)
            {
                friendsList.Add(this.friendsList[i].TitleDisplayName);
            }

        }, DisplayPlayfabError);
    }

    public 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;
        }

        PlayFabClientAPI.AddFriend(request, result =>
        {
            Debug.Log("Friend added successfully!");

        }, DisplayPlayfabError);
    }
    
    public void RemoveFriend(FriendInfo friendInfo) //친구 삭제
    {
        PlayFabClientAPI.RemoveFriend(new RemoveFriendRequest
        {
            FriendPlayFabId = friendInfo.FriendPlayFabId
        }, result =>
        {
            Debug.Log("Friend deleted successfully!");

            friendsList.Remove(friendInfo);

        }, DisplayPlayfabError);
    }
}

 

반응형

댓글