TapCoreMobile.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using TapSDK.Core.Internal;
  6. using TapSDK.Core.Internal.Utils;
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. using Newtonsoft.Json;
  10. using TapSDK.Core.Internal.Log;
  11. namespace TapSDK.Core.Mobile
  12. {
  13. public class TapCoreMobile : ITapCorePlatform
  14. {
  15. private EngineBridge Bridge = EngineBridge.GetInstance();
  16. public TapCoreMobile()
  17. {
  18. TapLog.Log("TapCoreMobile constructor");
  19. TapLoom.Initialize();
  20. EngineBridgeInitializer.Initialize();
  21. }
  22. public void Init(TapTapSdkOptions coreOption, TapTapSdkBaseOptions[] otherOptions)
  23. {
  24. TapLog.Log("TapCoreMobile SDK inited");
  25. SetPlatformAndVersion(TapTapSDK.SDKPlatform, TapTapSDK.Version);
  26. string coreOptionsJson = JsonUtility.ToJson(coreOption);
  27. string[] otherOptionsJson = otherOptions.Select(option => JsonConvert.SerializeObject(option)).ToArray();
  28. Bridge.CallHandler(EngineBridgeInitializer.GetBridgeServer()
  29. .Method("init")
  30. .Args("coreOption", coreOptionsJson)
  31. .Args("otherOptions", otherOptionsJson)
  32. .CommandBuilder());
  33. }
  34. private void SetPlatformAndVersion(string platform, string version)
  35. {
  36. TapLog.Log("TapCoreMobile SetPlatformAndVersion called with platform: " + platform + " and version: " + version);
  37. Bridge.CallHandler(EngineBridgeInitializer.GetBridgeServer()
  38. .Method("setPlatformAndVersion")
  39. .Args("platform", TapTapSDK.SDKPlatform)
  40. .Args("version", TapTapSDK.Version)
  41. .CommandBuilder());
  42. SetSDKArtifact("Unity");
  43. }
  44. private void SetSDKArtifact(string value)
  45. {
  46. TapLog.Log("TapCoreMobile SetSDKArtifact called with value: " + value);
  47. Bridge.CallHandler(EngineBridgeInitializer.GetBridgeServer()
  48. .Method("setSDKArtifact")
  49. .Args("artifact", "Unity")
  50. .CommandBuilder());
  51. }
  52. public void Init(TapTapSdkOptions coreOption)
  53. {
  54. Init(coreOption, new TapTapSdkBaseOptions[0]);
  55. }
  56. public void UpdateLanguage(TapTapLanguageType language)
  57. {
  58. TapLog.Log("TapCoreMobile UpdateLanguage language: " + language);
  59. Bridge.CallHandler(EngineBridgeInitializer.GetBridgeServer()
  60. .Method("updateLanguage")
  61. .Args("language", (int)language)
  62. .CommandBuilder());
  63. }
  64. public Task<bool> IsLaunchedFromTapTapPC()
  65. {
  66. return Task.FromResult(false);
  67. }
  68. }
  69. }