com.taptap.sdk.core 4.6.1-beta.9 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Mobile/Editor/NativeDependencies.xml +2 -2
- package/Mobile/Runtime/TapCoreMobile.cs +5 -0
- package/Mobile/Runtime/TapEventMobile.cs +21 -0
- package/Runtime/Internal/Platform/ITapCorePlatform.cs +2 -0
- package/Runtime/Internal/Platform/ITapEventPlatform.cs +4 -0
- package/Runtime/Internal/Utils/EventManager.cs +2 -0
- package/Runtime/Public/TapTapEvent.cs +7 -0
- package/Runtime/Public/TapTapSDK.cs +7 -1
- package/Runtime/Public/TapTapSdkOptions.cs +14 -0
- package/Standalone/Plugins/x86/tapsdkcore.dll +0 -0
- package/Standalone/Plugins/x86_64/tapsdkcore.dll +0 -0
- package/Standalone/Plugins/x86_64/taptap_api.dll +0 -0
- package/Standalone/Plugins/x86_64/taptap_api.dll.meta +52 -0
- package/Standalone/Resources/Prefabs/TapClient/TapClientConnectTipPanel.prefab +983 -0
- package/Standalone/Resources/Prefabs/TapClient/TapClientConnectTipPanel.prefab.meta +7 -0
- package/Standalone/Resources/Prefabs/TapClient.meta +8 -0
- package/Standalone/Resources/Prefabs.meta +8 -0
- package/Standalone/Resources/Texures/TapClientConnectError.png +0 -0
- package/Standalone/Resources/Texures/TapClientConnectError.png.meta +128 -0
- package/Standalone/Resources/Texures.meta +8 -0
- package/Standalone/Resources.meta +8 -0
- package/Standalone/Runtime/Internal/Openlog/TapCoreTracker.cs +107 -0
- package/Standalone/Runtime/Internal/Openlog/TapCoreTracker.cs.meta +11 -0
- package/Standalone/Runtime/Internal/TapClientBridge.cs +224 -0
- package/Standalone/Runtime/Internal/TapClientBridge.cs.meta +11 -0
- package/Standalone/Runtime/Internal/TapClientBridgePoll.cs +36 -0
- package/Standalone/Runtime/Internal/TapClientBridgePoll.cs.meta +11 -0
- package/Standalone/Runtime/Internal/UI/TapClientConnectTipController.cs +59 -0
- package/Standalone/Runtime/Internal/UI/TapClientConnectTipController.cs.meta +11 -0
- package/Standalone/Runtime/Internal/UI/TapUnderLineText.cs +76 -0
- package/Standalone/Runtime/Internal/UI/TapUnderLineText.cs.meta +11 -0
- package/Standalone/Runtime/Internal/UI.meta +8 -0
- package/Standalone/Runtime/Public/TapCoreStandalone.cs +366 -0
- package/Standalone/Runtime/Public/TapEventStandalone.cs +27 -0
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using UnityEngine.UI;
|
|
4
|
+
|
|
5
|
+
namespace TapSDK.Core.Standalone.Internal {
|
|
6
|
+
public enum UnderLineType
|
|
7
|
+
{
|
|
8
|
+
//画线位置
|
|
9
|
+
Bottom = 0,
|
|
10
|
+
Center
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//文本编辑扩展
|
|
14
|
+
public class TapUnderLineText : MonoBehaviour
|
|
15
|
+
{
|
|
16
|
+
public Text linkText;
|
|
17
|
+
public UnderLineType underLineType;
|
|
18
|
+
public bool autoLink = true;
|
|
19
|
+
private string underLineText = "_";
|
|
20
|
+
|
|
21
|
+
private void Awake()
|
|
22
|
+
{
|
|
23
|
+
if (underLineType == UnderLineType.Bottom)
|
|
24
|
+
{
|
|
25
|
+
underLineText = "_";
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
{
|
|
29
|
+
underLineText = "-";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private void Start()
|
|
34
|
+
{
|
|
35
|
+
if (autoLink)
|
|
36
|
+
CreateLink(linkText, null);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public void CreateLink(Text text, UnityEngine.Events.UnityAction onClickBtn = null)
|
|
40
|
+
{
|
|
41
|
+
if (text == null)
|
|
42
|
+
return;
|
|
43
|
+
|
|
44
|
+
//克隆Text,获得相同的属性
|
|
45
|
+
Text underline = Instantiate(text) as Text;
|
|
46
|
+
underline.name = "Underline";
|
|
47
|
+
underline.transform.SetParent(text.transform);
|
|
48
|
+
underline.transform.localScale = Vector3.one;
|
|
49
|
+
RectTransform rt = underline.rectTransform;
|
|
50
|
+
//设置下划线坐标和位置
|
|
51
|
+
rt.anchoredPosition3D = Vector3.zero;
|
|
52
|
+
rt.offsetMax = Vector2.zero;
|
|
53
|
+
rt.offsetMin = Vector2.zero;
|
|
54
|
+
rt.anchorMax = Vector2.one;
|
|
55
|
+
rt.anchorMin = Vector2.zero;
|
|
56
|
+
underline.text = underLineText;
|
|
57
|
+
float perlineWidth = underline.preferredWidth; //单个下划线宽度
|
|
58
|
+
float width = text.preferredWidth;
|
|
59
|
+
int lineCount = (int)Mathf.Round(width / perlineWidth);
|
|
60
|
+
for (int i = 1; i < lineCount; i++)
|
|
61
|
+
{
|
|
62
|
+
underline.text += underLineText;
|
|
63
|
+
}
|
|
64
|
+
if (onClickBtn != null)
|
|
65
|
+
{
|
|
66
|
+
var btn = text.gameObject.AddComponent<Button>();
|
|
67
|
+
btn.onClick.AddListener(onClickBtn);
|
|
68
|
+
}
|
|
69
|
+
var underLine = underline.GetComponent<TapUnderLineText>();
|
|
70
|
+
if (underLine)
|
|
71
|
+
{
|
|
72
|
+
underLine.autoLink = false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -10,6 +10,11 @@ using TapSDK.Core.Internal.Log;
|
|
|
10
10
|
using TapSDK.Core.Standalone.Internal.Http;
|
|
11
11
|
using Newtonsoft.Json;
|
|
12
12
|
using TapSDK.Core.Standalone.Internal.Bean;
|
|
13
|
+
using System.Threading.Tasks;
|
|
14
|
+
using System;
|
|
15
|
+
using System.Threading;
|
|
16
|
+
using TapSDK.UI;
|
|
17
|
+
using System.Runtime.InteropServices;
|
|
13
18
|
|
|
14
19
|
namespace TapSDK.Core.Standalone
|
|
15
20
|
{
|
|
@@ -31,6 +36,78 @@ namespace TapSDK.Core.Standalone
|
|
|
31
36
|
|
|
32
37
|
private readonly TapHttp tapHttp = TapHttp.NewBuilder("TapSDKCore", TapTapSDK.Version).Build();
|
|
33
38
|
|
|
39
|
+
|
|
40
|
+
// 初始化校验结果
|
|
41
|
+
private class TapInitResult
|
|
42
|
+
{
|
|
43
|
+
internal TapSDKInitResult result;
|
|
44
|
+
internal string errorMsg;
|
|
45
|
+
|
|
46
|
+
internal bool needQuitGame = false;
|
|
47
|
+
|
|
48
|
+
public TapInitResult(TapSDKInitResult result, string errorMsg)
|
|
49
|
+
{
|
|
50
|
+
this.result = result;
|
|
51
|
+
this.errorMsg = errorMsg;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public TapInitResult(bool needQuitGame)
|
|
55
|
+
{
|
|
56
|
+
this.needQuitGame = needQuitGame;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 使用客户端登录结果返回值
|
|
61
|
+
public class TapLoginResponseByTapClient
|
|
62
|
+
{
|
|
63
|
+
|
|
64
|
+
public bool isCancel = false;
|
|
65
|
+
|
|
66
|
+
public string redirectUri;
|
|
67
|
+
|
|
68
|
+
public bool isFail = false;
|
|
69
|
+
|
|
70
|
+
public string errorMsg;
|
|
71
|
+
|
|
72
|
+
public TapLoginResponseByTapClient(bool isCancel, string redirctUri)
|
|
73
|
+
{
|
|
74
|
+
this.redirectUri = redirctUri;
|
|
75
|
+
this.isCancel = isCancel;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public TapLoginResponseByTapClient(string errorMsg)
|
|
79
|
+
{
|
|
80
|
+
isFail = true;
|
|
81
|
+
isCancel = false;
|
|
82
|
+
this.errorMsg = errorMsg;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 使用客户端登录结果回调
|
|
89
|
+
public interface TapLoginCallbackWithTapClient
|
|
90
|
+
{
|
|
91
|
+
void onSuccess(TapLoginResponseByTapClient response);
|
|
92
|
+
|
|
93
|
+
void onFailure(string error);
|
|
94
|
+
|
|
95
|
+
void onCancel();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 是否是渠道服游戏包
|
|
99
|
+
private static bool isChannelPackage = false;
|
|
100
|
+
|
|
101
|
+
// -1 未执行 0 失败 1 成功
|
|
102
|
+
private static int lastIsLaunchedFromTapTapPCResult = -1;
|
|
103
|
+
private static bool isRuningIsLaunchedFromTapTapPC = false;
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// 当为渠道游戏包时,与启动器的初始化校验结果
|
|
107
|
+
private TapInitResult tapInitResult;
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
34
111
|
/// <summary>
|
|
35
112
|
/// Initializes a new instance of the <see cref="TapCoreStandalone"/> class.
|
|
36
113
|
/// </summary>
|
|
@@ -226,6 +303,295 @@ namespace TapSDK.Core.Standalone
|
|
|
226
303
|
public static string GetCurrentUserId(){
|
|
227
304
|
return User?.Id;
|
|
228
305
|
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
// <summary>
|
|
309
|
+
// 校验游戏是否通过启动器唤起,建立与启动器通讯
|
|
310
|
+
//</summary>
|
|
311
|
+
public async Task<bool> IsLaunchedFromTapTapPC()
|
|
312
|
+
{
|
|
313
|
+
#if UNITY_STANDALONE_WIN
|
|
314
|
+
// 正在执行中
|
|
315
|
+
if(isRuningIsLaunchedFromTapTapPC){
|
|
316
|
+
UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 正在执行,请勿重复调用", UIManager.GeneralToastLevel.Error);
|
|
317
|
+
TapLogger.Error("IsLaunchedFromTapTapPC 正在执行,请勿重复调用");
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
// 多次执行时返回上一次结果
|
|
321
|
+
if(lastIsLaunchedFromTapTapPCResult != -1){
|
|
322
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC duplicate invoke return " + lastIsLaunchedFromTapTapPCResult);
|
|
323
|
+
return lastIsLaunchedFromTapTapPCResult > 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
isChannelPackage = true;
|
|
327
|
+
if (coreOptions == null)
|
|
328
|
+
{
|
|
329
|
+
UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 调用必须在初始化之后", UIManager.GeneralToastLevel.Error);
|
|
330
|
+
TapLogger.Error("IsLaunchedFromTapTapPC 调用必须在初始化之后");
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
string clientId = coreOptions.clientId;
|
|
334
|
+
string pubKey = coreOptions.clientPublicKey;
|
|
335
|
+
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(pubKey))
|
|
336
|
+
{
|
|
337
|
+
UIManager.Instance.OpenToast("clientId 及 TapPubKey 参数都不能为空, clientId =" + clientId + ", TapPubKey = " + pubKey, UIManager.GeneralToastLevel.Error);
|
|
338
|
+
TapLogger.Error("clientId 或 TapPubKey 无效, clientId = " + clientId + ", TapPubKey = " + pubKey);
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
isRuningIsLaunchedFromTapTapPC = true;
|
|
342
|
+
|
|
343
|
+
string sessionId = Guid.NewGuid().ToString();
|
|
344
|
+
TapCoreTracker.Instance.TrackStart(TapCoreTracker.METHOD_LAUNCHER, sessionId);
|
|
345
|
+
try
|
|
346
|
+
{
|
|
347
|
+
TapInitResult result = await RunClientBridgeMethodWithTimeout(clientId, pubKey);
|
|
348
|
+
isRuningIsLaunchedFromTapTapPC = false;
|
|
349
|
+
if (result.needQuitGame)
|
|
350
|
+
{
|
|
351
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
352
|
+
TapCoreTracker.Instance.TrackSuccess(TapCoreTracker.METHOD_LAUNCHER, sessionId, TapCoreTracker.SUCCESS_TYPE_RESTART);
|
|
353
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC Quit game");
|
|
354
|
+
Application.Quit();
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
else
|
|
358
|
+
{
|
|
359
|
+
if (result.result == TapSDKInitResult.kTapSDKInitResult_OK)
|
|
360
|
+
{
|
|
361
|
+
string currentClientId;
|
|
362
|
+
bool isFetchClientIdSuccess = TapClientBridge.GetClientId(out currentClientId);
|
|
363
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC get clientId = " + currentClientId);
|
|
364
|
+
if (isFetchClientIdSuccess && !string.IsNullOrEmpty(currentClientId) && currentClientId != clientId ){
|
|
365
|
+
UIManager.Instance.OpenToast("SDK 中配置的 clientId = " + clientId + "与 Tap 启动器中" + currentClientId + "不一致", UIManager.GeneralToastLevel.Error);
|
|
366
|
+
TapLogger.Error("SDK 中配置的 clientId = " + clientId + "与 Tap 启动器中" + currentClientId + "不一致");
|
|
367
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, -1, "SDK 中配置的 clientId = " + clientId + "与 Tap 启动器中" + currentClientId + "不一致");
|
|
368
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
string openId ;
|
|
372
|
+
bool fetchOpenIdSuccess = TapClientBridge.GetTapUserOpenId(out openId);
|
|
373
|
+
if (fetchOpenIdSuccess){
|
|
374
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC get openId = " + openId);
|
|
375
|
+
EventManager.TriggerEvent(EventManager.IsLaunchedFromTapTapPCFinished, openId);
|
|
376
|
+
}else{
|
|
377
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC get openId failed" );
|
|
378
|
+
}
|
|
379
|
+
lastIsLaunchedFromTapTapPCResult = 1;
|
|
380
|
+
TapClientBridgePoll.StartUp();
|
|
381
|
+
TapCoreTracker.Instance.TrackSuccess(TapCoreTracker.METHOD_LAUNCHER, sessionId, TapCoreTracker.SUCCESS_TYPE_INIT);
|
|
382
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC check success");
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
else
|
|
386
|
+
{
|
|
387
|
+
|
|
388
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, (int)result.result, result.errorMsg ?? "");
|
|
389
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
390
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC show TapClient tip Pannel " + result.result + " , error = " + result.errorMsg);
|
|
391
|
+
string tipPannelPath = "Prefabs/TapClient/TapClientConnectTipPanel";
|
|
392
|
+
if (Resources.Load<GameObject>(tipPannelPath) != null)
|
|
393
|
+
{
|
|
394
|
+
var pannel = UIManager.Instance.OpenUI<TapClientConnectTipController>(tipPannelPath);
|
|
395
|
+
pannel.Show(result.result);
|
|
396
|
+
}
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
catch(TimeoutException e)
|
|
402
|
+
{
|
|
403
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
404
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, (int)TapSDKInitResult.kTapSDKInitResult_Timeout, e.Message ?? "");
|
|
405
|
+
|
|
406
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC check timeout");
|
|
407
|
+
string tipPannelPath = "Prefabs/TapClient/TapClientConnectTipPanel";
|
|
408
|
+
if (Resources.Load<GameObject>(tipPannelPath) != null)
|
|
409
|
+
{
|
|
410
|
+
var pannel = UIManager.Instance.OpenUI<TapClientConnectTipController>(tipPannelPath);
|
|
411
|
+
pannel.Show(TapSDKInitResult.kTapSDKInitResult_Timeout);
|
|
412
|
+
}
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
catch (Exception e)
|
|
416
|
+
{
|
|
417
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
418
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, (int)TapSDKInitResult.kTapSDKInitResult_Unknown, e.Message ?? "");
|
|
419
|
+
|
|
420
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC check exception = " + e.StackTrace);
|
|
421
|
+
string tipPannelPath = "Prefabs/TapClient/TapClientConnectTipPanel";
|
|
422
|
+
if (Resources.Load<GameObject>(tipPannelPath) != null)
|
|
423
|
+
{
|
|
424
|
+
var pannel = UIManager.Instance.OpenUI<TapClientConnectTipController>(tipPannelPath);
|
|
425
|
+
pannel.Show(TapSDKInitResult.kTapSDKInitResult_Unknown);
|
|
426
|
+
}
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
#else
|
|
431
|
+
UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 仅支持 Windows PC 端", UIManager.GeneralToastLevel.Error);
|
|
432
|
+
TapLogger.Error("IsLaunchedFromTapTapPC 仅支持 Windows PC 端");
|
|
433
|
+
return false;
|
|
434
|
+
#endif
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private async Task<TapInitResult> RunClientBridgeMethodWithTimeout(string clientId, string pubKey)
|
|
438
|
+
{
|
|
439
|
+
#if UNITY_STANDALONE_WIN
|
|
440
|
+
TaskCompletionSource<TapInitResult> task = new TaskCompletionSource<TapInitResult>();
|
|
441
|
+
try
|
|
442
|
+
{
|
|
443
|
+
TapInitResult result = await ExecuteWithTimeoutAsync(() =>
|
|
444
|
+
{
|
|
445
|
+
bool needQuitGame = TapClientBridge.TapSDK_RestartAppIfNecessary(clientId);
|
|
446
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke TapSDK_RestartAppIfNecessary result = " + needQuitGame);
|
|
447
|
+
if (needQuitGame)
|
|
448
|
+
{
|
|
449
|
+
tapInitResult = new TapInitResult(needQuitGame);
|
|
450
|
+
}
|
|
451
|
+
else
|
|
452
|
+
{
|
|
453
|
+
string outputError;
|
|
454
|
+
TapSDKInitResult tapSDKInitResult = TapClientBridge.CheckInitState(out outputError, pubKey);
|
|
455
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke CheckInitState result = " + tapSDKInitResult + ", error = " + outputError);
|
|
456
|
+
tapInitResult = new TapInitResult(tapSDKInitResult, outputError);
|
|
457
|
+
}
|
|
458
|
+
return tapInitResult;
|
|
459
|
+
}, TimeSpan.FromSeconds(5));
|
|
460
|
+
task.TrySetResult(tapInitResult);
|
|
461
|
+
|
|
462
|
+
}
|
|
463
|
+
catch (TimeoutException ex)
|
|
464
|
+
{
|
|
465
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke CheckInitState 方法执行超时!");
|
|
466
|
+
task.TrySetException(ex);
|
|
467
|
+
}
|
|
468
|
+
catch (Exception ex)
|
|
469
|
+
{
|
|
470
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke C 方法出错!" + ex.StackTrace);
|
|
471
|
+
task.TrySetException(ex);
|
|
472
|
+
}
|
|
473
|
+
return await task.Task;
|
|
474
|
+
#else
|
|
475
|
+
throw new Exception("当前平台不支持该操作,仅支持 Windows PC");
|
|
476
|
+
#endif
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/// <summary>
|
|
480
|
+
/// 在 IO 线程执行 C 方法,超时 5 秒后切回主线程
|
|
481
|
+
/// </summary>
|
|
482
|
+
private static async Task<T> ExecuteWithTimeoutAsync<T>(Func<T> cMethod, TimeSpan timeout)
|
|
483
|
+
{
|
|
484
|
+
using (var cts = new CancellationTokenSource())
|
|
485
|
+
{
|
|
486
|
+
Task<T> ioTask = Task.Run(cMethod); // 在后台线程执行 C 方法
|
|
487
|
+
Task delayTask = Task.Delay(timeout); // 超时任务
|
|
488
|
+
|
|
489
|
+
Task completedTask = await Task.WhenAny(ioTask, delayTask);
|
|
490
|
+
|
|
491
|
+
if (completedTask == delayTask)
|
|
492
|
+
{
|
|
493
|
+
cts.Cancel(); // 取消 C 方法任务
|
|
494
|
+
throw new TimeoutException("C 方法执行超时!");
|
|
495
|
+
}
|
|
496
|
+
else
|
|
497
|
+
{
|
|
498
|
+
cts.Cancel();
|
|
499
|
+
return await ioTask;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/// <summary>
|
|
505
|
+
/// 是否需要从启动器登录
|
|
506
|
+
/// </summary>
|
|
507
|
+
public static bool IsNeedLoginByTapClient()
|
|
508
|
+
{
|
|
509
|
+
return isChannelPackage;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
#if UNITY_STANDALONE_WIN
|
|
514
|
+
private static TaskCompletionSource<TapLoginResponseByTapClient> taskCompletionSource;
|
|
515
|
+
private static TapClientBridge.CallbackDelegate currentLoginDelegate;
|
|
516
|
+
#endif
|
|
517
|
+
|
|
518
|
+
/// <summary>
|
|
519
|
+
/// 发起登录授权
|
|
520
|
+
/// </summary>
|
|
521
|
+
public static async Task<TapLoginResponseByTapClient> LoginWithScopesAsync(string[] scopes, string responseType, string redirectUri,
|
|
522
|
+
string codeChallenge, string state, string codeChallengeMethod, string versonCode, string sdkUa, string info)
|
|
523
|
+
{
|
|
524
|
+
#if UNITY_STANDALONE_WIN
|
|
525
|
+
if(lastIsLaunchedFromTapTapPCResult == -1){
|
|
526
|
+
// UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 正在执行,请在完成后调用授权接口", UIManager.GeneralToastLevel.Error);
|
|
527
|
+
TapLogger.Error("IsLaunchedFromTapTapPC 正在执行,请在完成后调用授权接口");
|
|
528
|
+
throw new Exception("操作异常: IsLaunchedFromTapTapPC 正在执行,请在完成后调用授权接口");
|
|
529
|
+
}
|
|
530
|
+
TapLogger.Debug("LoginWithScopes start login by tapclient mainthread = " + Thread.CurrentThread.ManagedThreadId);
|
|
531
|
+
|
|
532
|
+
taskCompletionSource = new TaskCompletionSource<TapLoginResponseByTapClient>();
|
|
533
|
+
|
|
534
|
+
currentLoginDelegate = loginCallbackDelegate;
|
|
535
|
+
try
|
|
536
|
+
{
|
|
537
|
+
|
|
538
|
+
// if(currentLoginDelegate == null){
|
|
539
|
+
// currentLoginDelegate = loginCallbackDelegate;
|
|
540
|
+
TapLogger.Debug("LoginWithScopes setDelegate ");
|
|
541
|
+
TapClientBridge.RegisterCallback((int)TapCallbackID.kTapCallbackIDAuthorizeFinished, currentLoginDelegate);
|
|
542
|
+
// }
|
|
543
|
+
TapLogger.Debug("LoginWithScopes try get login result ");
|
|
544
|
+
AuthorizeResult authorizeResult = TapClientBridge.LoginWithScopes(scopes, responseType, redirectUri,
|
|
545
|
+
codeChallenge, state, codeChallengeMethod, versonCode, sdkUa, info);
|
|
546
|
+
|
|
547
|
+
TapLogger.Debug("LoginWithScopes in mainthread = " + authorizeResult);
|
|
548
|
+
if (authorizeResult != AuthorizeResult.kAuthorizeResult_OK)
|
|
549
|
+
{
|
|
550
|
+
TapClientBridge.UnRegisterCallback(currentLoginDelegate, true);
|
|
551
|
+
taskCompletionSource.TrySetResult(new TapLoginResponseByTapClient("发起授权失败,请确认 Tap 客户端是否正常运行"));
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
}
|
|
555
|
+
catch (Exception ex)
|
|
556
|
+
{
|
|
557
|
+
TapLogger.Debug("LoginWithScopes start login by tapclient error = " + ex.StackTrace);
|
|
558
|
+
TapClientBridge.UnRegisterCallback(currentLoginDelegate, true);
|
|
559
|
+
taskCompletionSource.TrySetResult(new TapLoginResponseByTapClient(false, ex.StackTrace));
|
|
560
|
+
}
|
|
561
|
+
return await taskCompletionSource.Task;
|
|
562
|
+
#else
|
|
563
|
+
throw new Exception("当前平台不支持该授权操作,仅支持 Windows PC ");
|
|
564
|
+
#endif
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
#if UNITY_STANDALONE_WIN
|
|
568
|
+
[AOT.MonoPInvokeCallback(typeof(TapClientBridge.CallbackDelegate))]
|
|
569
|
+
static void loginCallbackDelegate(int id, IntPtr userData)
|
|
570
|
+
{
|
|
571
|
+
|
|
572
|
+
TapLogger.Debug("LoginWithScopes recevie callback " + id);
|
|
573
|
+
if (id == (int)TapCallbackID.kTapCallbackIDAuthorizeFinished)
|
|
574
|
+
{
|
|
575
|
+
TapLogger.Debug("LoginWithScopes callback mainthread = " + Thread.CurrentThread.ManagedThreadId);
|
|
576
|
+
TapClientBridge.AuthorizeFinishedResponse response = Marshal.PtrToStructure<TapClientBridge.AuthorizeFinishedResponse>(userData);
|
|
577
|
+
TapLogger.Debug("LoginWithScopes callback = " + response.is_cancel + " uri = " + response.callback_uri);
|
|
578
|
+
if (taskCompletionSource != null) {
|
|
579
|
+
taskCompletionSource.TrySetResult(new TapLoginResponseByTapClient(response.is_cancel > 0, response.callback_uri));
|
|
580
|
+
taskCompletionSource = null;
|
|
581
|
+
}
|
|
582
|
+
TapLogger.Debug("LoginWithScopes callback finish and will remove delegate " );
|
|
583
|
+
if (currentLoginDelegate != null){
|
|
584
|
+
TapLogger.Debug("LoginWithScopes callback finish and will remove delegate and not null" );
|
|
585
|
+
TapClientBridge.UnRegisterCallback(currentLoginDelegate, true);
|
|
586
|
+
currentLoginDelegate = null;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
TapLogger.Debug("LoginWithScopes callback finish and will remove delegate finish" );
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
#endif
|
|
594
|
+
|
|
229
595
|
|
|
230
596
|
}
|
|
231
597
|
|
|
@@ -292,6 +292,33 @@ namespace TapSDK.Core.Standalone
|
|
|
292
292
|
Tracker.RegisterDynamicPropsDelegate(dynamicProperties);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
/// <summary>
|
|
296
|
+
/// set custom oaid value
|
|
297
|
+
/// </summary>
|
|
298
|
+
/// <param name="value">oaid</param>
|
|
299
|
+
public void SetOAID(string value)
|
|
300
|
+
{
|
|
301
|
+
if (!TapCoreStandalone.CheckInitState())
|
|
302
|
+
{
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/// <summary>
|
|
309
|
+
/// Logs a device login event.
|
|
310
|
+
/// </summary>
|
|
311
|
+
public void LogDeviceLoginEvent()
|
|
312
|
+
{
|
|
313
|
+
// PC端空实现
|
|
314
|
+
if (!TapCoreStandalone.CheckInitState())
|
|
315
|
+
{
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
Debug.Log("LogDeviceLoginEvent called in PC platform (empty implementation)");
|
|
320
|
+
}
|
|
321
|
+
|
|
295
322
|
/// <summary>
|
|
296
323
|
/// Represents the implementation of dynamic properties for the Tap event platform.
|
|
297
324
|
/// </summary>
|