반응형
코드 작성
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.ProfilesModels.EntityKey;
public class PlayfabManager : MonoBehaviour
{
static string customId = "";
static string playfabId = "";
private string entityId;
private string entityType;
public void OnClickGuestLogin() //게스트 로그인 버튼
{
if (string.IsNullOrEmpty(customId))
CreateGuestId();
else
LoginGuestId();
}
private void CreateGuestId() //저장된 아이디가 없을 경우 새로 생성
{
customId = GetRandomPassword(16);
PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest()
{
CustomId = customId,
CreateAccount = true
}, result =>
{
OnLoginSuccess(result);
}, error =>
{
Debug.LogError("Login Fail - Guest");
});
}
private string GetRandomPassword(int _totLen) //랜덤한 16자리 id 생성
{
string input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var chars = Enumerable.Range(0, _totLen)
.Select(x => input[UnityEngine.Random.Range(0, input.Length)]);
return new string(chars.ToArray());
}
private void LoginGuestId() //게스트 로그인
{
Debug.Log("Guest Login");
PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest()
{
CustomId = customId,
CreateAccount = false
}, result =>
{
OnLoginSuccess(result);
}, error =>
{
Debug.LogError("Login Fail - Guest");
});
}
public void OnLoginSuccess(LoginResult result) //로그인 결과
{
Debug.Log("Playfab Login Success");
playfabId = result.PlayFabId;
entityId = result.EntityToken.Entity.Id;
entityType = result.EntityToken.Entity.Type;
}
}
참고할만한 글
반응형
'개발 > Playfab' 카테고리의 다른 글
유니티 플레이팹 유저 프로필 가져오기 Playfab GetProfile 간단 사용법 (0) | 2022.07.08 |
---|---|
유니티 플레이팹 유저 데이터 불러오기 Playfab GetUserData 간단 사용법 (0) | 2022.07.08 |
유니티 플레이팹 유저 데이터 가져오기 Playfab SetUserData 간단 사용법 (0) | 2022.07.08 |
유니티 플레이팹 통계 저장 불러오기 Playfab GetStatistics 간단 사용법 (0) | 2022.07.02 |
유니티 플레이팹 상점 카테고리 가져오기 Playfab GetCatalog 간단 사용법 (0) | 2022.07.02 |
유니티 플레이팹 유저 인벤토리 가져오기 Playfab GetUserInventory 간단 사용법 (0) | 2022.07.02 |
유니티 플레이팹 구글 로그인 Playfab Sign In with Google Login 간단 구현 (0) | 2022.06.22 |
유니티 플레이팹 패키지 Playfab Unity SDK 설치 (0) | 2022.06.18 |
댓글