using UnityEngine;
|
|
using System.Collections;
|
|
using LuaInterface;
|
|
using LuaFramework;
|
|
|
|
#if UNITY_IPHONE || UNITY_IOS
|
|
using System.Runtime.InteropServices;
|
|
#endif
|
|
|
|
public class SDKManager : Manager
|
|
{
|
|
AndroidJavaObject jo = null;
|
|
|
|
private static LuaFunction m_callback_func = null;
|
|
private static bool m_is_android = false;
|
|
private static bool m_is_ios = false;
|
|
|
|
#if UNITY_IPHONE || UNITY_IOS
|
|
[DllImport("__Internal")]
|
|
private static extern void CallIOSSDKFunc(string arg);
|
|
[DllImport("__Internal")]
|
|
private static extern int CallIOSIntFunc(string arg);
|
|
[DllImport("__Internal")]
|
|
private static extern bool CallIOSBoolFunc(string arg);
|
|
[DllImport("__Internal")]
|
|
private static extern string CallIOSStringFunc(string arg);
|
|
#endif
|
|
|
|
void Start()
|
|
{
|
|
if (Application.platform == RuntimePlatform.Android)
|
|
m_is_android = true;
|
|
|
|
if (Application.platform == RuntimePlatform.IPhonePlayer)
|
|
m_is_ios = true;
|
|
}
|
|
|
|
void Update ()
|
|
{
|
|
}
|
|
|
|
public void CallSDKFunc(string data)
|
|
{
|
|
if (!AppConst.SupportSDKMode)
|
|
return;
|
|
|
|
LogManager.LogWarning("CallSDKFunc:" + data);
|
|
if (m_is_android)
|
|
{
|
|
jo.Call("GameCallInto", data);
|
|
}
|
|
|
|
if(m_is_ios)
|
|
{
|
|
#if UNITY_IPHONE || UNITY_IOS
|
|
CallIOSSDKFunc(data);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
public void RegisterCallbackFunc(LuaFunction func)
|
|
{
|
|
if (!AppConst.SupportSDKMode)
|
|
return;
|
|
|
|
if (m_is_android)
|
|
{
|
|
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
|
jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
|
|
}
|
|
|
|
m_callback_func = func;
|
|
}
|
|
|
|
public void CallGameFunc(string func_data)
|
|
{
|
|
Debug.Log("CallGameFunc:" + func_data);
|
|
|
|
if ( m_callback_func != null )
|
|
{
|
|
m_callback_func.Call(func_data);
|
|
}
|
|
|
|
if (func_data.Contains("ReceiveMemoryWarning"))
|
|
AppConst.IsLowMemoryState = true;
|
|
}
|
|
|
|
public int CallIntFunc(string data)
|
|
{
|
|
if (!AppConst.SupportSDKMode)
|
|
return 0;
|
|
|
|
if (m_is_android)
|
|
return jo.Call<int>("CallIntFunc", data);
|
|
|
|
if (m_is_ios)
|
|
{
|
|
#if UNITY_IPHONE || UNITY_IOS
|
|
return CallIOSIntFunc(data);
|
|
#endif
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public bool CallBoolFunc(string data)
|
|
{
|
|
if (!AppConst.SupportSDKMode)
|
|
return false;
|
|
|
|
if (m_is_android)
|
|
return jo.Call<bool>("CallBoolFunc", data);
|
|
|
|
if (m_is_ios)
|
|
{
|
|
#if UNITY_IPHONE || UNITY_IOS
|
|
return CallIOSBoolFunc(data);
|
|
#endif
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public string CallStringFunc(string data)
|
|
{
|
|
if (!AppConst.SupportSDKMode)
|
|
return "";
|
|
|
|
if (m_is_android)
|
|
return jo.Call<string>("CallStringFunc", data);
|
|
|
|
if (m_is_ios)
|
|
{
|
|
#if UNITY_IPHONE || UNITY_IOS
|
|
return CallIOSStringFunc(data);
|
|
#endif
|
|
}
|
|
return "";
|
|
}
|
|
}
|