Files
ichni_Official/Assets/Scripts/Online/Logic/ThirdPartyServiceManager.cs
Kexun Liu 00c4432007 update
2026-04-24 14:09:37 +08:00

68 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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}");
}
}
}
}