源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

140 行
3.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using LuaInterface;
  4. using LuaFramework;
  5. #if UNITY_IPHONE || UNITY_IOS
  6. using System.Runtime.InteropServices;
  7. #endif
  8. public class SDKManager : Manager
  9. {
  10. AndroidJavaObject jo = null;
  11. private static LuaFunction m_callback_func = null;
  12. private static bool m_is_android = false;
  13. private static bool m_is_ios = false;
  14. #if UNITY_IPHONE || UNITY_IOS
  15. [DllImport("__Internal")]
  16. private static extern void CallIOSSDKFunc(string arg);
  17. [DllImport("__Internal")]
  18. private static extern int CallIOSIntFunc(string arg);
  19. [DllImport("__Internal")]
  20. private static extern bool CallIOSBoolFunc(string arg);
  21. [DllImport("__Internal")]
  22. private static extern string CallIOSStringFunc(string arg);
  23. #endif
  24. void Start()
  25. {
  26. if (Application.platform == RuntimePlatform.Android)
  27. m_is_android = true;
  28. if (Application.platform == RuntimePlatform.IPhonePlayer)
  29. m_is_ios = true;
  30. }
  31. void Update ()
  32. {
  33. }
  34. public void CallSDKFunc(string data)
  35. {
  36. if (!AppConst.SupportSDKMode)
  37. return;
  38. LogManager.LogWarning("CallSDKFunc:" + data);
  39. if (m_is_android)
  40. {
  41. jo.Call("GameCallInto", data);
  42. }
  43. if(m_is_ios)
  44. {
  45. #if UNITY_IPHONE || UNITY_IOS
  46. CallIOSSDKFunc(data);
  47. #endif
  48. }
  49. }
  50. public void RegisterCallbackFunc(LuaFunction func)
  51. {
  52. if (!AppConst.SupportSDKMode)
  53. return;
  54. if (m_is_android)
  55. {
  56. AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  57. jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
  58. }
  59. m_callback_func = func;
  60. }
  61. public void CallGameFunc(string func_data)
  62. {
  63. Debug.Log("CallGameFunc:" + func_data);
  64. if ( m_callback_func != null )
  65. {
  66. m_callback_func.Call(func_data);
  67. }
  68. if (func_data.Contains("ReceiveMemoryWarning"))
  69. AppConst.IsLowMemoryState = true;
  70. }
  71. public int CallIntFunc(string data)
  72. {
  73. if (!AppConst.SupportSDKMode)
  74. return 0;
  75. if (m_is_android)
  76. return jo.Call<int>("CallIntFunc", data);
  77. if (m_is_ios)
  78. {
  79. #if UNITY_IPHONE || UNITY_IOS
  80. return CallIOSIntFunc(data);
  81. #endif
  82. }
  83. return 0;
  84. }
  85. public bool CallBoolFunc(string data)
  86. {
  87. if (!AppConst.SupportSDKMode)
  88. return false;
  89. if (m_is_android)
  90. return jo.Call<bool>("CallBoolFunc", data);
  91. if (m_is_ios)
  92. {
  93. #if UNITY_IPHONE || UNITY_IOS
  94. return CallIOSBoolFunc(data);
  95. #endif
  96. }
  97. return false;
  98. }
  99. public string CallStringFunc(string data)
  100. {
  101. if (!AppConst.SupportSDKMode)
  102. return "";
  103. if (m_is_android)
  104. return jo.Call<string>("CallStringFunc", data);
  105. if (m_is_ios)
  106. {
  107. #if UNITY_IPHONE || UNITY_IOS
  108. return CallIOSStringFunc(data);
  109. #endif
  110. }
  111. return "";
  112. }
  113. }