先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using asap.playfab.async;
|
|
using Newtonsoft.Json.Linq;
|
|
using PlayFab;
|
|
using PlayFab.ClientModels;
|
|
using UnityEngine;
|
|
|
|
public class PlayFabTools
|
|
{
|
|
public class PFPlayerInfo
|
|
{
|
|
public string DisplayName { get; set; }
|
|
public string Avatar { get; set; }
|
|
public int SdkId { get; set; }
|
|
public string PlayFabId { get; set; }
|
|
public int Level { get; set; }
|
|
public int Diamond { get; set; }
|
|
public int Energy { get; set; }
|
|
|
|
public static PFPlayerInfo Empty(int sdkId)
|
|
{
|
|
return new PFPlayerInfo()
|
|
{
|
|
DisplayName = "Unknown",
|
|
SdkId = sdkId,
|
|
PlayFabId = string.Empty,
|
|
Level = 0,
|
|
Diamond = 0,
|
|
Energy = 0
|
|
};
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return JObject.FromObject(this).ToString();
|
|
}
|
|
|
|
public bool IsAccountValid => !string.IsNullOrEmpty(PlayFabId);
|
|
public bool IsDataValid => Level > 0 && !string.IsNullOrEmpty(PlayFabId);
|
|
}
|
|
|
|
public static async Task<PFPlayerInfo> GetPFPlayerInfoBySDKId(int sdkId, string playfabTitleId)
|
|
{
|
|
PlayFab.Internal.PlayFabWebRequest.SkipCertificateValidation();
|
|
var settings = new PlayFabApiSettings() { TitleId = playfabTitleId };
|
|
var pfClient = new PlayFabClientInstanceAPI(settings);
|
|
|
|
var requestParams = new GetPlayerCombinedInfoRequestParams()
|
|
{
|
|
GetPlayerProfile = true,
|
|
GetUserData = true,
|
|
ProfileConstraints = new PlayerProfileViewConstraints()
|
|
{
|
|
ShowDisplayName = true,
|
|
ShowAvatarUrl = true,
|
|
},
|
|
UserDataKeys = new List<string>() { "NewPlayerDataDic" }
|
|
};
|
|
|
|
var request = new LoginWithCustomIDRequest()
|
|
{
|
|
CreateAccount = false,
|
|
CustomId = sdkId.ToString(),
|
|
InfoRequestParameters = requestParams
|
|
};
|
|
|
|
try
|
|
{
|
|
var result = await pfClient.ExecuteWithRetryAsync(
|
|
() => pfClient.ToAsync<LoginWithCustomIDRequest, LoginResult>(request, pfClient.LoginWithCustomID));
|
|
|
|
if (result == null)
|
|
return PFPlayerInfo.Empty(sdkId);
|
|
|
|
var infoResultPayload = result.InfoResultPayload;
|
|
if (!infoResultPayload.UserData.TryGetValue("NewPlayerDataDic", out var userData))
|
|
{
|
|
Debug.LogWarning("No user data found.");
|
|
return new PFPlayerInfo() { SdkId = sdkId, PlayFabId = result.PlayFabId };
|
|
}
|
|
|
|
var playerProfile = infoResultPayload.PlayerProfile;
|
|
JObject userDataJson = JObject.Parse(userData.Value);
|
|
if (!userDataJson.TryGetValue("newData", out var newData))
|
|
{
|
|
Debug.LogWarning("No newData found in user data.");
|
|
return new PFPlayerInfo() { SdkId = sdkId, PlayFabId = result.PlayFabId };
|
|
}
|
|
|
|
var dataList = newData.ToString().Split(',');
|
|
return new PFPlayerInfo()
|
|
{
|
|
DisplayName = playerProfile.DisplayName,
|
|
Avatar = playerProfile.AvatarUrl,
|
|
SdkId = sdkId,
|
|
PlayFabId = result.PlayFabId,
|
|
Level = int.Parse(dataList[0]),
|
|
Energy = int.Parse(dataList[3]),
|
|
Diamond = int.Parse(dataList[11]),
|
|
};
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogWarning(e.Message);
|
|
return PFPlayerInfo.Empty(sdkId);
|
|
}
|
|
|
|
}
|
|
} |