- Added LoginTypeToBindType function to map login types to binding types. - Updated ChangeLinkAccount method to handle account linking and unbinding with appropriate error handling. - Ensured proper messaging for success and failure cases during account changes. - Cleaned temporary SNS information after account change attempts.
166 lines
4.7 KiB
C#
166 lines
4.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json.Linq;
|
|
using tysdk;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UnbindTest : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Text message;
|
|
[SerializeField]
|
|
private Button cleanBtn;
|
|
|
|
[SerializeField]
|
|
private Button initBtn;
|
|
|
|
[SerializeField]
|
|
private Dropdown accoutTypeDropdown;
|
|
|
|
[SerializeField]
|
|
private Button loginBtn;
|
|
|
|
[SerializeField]
|
|
private Button logoutBtn;
|
|
|
|
[SerializeField]
|
|
private Button getSnsBtn;
|
|
|
|
[SerializeField]
|
|
private Button rmSnsBtn;
|
|
|
|
|
|
[SerializeField]
|
|
private Button loginBySns;
|
|
|
|
[SerializeField]
|
|
private Button bindBtn;
|
|
|
|
[SerializeField]
|
|
private Button changeBindBtn;
|
|
|
|
private EAccoutType accoutType;
|
|
|
|
private const string Cls = "com.unity3d.player.SnsTest";
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
|
message.text = string.Empty;
|
|
accoutType = (EAccoutType)accoutTypeDropdown.value;
|
|
|
|
cleanBtn.onClick.AddListener(() => message.text = string.Empty);
|
|
initBtn.onClick.AddListener(Init);
|
|
accoutTypeDropdown.onValueChanged.AddListener((index) =>
|
|
{
|
|
accoutType = (EAccoutType)index;
|
|
message.text += $"[Account Type] {accoutType.ToString()}\r\n";
|
|
}); loginBtn.onClick.AddListener(OnLogin);
|
|
logoutBtn.onClick.AddListener(OnLogout);
|
|
getSnsBtn.onClick.AddListener(OnGetSns);
|
|
rmSnsBtn.onClick.AddListener(OnRmSns);
|
|
loginBySns.onClick.AddListener(OnLoginBySns);
|
|
bindBtn.onClick.AddListener(OnBind);
|
|
changeBindBtn.onClick.AddListener(OnChangeBind);
|
|
Debug.Log("========== Init =============");
|
|
TYSdkFacade.Instance.Init();
|
|
Debug.Log($"AccoutType {accoutType}");
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
UnityBridgeFunc.UnityResetServerUrl("https://128-hwsfsdk-sdk-test01.qijihdhk.com");
|
|
TYSdkFacade.Instance.CleanLinkTempSnSInfo();
|
|
}
|
|
|
|
private void OnLogout()
|
|
{
|
|
Debug.Log("========== Logout =============");
|
|
TYSdkFacade.Instance.Logout();
|
|
}
|
|
|
|
private LoginInfo loginInfo;
|
|
private async void OnLogin()
|
|
{
|
|
Debug.Log("========== Login =============");
|
|
message.text += $"Login {accoutType}\r\n";
|
|
var info = await TYSdkFacade.Instance.Login(accoutType);
|
|
message.text = $"Login Success {info.isSuccess}\r\n";
|
|
if(info.isSuccess)
|
|
{
|
|
loginInfo = info;
|
|
}
|
|
}
|
|
|
|
private void OnGetSns()
|
|
{
|
|
Debug.Log("========== Get SNS =============");
|
|
using var t = new AndroidJavaClass(Cls);
|
|
t.CallStatic("GetSns", accoutType.ToString());
|
|
}
|
|
|
|
private void OnRmSns()
|
|
{
|
|
Debug.Log("========== Get SNS =============");
|
|
using var t = new AndroidJavaClass(Cls);
|
|
t.CallStatic("RmSns") ;
|
|
}
|
|
|
|
private async void OnLoginBySns()
|
|
{
|
|
try
|
|
{
|
|
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 int buserId;
|
|
private async void OnBind()
|
|
{
|
|
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");
|
|
buserId = linkResult.userId;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogException(e);
|
|
}
|
|
}
|
|
|
|
private async void OnChangeBind()
|
|
{
|
|
try
|
|
{
|
|
Debug.Log("========== Change Bind =============");
|
|
var result = await TYSdkFacade.Instance.ChangeLinkAccount(accoutType, buserId, loginInfo.userId);
|
|
Debug.Log($"Change Bind Result Code:{result.code}, UserId:{result.userId}, msg:{result.msg}");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogException(e);
|
|
}
|
|
}
|
|
}
|