com.taptap.sdk.cloudsave 4.8.0-beta.1 → 4.8.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.
Files changed (35) hide show
  1. package/Mobile/Editor/NativeDependencies.xml +8 -2
  2. package/Mobile/Editor/TapCloudSaveMobileProcessBuild.cs +1 -0
  3. package/Mobile/Runtime/TapCloudSaveBridge.cs +168 -57
  4. package/Runtime/Internal/ITapCloudSaveBridge.cs +14 -9
  5. package/Runtime/Internal/TapCloudSaveInitTask.cs +2 -0
  6. package/Runtime/Internal/TapTapCloudSaveInternal.cs +22 -29
  7. package/Runtime/Public/TapTapCloudSave.cs +18 -29
  8. package/Standalone/Editor/TapCloudSaveStandaloneProcessBuild.cs +26 -0
  9. package/Standalone/Editor/TapCloudSaveStandaloneProcessBuild.cs.meta +11 -0
  10. package/Standalone/Editor/TapSDK.CloudSave.Standalone.Editor.asmdef +17 -0
  11. package/Standalone/Editor/TapSDK.CloudSave.Standalone.Editor.asmdef.meta +7 -0
  12. package/Standalone/Editor.meta +8 -0
  13. package/Standalone/Plugins/x86_64/cloudsave_sdk.dll +0 -0
  14. package/Standalone/Plugins/x86_64/cloudsave_sdk.dll.meta +80 -0
  15. package/Standalone/Plugins/x86_64.meta +8 -0
  16. package/Standalone/Plugins.meta +8 -0
  17. package/Standalone/Runtime/Internal/TapCloudSaveArchiveListResponse.cs +11 -0
  18. package/Standalone/Runtime/Internal/TapCloudSaveArchiveListResponse.cs.meta +11 -0
  19. package/Standalone/Runtime/Internal/TapCloudSaveBaseResponse.cs +29 -0
  20. package/Standalone/Runtime/Internal/TapCloudSaveBaseResponse.cs.meta +11 -0
  21. package/Standalone/Runtime/Internal/TapCloudSaveTracker.cs +101 -0
  22. package/Standalone/Runtime/Internal/TapCloudSaveTracker.cs.meta +11 -0
  23. package/Standalone/Runtime/Internal/TapCloudSaveWrapper.cs +518 -0
  24. package/Standalone/Runtime/Internal/TapCloudSaveWrapper.cs.meta +11 -0
  25. package/Standalone/Runtime/Internal.meta +8 -0
  26. package/Standalone/Runtime/TapCloudSaveResultCode.cs +9 -0
  27. package/Standalone/Runtime/TapCloudSaveResultCode.cs.meta +11 -0
  28. package/Standalone/Runtime/TapCloudSaveStandalone.cs +672 -0
  29. package/Standalone/Runtime/TapCloudSaveStandalone.cs.meta +11 -0
  30. package/Standalone/Runtime.meta +8 -0
  31. package/Standalone/TapSDK.CloudSave.Standalone.Runtime.asmdef +22 -0
  32. package/Standalone/TapSDK.CloudSave.Standalone.Runtime.asmdef.meta +7 -0
  33. package/Standalone.meta +8 -0
  34. package/link.xml.meta +1 -1
  35. package/package.json +10 -10
@@ -0,0 +1,672 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.IO;
4
+ using System.Text;
5
+ using System.Threading.Tasks;
6
+ using Newtonsoft.Json;
7
+ using TapSDK.CloudSave.Internal;
8
+ using TapSDK.Core;
9
+ using TapSDK.Core.Internal.Log;
10
+ using TapSDK.Core.Internal.Utils;
11
+ using TapSDK.Core.Standalone;
12
+ using TapSDK.Core.Standalone.Internal;
13
+ using TapSDK.Core.Standalone.Internal.Http;
14
+ using TapSDK.Login;
15
+ using UnityEngine;
16
+
17
+ namespace TapSDK.CloudSave.Standalone
18
+ {
19
+ public class TapCloudSaveStandalone : ITapCloudSaveBridge
20
+ {
21
+ private List<ITapCloudSaveCallback> currentSaveCallback = null;
22
+ private static readonly bool isRND = false;
23
+ private bool _hasInitNative = false;
24
+ private object _lockObj = new object();
25
+
26
+ private TapLog cloudSaveLog;
27
+
28
+ public void Init(TapTapSdkOptions options)
29
+ {
30
+ Log("TapCloudSave start init");
31
+ TapCloudSaveTracker.Instance.TrackInit();
32
+ string cacheDir = Path.Combine(
33
+ Application.persistentDataPath,
34
+ "cloudsave_" + options.clientId
35
+ );
36
+ string deviceID = SystemInfo.deviceUniqueIdentifier;
37
+ Task.Run(async () =>
38
+ {
39
+ TapTapAccount tapAccount = await TapTapLogin.Instance.GetCurrentTapAccount();
40
+ string loginKid = "";
41
+ string loginKey = "";
42
+ if (tapAccount != null && !string.IsNullOrEmpty(tapAccount.openId))
43
+ {
44
+ loginKey = tapAccount.accessToken.macKey;
45
+ loginKid = tapAccount.accessToken.kid;
46
+ }
47
+ Dictionary<string, object> loginData = new Dictionary<string, object>
48
+ {
49
+ { "kid", loginKid },
50
+ { "key", loginKey },
51
+ };
52
+ int region = isRND ? 2 : 0;
53
+ try
54
+ {
55
+ Dictionary<string, object> initConfig = new Dictionary<string, object>()
56
+ {
57
+ { "region", region },
58
+ { "log_to_console", 1 },
59
+ { "log_level", 3 },
60
+ { "data_dir", cacheDir },
61
+ { "client_id", options.clientId },
62
+ { "client_token", options.clientToken },
63
+ { "ua", TapHttpUtils.GenerateUserAgent() },
64
+ { "lang", Tracker.getServerLanguage() },
65
+ { "platform", "PC" },
66
+ { "device_id", deviceID },
67
+ { "sdk_artifact", "Unity" },
68
+ { "sdk_module_ver", TapTapCloudSave.Version },
69
+ { "sdk_token", loginData },
70
+ };
71
+ Log(" start invoke TapSdkCloudSaveInitialize result ");
72
+ string config = JsonConvert.SerializeObject(initConfig);
73
+ int initResult = TapCloudSaveWrapper.TapSdkCloudSaveInitialize(config);
74
+ Log("TapSdkCloudSaveInitialize result = " + initResult);
75
+ if (initResult < 0)
76
+ {
77
+ RunOnMainThread(() =>
78
+ {
79
+ if (currentSaveCallback != null && currentSaveCallback.Count > 0)
80
+ {
81
+ foreach (var callback in currentSaveCallback)
82
+ {
83
+ callback?.OnResult(TapCloudSaveResultCode.INIT_FAIL);
84
+ }
85
+ }
86
+ });
87
+ }
88
+ else
89
+ {
90
+ lock (_lockObj)
91
+ {
92
+ _hasInitNative = true;
93
+ }
94
+ }
95
+ }
96
+ catch (Exception e)
97
+ {
98
+ Log("TapSdkCloudSaveInitialize error " + e.Message);
99
+ }
100
+ });
101
+
102
+ EventManager.AddListener(EventManager.OnTapUserChanged, OnLoginInfoChanged);
103
+ }
104
+
105
+ public Task<ArchiveData> CreateArchive(
106
+ ArchiveMetadata metadata,
107
+ string archiveFilePath,
108
+ string archiveCoverPath
109
+ )
110
+ {
111
+ var taskSource = new TaskCompletionSource<ArchiveData>();
112
+ CheckPCLaunchState();
113
+ string seesionId = Guid.NewGuid().ToString();
114
+ const string method = "createArchive";
115
+ Task.Run(async () =>
116
+ {
117
+ bool hasInit = await CheckInitAndLoginState(method, seesionId);
118
+ if (!hasInit)
119
+ {
120
+ taskSource.TrySetException(new TapException(-1, "Init or login state check failed"));
121
+ return;
122
+ }
123
+ try
124
+ {
125
+ byte[] fileBytes = File.ReadAllBytes(archiveFilePath);
126
+ byte[] coverData = null;
127
+ if (!string.IsNullOrEmpty(archiveCoverPath))
128
+ {
129
+ coverData = File.ReadAllBytes(archiveCoverPath);
130
+ }
131
+ string metaValue = JsonConvert.SerializeObject(metadata);
132
+ string result = TapCloudSaveWrapper.CreateArchive(
133
+ metaValue,
134
+ fileBytes,
135
+ fileBytes.Length,
136
+ coverData,
137
+ coverData?.Length ?? 0
138
+ );
139
+ TapCloudSaveBaseResponse response =
140
+ JsonConvert.DeserializeObject<TapCloudSaveBaseResponse>(result);
141
+ if (response.success)
142
+ {
143
+ ArchiveData data = response.data.ToObject<ArchiveData>();
144
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
145
+ var archiveData = new ArchiveData()
146
+ {
147
+ FileId = data.FileId,
148
+ Uuid = data.Uuid,
149
+ Name = metadata.Name,
150
+ Summary = metadata.Summary,
151
+ Extra = metadata.Extra,
152
+ Playtime = metadata.Playtime,
153
+ };
154
+ taskSource.TrySetResult(archiveData);
155
+ }
156
+ else
157
+ {
158
+ try
159
+ {
160
+ TapCloudSaveError error = response.data.ToObject<TapCloudSaveError>();
161
+ Log(
162
+ "createArchive failed error = " + JsonConvert.SerializeObject(error)
163
+ );
164
+ TapCloudSaveTracker.Instance.TrackFailure(
165
+ method,
166
+ seesionId,
167
+ error.code,
168
+ error.msg ?? ""
169
+ );
170
+ taskSource.TrySetException(new TapException(error.code, $"创建存档失败: {error.msg}"));
171
+ }
172
+ catch (Exception e)
173
+ {
174
+ TapCloudSaveTracker.Instance.TrackFailure(
175
+ method,
176
+ seesionId,
177
+ -1,
178
+ "创建存档失败: 数据解析异常"
179
+ );
180
+ taskSource.TrySetException(new TapException(-1, "创建存档失败: 数据解析异常"));
181
+ }
182
+ }
183
+ }
184
+ catch (Exception e)
185
+ {
186
+ string msg = $"创建存档失败: {e.Message}";
187
+ TapCloudSaveTracker.Instance.TrackFailure(method, seesionId, -1, msg);
188
+ taskSource.TrySetException(new TapException(-1, msg));
189
+ }
190
+ });
191
+ return taskSource.Task;
192
+ }
193
+
194
+ public Task<ArchiveData> DeleteArchive(string archiveUuid)
195
+ {
196
+ var taskSource = new TaskCompletionSource<ArchiveData>();
197
+ CheckPCLaunchState();
198
+ string seesionId = Guid.NewGuid().ToString();
199
+ const string method = "deleteArchive";
200
+ Task.Run(async () =>
201
+ {
202
+ bool hasInit = await CheckInitAndLoginState(method, seesionId);
203
+ if (!hasInit)
204
+ {
205
+ taskSource.TrySetException(new TapException(-1, "Init or login state check failed"));
206
+ return;
207
+ }
208
+ try
209
+ {
210
+ string result = TapCloudSaveWrapper.DeleteArchive(archiveUuid);
211
+ TapCloudSaveBaseResponse response =
212
+ JsonConvert.DeserializeObject<TapCloudSaveBaseResponse>(result);
213
+ if (response.success)
214
+ {
215
+ ArchiveData archiveData = response.data.ToObject<ArchiveData>();
216
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
217
+ taskSource.TrySetResult(archiveData);
218
+ }
219
+ else
220
+ {
221
+ try
222
+ {
223
+ TapCloudSaveError error = response.data.ToObject<TapCloudSaveError>();
224
+ Log(
225
+ "deleteArchive failed error = " + JsonConvert.SerializeObject(error)
226
+ );
227
+ TapCloudSaveTracker.Instance.TrackFailure(
228
+ method,
229
+ seesionId,
230
+ error.code,
231
+ error.msg ?? ""
232
+ );
233
+ taskSource.TrySetException(new TapException(error.code, $"删除存档失败: {error.msg}"));
234
+ }
235
+ catch (Exception e)
236
+ {
237
+ TapCloudSaveTracker.Instance.TrackFailure(
238
+ method,
239
+ seesionId,
240
+ -1,
241
+ "删除存档失败: 数据解析异常"
242
+ );
243
+ taskSource.TrySetException(new TapException(-1, "删除存档失败: 数据解析异常"));
244
+ }
245
+ }
246
+ }
247
+ catch (Exception e)
248
+ {
249
+ string msg = $"删除失败: {e.Message}";
250
+ TapCloudSaveTracker.Instance.TrackFailure(method, seesionId, -1, msg);
251
+ taskSource.TrySetException(new TapException(-1, msg));
252
+ }
253
+ });
254
+ return taskSource.Task;
255
+ }
256
+
257
+ public Task<byte[]> GetArchiveCover(
258
+ string archiveUuid,
259
+ string archiveFileId
260
+ )
261
+ {
262
+ var taskSource = new TaskCompletionSource<byte[]>();
263
+ CheckPCLaunchState();
264
+ string seesionId = Guid.NewGuid().ToString();
265
+ const string method = "getArchiveCover";
266
+ Task.Run(async () =>
267
+ {
268
+ bool hasInit = await CheckInitAndLoginState(method, seesionId);
269
+ if (!hasInit)
270
+ {
271
+ taskSource.TrySetException(new TapException(-1, "Init or login state check failed"));
272
+ return;
273
+ }
274
+ try
275
+ {
276
+ byte[] result = TapCloudSaveWrapper.GetArchiveCover(
277
+ archiveUuid,
278
+ archiveFileId,
279
+ out int coverSize
280
+ );
281
+ if (coverSize >= 0)
282
+ {
283
+ taskSource.TrySetResult(result);
284
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
285
+ }
286
+ else
287
+ {
288
+ try
289
+ {
290
+ TapCloudSaveBaseResponse response =
291
+ JsonConvert.DeserializeObject<TapCloudSaveBaseResponse>(
292
+ Encoding.UTF8.GetString(result)
293
+ );
294
+ TapCloudSaveError error = response.data.ToObject<TapCloudSaveError>();
295
+ Log(
296
+ "getArchiveCover failed error = " + JsonConvert.SerializeObject(error)
297
+ );
298
+ TapCloudSaveTracker.Instance.TrackFailure(
299
+ method,
300
+ seesionId,
301
+ error.code,
302
+ error.msg ?? ""
303
+ );
304
+ taskSource.TrySetException(new TapException(error.code, $"获取封面失败: {error.msg}"));
305
+ }
306
+ catch (Exception e)
307
+ {
308
+ TapCloudSaveTracker.Instance.TrackFailure(
309
+ method,
310
+ seesionId,
311
+ -1,
312
+ "获取封面失败: 数据解析异常"
313
+ );
314
+ taskSource.TrySetException(new TapException(-1, "获取封面失败: 数据解析异常"));
315
+ }
316
+ }
317
+ }
318
+ catch (Exception e)
319
+ {
320
+ string msg = $"获取封面失败: {e.Message}";
321
+ TapCloudSaveTracker.Instance.TrackFailure(method, seesionId, -1, msg);
322
+ taskSource.TrySetException(new TapException(-1, msg));
323
+ }
324
+ });
325
+ return taskSource.Task;
326
+ }
327
+
328
+ public Task<byte[]> GetArchiveData(
329
+ string archiveUuid,
330
+ string archiveFileId
331
+ )
332
+ {
333
+ var taskSource = new TaskCompletionSource<byte[]>();
334
+ CheckPCLaunchState();
335
+ string seesionId = Guid.NewGuid().ToString();
336
+ const string method = "getArchiveData";
337
+ Task.Run(async () =>
338
+ {
339
+ bool hasInit = await CheckInitAndLoginState(method, seesionId);
340
+ if (!hasInit)
341
+ {
342
+ taskSource.TrySetException(new TapException(-1, "Init or login state check failed"));
343
+ return;
344
+ }
345
+ try
346
+ {
347
+ byte[] result = TapCloudSaveWrapper.GetArchiveData(
348
+ archiveUuid,
349
+ archiveFileId,
350
+ out int fileSize
351
+ );
352
+ if (fileSize >= 0)
353
+ {
354
+ taskSource.TrySetResult(result);
355
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
356
+ }
357
+ else
358
+ {
359
+ try
360
+ {
361
+ TapCloudSaveBaseResponse response =
362
+ JsonConvert.DeserializeObject<TapCloudSaveBaseResponse>(
363
+ Encoding.UTF8.GetString(result)
364
+ );
365
+ TapCloudSaveError error = response.data.ToObject<TapCloudSaveError>();
366
+ Log(
367
+ "getArchiveData failed error = " + JsonConvert.SerializeObject(error)
368
+ );
369
+ TapCloudSaveTracker.Instance.TrackFailure(
370
+ method,
371
+ seesionId,
372
+ error.code,
373
+ error.msg ?? ""
374
+ );
375
+ taskSource.TrySetException(new TapException(error.code, $"获取存档失败: {error.msg}"));
376
+ }
377
+ catch (Exception e)
378
+ {
379
+ TapCloudSaveTracker.Instance.TrackFailure(
380
+ method,
381
+ seesionId,
382
+ -1,
383
+ "获取存档失败: 数据解析异常"
384
+ );
385
+ taskSource.TrySetException(new TapException(-1, "获取存档失败: 数据解析异常"));
386
+ }
387
+ }
388
+ }
389
+ catch (Exception e)
390
+ {
391
+ string msg = $"获取存档失败: {e.Message}";
392
+ TapCloudSaveTracker.Instance.TrackFailure(method, seesionId, -1, msg);
393
+ taskSource.TrySetException(new TapException(-1, msg));
394
+ }
395
+ });
396
+ return taskSource.Task;
397
+ }
398
+
399
+ public Task<List<ArchiveData>> GetArchiveList()
400
+ {
401
+ var taskSource = new TaskCompletionSource<List<ArchiveData>>();
402
+ CheckPCLaunchState();
403
+ string seesionId = Guid.NewGuid().ToString();
404
+ const string method = "getArchiveList";
405
+ Task.Run(async () =>
406
+ {
407
+ bool hasInit = await CheckInitAndLoginState(method, seesionId);
408
+ if (!hasInit)
409
+ {
410
+ taskSource.TrySetException(new TapException(-1, "Init or login state check failed"));
411
+ return;
412
+ }
413
+ try
414
+ {
415
+ string result = TapCloudSaveWrapper.GetArchiveList();
416
+ TapCloudSaveBaseResponse response =
417
+ JsonConvert.DeserializeObject<TapCloudSaveBaseResponse>(result);
418
+ if (response.success)
419
+ {
420
+ TapCloudSaveArchiveListResponse archiveDatas =
421
+ response.data.ToObject<TapCloudSaveArchiveListResponse>();
422
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
423
+ taskSource.TrySetResult(archiveDatas.saves);
424
+ }
425
+ else
426
+ {
427
+ try
428
+ {
429
+ TapCloudSaveError error = response.data.ToObject<TapCloudSaveError>();
430
+ Log(
431
+ "getArchiveList failed error = " + JsonConvert.SerializeObject(error)
432
+ );
433
+ TapCloudSaveTracker.Instance.TrackFailure(
434
+ method,
435
+ seesionId,
436
+ error.code,
437
+ error.msg ?? ""
438
+ );
439
+ taskSource.TrySetException(new TapException(error.code, $"获取存档列表失败: {error.msg}"));
440
+ }
441
+ catch (Exception e)
442
+ {
443
+ TapCloudSaveTracker.Instance.TrackFailure(
444
+ method,
445
+ seesionId,
446
+ -1,
447
+ "获取存档列表失败: 数据解析异常"
448
+ );
449
+ taskSource.TrySetException(new TapException(-1, "获取存档列表失败: 数据解析异常"));
450
+ }
451
+ }
452
+ }
453
+ catch (Exception e)
454
+ {
455
+ string msg = $"获取存档列表失败: {e.Message}";
456
+ TapCloudSaveTracker.Instance.TrackFailure(method, seesionId, -1, msg);
457
+ taskSource.TrySetException(new TapException(-1, msg));
458
+ }
459
+ });
460
+ return taskSource.Task;
461
+ }
462
+
463
+ public void RegisterCloudSaveCallback(ITapCloudSaveCallback callback)
464
+ {
465
+ currentSaveCallback?.Clear();
466
+ string seesionId = Guid.NewGuid().ToString();
467
+ const string method = "registerCloudSaveCallback";
468
+ TapCloudSaveTracker.Instance.TrackStart(method, seesionId);
469
+ if (currentSaveCallback == null)
470
+ {
471
+ currentSaveCallback = new List<ITapCloudSaveCallback>();
472
+ }
473
+ if (!currentSaveCallback.Contains(callback))
474
+ {
475
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
476
+ currentSaveCallback.Add(callback);
477
+ }
478
+ else
479
+ {
480
+ TapCloudSaveTracker.Instance.TrackFailure(
481
+ method,
482
+ seesionId,
483
+ errorMessage: "callback has already registered"
484
+ );
485
+ }
486
+ }
487
+
488
+ public Task<ArchiveData> UpdateArchive(
489
+ string archiveUuid,
490
+ ArchiveMetadata metadata,
491
+ string archiveFilePath,
492
+ string archiveCoverPath
493
+ )
494
+ {
495
+ var taskSource = new TaskCompletionSource<ArchiveData>();
496
+ CheckPCLaunchState();
497
+ string seesionId = Guid.NewGuid().ToString();
498
+ const string method = "updateArchive";
499
+ Task.Run(async () =>
500
+ {
501
+ bool hasInit = await CheckInitAndLoginState(method, seesionId);
502
+ if (!hasInit)
503
+ {
504
+ taskSource.TrySetException(new TapException(-1, "Init or login state check failed"));
505
+ return;
506
+ }
507
+ try
508
+ {
509
+ byte[] fileBytes = File.ReadAllBytes(archiveFilePath);
510
+ byte[] coverData = null;
511
+ if (!string.IsNullOrEmpty(archiveCoverPath))
512
+ {
513
+ coverData = File.ReadAllBytes(archiveCoverPath);
514
+ }
515
+ string metaValue = JsonConvert.SerializeObject(metadata);
516
+ string result = TapCloudSaveWrapper.UpdateArchive(
517
+ archiveUuid,
518
+ metaValue,
519
+ fileBytes,
520
+ fileBytes.Length,
521
+ coverData,
522
+ coverData?.Length ?? 0
523
+ );
524
+ TapCloudSaveBaseResponse response =
525
+ JsonConvert.DeserializeObject<TapCloudSaveBaseResponse>(result);
526
+ if (response.success)
527
+ {
528
+ ArchiveData data = response.data.ToObject<ArchiveData>();
529
+ TapCloudSaveTracker.Instance.TrackSuccess(method, seesionId);
530
+ taskSource.TrySetResult(data);
531
+ }
532
+ else
533
+ {
534
+ try
535
+ {
536
+ TapCloudSaveError error = response.data.ToObject<TapCloudSaveError>();
537
+ Log(
538
+ "updateArchive failed error = " + JsonConvert.SerializeObject(error)
539
+ );
540
+ TapCloudSaveTracker.Instance.TrackFailure(
541
+ method,
542
+ seesionId,
543
+ error.code,
544
+ error.msg ?? ""
545
+ );
546
+ taskSource.TrySetException(new TapException(error.code, $"更新存档失败: {error.msg}"));
547
+ }
548
+ catch (Exception e)
549
+ {
550
+ TapCloudSaveTracker.Instance.TrackFailure(
551
+ method,
552
+ seesionId,
553
+ -1,
554
+ "更新存档失败: 数据解析异常"
555
+ );
556
+ taskSource.TrySetException(new TapException(-1, "更新存档失败: 数据解析异常"));
557
+ }
558
+ }
559
+ }
560
+ catch (Exception e)
561
+ {
562
+ string msg = $"更新存档失败: {e.Message}";
563
+ TapCloudSaveTracker.Instance.TrackFailure(method, seesionId, -1, msg);
564
+ taskSource.TrySetException(new TapException(-1, msg));
565
+ }
566
+ });
567
+ return taskSource.Task;
568
+ }
569
+
570
+ private async Task<bool> CheckInitAndLoginState(string method, string sessionId)
571
+ {
572
+ if (TapCoreStandalone.CheckInitState())
573
+ {
574
+ lock (_lockObj)
575
+ {
576
+ if (!_hasInitNative)
577
+ {
578
+ Log("not init success, so return", true);
579
+ return false;
580
+ }
581
+ }
582
+ TapCloudSaveTracker.Instance.TrackStart(method, sessionId);
583
+ TapTapAccount tapAccount = await TapTapLogin.Instance.GetCurrentTapAccount();
584
+ if (tapAccount != null && !string.IsNullOrEmpty(tapAccount.openId))
585
+ {
586
+ return true;
587
+ }
588
+ else
589
+ {
590
+ if (currentSaveCallback != null && currentSaveCallback.Count > 0)
591
+ {
592
+ foreach (var callback in currentSaveCallback)
593
+ {
594
+ callback?.OnResult(TapCloudSaveResultCode.NEED_LOGIN);
595
+ }
596
+ }
597
+ TapCloudSaveTracker.Instance.TrackFailure(method, sessionId, -1, "not login");
598
+ return false;
599
+ }
600
+ }
601
+ return false;
602
+ }
603
+
604
+ /// <summary>
605
+ /// 检查是否通过 PC 启动校验
606
+ /// </summary>
607
+ private void CheckPCLaunchState()
608
+ {
609
+ #if UNITY_STANDALONE_WIN
610
+ if (!TapClientStandalone.isPassedInLaunchedFromTapTapPCCheck())
611
+ {
612
+ throw new Exception("TapCloudSave method must be invoked after isLaunchedFromTapTapPC succeed");
613
+ }
614
+ #endif
615
+ }
616
+
617
+ internal void OnLoginInfoChanged(object data)
618
+ {
619
+ lock (_lockObj)
620
+ {
621
+ if (_hasInitNative)
622
+ {
623
+ Task.Run(async () =>
624
+ {
625
+ TapTapAccount tapAccount =
626
+ await TapTapLogin.Instance.GetCurrentTapAccount();
627
+ string loginKid = "";
628
+ string loginKey = "";
629
+ if (tapAccount != null && !string.IsNullOrEmpty(tapAccount.openId))
630
+ {
631
+ loginKey = tapAccount.accessToken.macKey;
632
+ loginKid = tapAccount.accessToken.kid;
633
+ }
634
+ Dictionary<string, object> loginData = new Dictionary<string, object>
635
+ {
636
+ { "kid", loginKid },
637
+ { "key", loginKey },
638
+ };
639
+ int result = TapCloudSaveWrapper.TapSdkCloudSaveUpdateAccessToken(
640
+ JsonConvert.SerializeObject(loginData)
641
+ );
642
+ Log("update login msg result = " + result);
643
+ });
644
+ }
645
+ }
646
+ }
647
+
648
+ private void RunOnMainThread(Action action)
649
+ {
650
+ TapLoom.QueueOnMainThread(action);
651
+ }
652
+
653
+ private void Log(string msg, bool isError = false)
654
+ {
655
+ if (cloudSaveLog == null)
656
+ {
657
+ cloudSaveLog = new TapLog("TapCloudSave");
658
+ }
659
+ if (!string.IsNullOrEmpty(msg))
660
+ {
661
+ if (isError)
662
+ {
663
+ cloudSaveLog.Error(msg);
664
+ }
665
+ else
666
+ {
667
+ cloudSaveLog.Log(msg);
668
+ }
669
+ }
670
+ }
671
+ }
672
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: de4da063a6acb40e0a54d5b63ad0e8c9
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: ac7968c96d3e84ff897aa47ef7cb6067
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant: