update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Sirenix.OdinInspector;
|
||||
using TapSDK.Core;
|
||||
using TapSDK.Login;
|
||||
@@ -11,7 +12,6 @@ namespace IchniOnline.Online.Logic
|
||||
public class ThirdPartyServiceManager:SerializedMonoBehaviour
|
||||
{
|
||||
public static ThirdPartyServiceManager Instance { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// TapTap 登录成功时触发,参数为登录获得的 TapTapAccount
|
||||
/// </summary>
|
||||
@@ -33,7 +33,17 @@ namespace IchniOnline.Online.Logic
|
||||
/// </summary>
|
||||
public event Action<TapTapAccount, AccessToken> OnLoginWithToken;
|
||||
|
||||
private bool _initialized;
|
||||
// 使用 static 字段防止 Domain Reload 后重复初始化 TapSDK 原生模块导致崩溃
|
||||
private static bool _sdkInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Domain Reload 时重置 static 状态,确保 Play Mode 正确重新初始化
|
||||
/// </summary>
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void ResetStatic()
|
||||
{
|
||||
_sdkInitialized = false;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -54,7 +64,7 @@ namespace IchniOnline.Online.Logic
|
||||
|
||||
private void InitializeTapTapSDK()
|
||||
{
|
||||
if (_initialized) return;
|
||||
if (_sdkInitialized) return;
|
||||
|
||||
// 核心配置 详细参数见 [TapTapSDK]
|
||||
TapTapSdkOptions coreOptions = new TapTapSdkOptions()
|
||||
@@ -65,21 +75,31 @@ namespace IchniOnline.Online.Logic
|
||||
preferredLanguage = TapTapLanguageType.en,
|
||||
enableLog = true
|
||||
};
|
||||
// TapSDK 初始化,但是这玩意目前极易崩unity
|
||||
#if false
|
||||
TapTapSDK.Init(coreOptions);
|
||||
_initialized = true;
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
TapTapSDK.Init(coreOptions);
|
||||
_sdkInitialized = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"[ThirdPartyServiceManager] TapSDK 初始化失败: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发起 TapTap 登录,由 UI 按钮调用。
|
||||
/// 登录结果通过事件 OnLoginSuccess / OnLoginCanceled / OnLoginFailed 通知。
|
||||
/// </summary>
|
||||
public async void StartTapTapLogin()
|
||||
public void StartTapTapLogin()
|
||||
{
|
||||
StartTapTapLoginAsync().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid StartTapTapLoginAsync()
|
||||
{
|
||||
// 确保 SDK 已初始化
|
||||
if (!_initialized)
|
||||
if (!_sdkInitialized)
|
||||
{
|
||||
InitializeTapTapSDK();
|
||||
}
|
||||
@@ -120,4 +140,4 @@ namespace IchniOnline.Online.Logic
|
||||
Debug.Log("TapTap 已登出");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user