반응형
플레이팹 로그인이 되었다는 가정하에 진행
코드 작성
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);
}
}
반응형