update
This commit is contained in:
68
Assets/Scripts/Online/Logic/ThirdPartyServiceManager.cs
Normal file
68
Assets/Scripts/Online/Logic/ThirdPartyServiceManager.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ichni.RhythmGame;
|
||||
using Sirenix.OdinInspector;
|
||||
using TapSDK.Core;
|
||||
using TapSDK.Login;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Online.Logic
|
||||
{
|
||||
public class ThirdPartyServiceManager:SerializedMonoBehaviour
|
||||
{
|
||||
public static ThirdPartyServiceManager Instance { get; private set; } = null!;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 核心配置 详细参数见 [TapTapSDK]
|
||||
TapTapSdkOptions coreOptions = new TapTapSdkOptions()
|
||||
{
|
||||
clientId = "hkbfpbh2jv2kbxupmo",
|
||||
clientToken = "Cry8OrA9EmfAetgu1RduPrWntgba2Qt44uC5tfEB",
|
||||
region = TapTapRegionType.Overseas,
|
||||
preferredLanguage = TapTapLanguageType.en,
|
||||
enableLog = true
|
||||
};
|
||||
// TapSDK 初始化
|
||||
TapTapSDK.Init(coreOptions);
|
||||
TapTapLoginTest();
|
||||
}
|
||||
|
||||
async Task TapTapLoginTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 定义授权范围
|
||||
List<string> scopes = new List<string>
|
||||
{
|
||||
TapTapLogin.TAP_LOGIN_SCOPE_PUBLIC_PROFILE,
|
||||
TapTapLogin.TAP_LOGIN_SCOPE_EMAIL
|
||||
};
|
||||
// 发起 Tap 登录
|
||||
var userInfo = await TapTapLogin.Instance.LoginWithScopes(scopes.ToArray());
|
||||
Debug.Log($"登录成功,当前用户 ID:{JsonUtility.ToJson(userInfo.accessToken)}");
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
Debug.Log("用户取消登录");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.Log($"登录失败,出现异常:{exception}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user