[U] add PlayFab SDK and SNS login improvements
- Add PlayFabSDK as local package dependency - Add PlayFabTool.cs for PlayFab API integration - Implement LoginBySns method in TYSdkFacade - Add Android SNS login support in SDKManager and UnityBridgeFunc - Add Build Android With Debug menu option - Improve exception handling and timeout management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
107
sdk-intergration/Assets/Scripts/PlayFabTool.cs
Normal file
107
sdk-intergration/Assets/Scripts/PlayFabTool.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using PlayFab.ClientModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PlayFab;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayFabTool
|
||||
{
|
||||
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 static async Task<PFPlayerInfo> GetPFPlayerInfoBySDKId(int sdkId, string playfabTitleId)
|
||||
{
|
||||
PlayFab.Internal.PlayFabWebRequest.SkipCertificateValidation();
|
||||
var tcs = new TaskCompletionSource<PFPlayerInfo>();
|
||||
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
|
||||
};
|
||||
|
||||
pfClient.LoginWithCustomID(request,
|
||||
(result) =>
|
||||
{ var infoResultPayload = result.InfoResultPayload;
|
||||
|
||||
if(!infoResultPayload.UserData.TryGetValue("NewPlayerDataDic", out var userData))
|
||||
{
|
||||
tcs.SetResult(PFPlayerInfo.Empty(sdkId));
|
||||
return;
|
||||
}
|
||||
var playerProfile = infoResultPayload.PlayerProfile;
|
||||
var displayName = playerProfile.DisplayName;
|
||||
var avatar = playerProfile.AvatarUrl;
|
||||
var playfabId = result.PlayFabId;
|
||||
|
||||
JObject userDataJson = JObject.Parse(userData.Value);
|
||||
if(!userDataJson.TryGetValue("newData", out var newData))
|
||||
{
|
||||
tcs.SetResult(PFPlayerInfo.Empty(sdkId));
|
||||
return;
|
||||
}
|
||||
var dataList = newData.ToString().Split(',');
|
||||
var level = int.Parse(dataList[0]);
|
||||
var energy = int.Parse(dataList[3]);
|
||||
var diamond = int.Parse(dataList[11]);
|
||||
var pfPlayerInfo = new PFPlayerInfo(){
|
||||
DisplayName = displayName,
|
||||
Avatar = avatar,
|
||||
SdkId = sdkId,
|
||||
PlayFabId = playfabId,
|
||||
Level = level,
|
||||
Diamond = diamond,
|
||||
Energy = energy
|
||||
};
|
||||
tcs.SetResult(pfPlayerInfo);
|
||||
},
|
||||
(error) =>
|
||||
{
|
||||
Debug.LogWarning(error.ErrorMessage);
|
||||
tcs.SetResult(null);
|
||||
});
|
||||
return await tcs.Task;
|
||||
}
|
||||
}
|
||||
11
sdk-intergration/Assets/Scripts/PlayFabTool.cs.meta
Normal file
11
sdk-intergration/Assets/Scripts/PlayFabTool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d7d04335b4344f97a23dbe66f9eaafb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -86,32 +86,51 @@ public class UnbindTest : MonoBehaviour
|
||||
{
|
||||
loginInfo = info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnGetSns()
|
||||
{
|
||||
Debug.Log("========== Get SNS =============");
|
||||
using (var t = new AndroidJavaClass(Cls))
|
||||
{
|
||||
t.CallStatic("GetSns", accoutType.ToString());
|
||||
}
|
||||
using var t = new AndroidJavaClass(Cls);
|
||||
t.CallStatic("GetSns", accoutType.ToString());
|
||||
}
|
||||
|
||||
private void OnCheckSns()
|
||||
private async void OnCheckSns()
|
||||
{
|
||||
Debug.Log("========== Check SNS =============");
|
||||
using (var t = new AndroidJavaClass(Cls))
|
||||
try
|
||||
{
|
||||
t.CallStatic("CheckSns", accoutType.ToString());
|
||||
Debug.Log("========== Login by sns =============");
|
||||
message.text += $"Login {accoutType}\r\n";
|
||||
var info = await TYSdkFacade.Instance.LoginBySns();
|
||||
message.text = $"sns Login Success {info.isSuccess}\r\n";
|
||||
if(info.isSuccess)
|
||||
{
|
||||
loginInfo = info;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnBind()
|
||||
{
|
||||
Debug.Log("========== Bind =============");
|
||||
var linkResult = await TYSdkFacade.Instance.LinkAccount(accoutType);
|
||||
Debug.Log($"Bind Result Code:{linkResult.code}, UserId:{linkResult.userId}, bindInfo:{linkResult.bindInfo}");
|
||||
try
|
||||
{
|
||||
Debug.Log("========== Bind =============");
|
||||
var linkResult = await TYSdkFacade.Instance.LinkAccount(accoutType);
|
||||
Debug.Log($"Bind Result Code:{linkResult.code}, UserId:{linkResult.userId}, bindInfo:{linkResult.bindInfo}");
|
||||
if(linkResult.code == -1)
|
||||
{
|
||||
var info = await PlayFabTool.GetPFPlayerInfoBySDKId(linkResult.userId, "6DC6D");
|
||||
Debug.Log(info?.ToString() ?? "[UnbindTest::OnBind] info is null");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void BindCallback(string message)
|
||||
|
||||
Reference in New Issue
Block a user