Unity

[Unity] Playfab Function 정리 -2

Guk-blog 2020. 8. 18. 11:09
728x90
반응형

랜덤 박스 실행

public bool RandomBoxGrant(string catalogversion, string tableId) //랜덤박스
    {
        // First, roll a random number and evaluate the drop table
        PlayFabServerAPI.EvaluateRandomResultTable(new PlayFab.ServerModels.EvaluateRandomResultTableRequest()
        {
            CatalogVersion = catalogversion,
            TableId = tableId
        }, result =>
        {
            Debug.Log("Success");
        }, fail =>
        {
            Debug.Log("Fail");
        });
    }

 

유저 타이틀 데이터 저장/가져오기

public void SetData(Dictionary<string,string> data) //플레이어 타이틀 저장
    {
        var request = new UpdateUserDataRequest() { Data = data, Permission = UserDataPermission.Public};
        PlayFabClientAPI.UpdateUserData(request, (result) =>
        {
            Debug.Log("플레이어 데이터 저장 성공!");
        }, (error) => Debug.Log("Fail"););

    }
    public void GetData(Dictionary<string, string> data) //플레이어 타이틀 불러오기
    {
        var request = new GetUserDataRequest() { PlayFabId = PlayfabID };
        PlayFabClientAPI.GetUserData(request, (result) => {

            foreach (var eachData in result.Data)
            {
                data.Add(eachData.Key,eachData.Value.Value);
            }

            Debug.Log("플레이어 데이터 불러오기 성공!");

        }, fail =>
        {
            Debug.Log("Fail");
        });
    }

 

유저 스텟 저장/가져오기

public void SetStat(string name, int value) //플레이어 상태값 저장
    {
        PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest
        {
            Statistics = new List<StatisticUpdate>
            {
                new StatisticUpdate {StatisticName = name, Value = value}
            }
        },
        (result) => { Debug.Log("플레이어 상태값 저장 성공"); }
        , (error) => Debug.Log("Fail");
    }

    public void GetStat() //플레이어 상태값 불러오기
    {
        PlayFabClientAPI.GetPlayerStatistics(
            new GetPlayerStatisticsRequest(),
            (result) =>
            {
                for(int i = 0;i<result.Statistics.Count;i++)
                {
                	// 원하는 변수에 저장
                }
            }
            ,(error) => Debug.Log("Fail");
    }

 

서버 시간 가져오기

public System.DateTime Get_ServerTime() //서버 시간 가져오기
    {
        System.DateTime _time = System.DateTime.Now;
        PlayFabClientAPI.GetTime(new GetTimeRequest(),
            result =>
            {
                _time = result.Time;
            }, fail => Debug.Log("fail");
        return _time;
    }
728x90
반응형