添加iossdk接口

dev_chengFeng
jl_ios 2020-08-15 10:13:32 +08:00
parent 8be4e2745b
commit e5015da253
5 changed files with 139 additions and 69 deletions

View File

@ -7,6 +7,7 @@ namespace SDK
{ {
public virtual void Init() { } public virtual void Init() { }
public virtual void Login() { } public virtual void Login() { }
public virtual void Logout() { }
public virtual void Exit() { } public virtual void Exit() { }
public virtual void SubmitExtraData(SDKSubmitExtraDataArgs args) { } public virtual void SubmitExtraData(SDKSubmitExtraDataArgs args) { }
public virtual void Pay(SDKPayArgs args) { } public virtual void Pay(SDKPayArgs args) { }
@ -14,6 +15,7 @@ namespace SDK
public virtual string GetDeviceID() { return ""; } public virtual string GetDeviceID() { return ""; }
public virtual string GetIMEICode() { return ""; } public virtual string GetIMEICode() { return ""; }
public virtual string GetPayOrderID() { return ""; } public virtual string GetPayOrderID() { return ""; }
public virtual void CustomEvent(string eventName, string eventDesc) { }
public virtual void ShotCapture() { } public virtual void ShotCapture() { }
private Queue<Message> messages = new Queue<Message>(); private Queue<Message> messages = new Queue<Message>();
public void PushMessage(Message msg) { lock (messages) { messages.Enqueue(msg); } } public void PushMessage(Message msg) { lock (messages) { messages.Enqueue(msg); } }

View File

@ -10,80 +10,65 @@ namespace SDK
{ {
public class iOSProxy : Proxy public class iOSProxy : Proxy
{ {
////初始化 // //初始化
//[DllImport("__Internal")] // [DllImport("__Internal")]
//private static extern void m_KTInit(string totalStr); // private static extern void m_SDK_Init();
//public override void Init()//SDKInitArgs args) // public override void Init()
//{ // {
// //StringBuilder sb = new StringBuilder(); // m_SDK_Init();
// //sb.AppendFormat("{0}#{1}", args.appid, args.appkey); // }
// //m_KTInit(sb.ToString());
//} ////登录
//[DllImport("__Internal")]
////登录 //private static extern void m_SDK_Login();
//[DllImport("__Internal")] //public override void Login()
//private static extern void m_KTIogin(); //{
//public override void Login() // m_SDK_Login();
//{ //}
// m_KTIogin();
//} ////登录
//[DllImport("__Internal")]
//private static extern void m_SDK_Logout();
//public override void Logout()
//{
// m_SDK_Logout();
//}
////退出游戏 ////退出游戏
//[DllImport("__Internal")] //[DllImport("__Internal")]
//private static extern void m_KTExit(); //private static extern void m_SDK_Exit();
//public override void Exit() //public override void Exit()
//{ //{
// m_KTExit(); // m_SDK_Exit();
//} //}
//[DllImport("__Internal")]
//private static extern void m_KTPay(string totalStr);
//public override void Pay(SDKPayArgs args)
//{
// StringBuilder sb = new StringBuilder();
// sb.AppendFormat("{0}#{1}#{2}#{3}#{4}#{5}#{6}#{7}#{8}#{9}#{10}#{11}#{12}#{13}#{14}",
// AppConst.TokenStr,
// args.zoneId,
// args.serverID,
// args.serverName,
// args.roleID,
// args.roleName,
// args.roleLevel,
// args.productId,
// args.productName,
// args.roleID,
// "",//extendbox
// "",//gateway
// AppConst.OpenId,
// "",//payext
// args.price);
// m_KTPay(sb.ToString());
//}
////sdk 获取设备标识 ////退出游戏
//[DllImport("__Internal")] //[DllImport("__Internal")]
//private static extern string m_KTGetDeviceID(); //private static extern void m_SDK_SubmitExtraData(string areaName, string roleName, string roleGrade);
//public override string GetDeviceID() //public override void SubmitExtraData(SDKSubmitExtraDataArgs args)
//{ //{
// return m_KTGetDeviceID(); // m_SDK_SubmitExtraData(args.zoneID, args.roleID, args.roleLevel);
//} //}
////sdk 获取IMEI
//[DllImport("__Internal")]
//private static extern string m_KTGetIMEICode();
//public override string GetIMEICode()
//{
// return m_KTGetIMEICode();
//}
////sdk获取支付订单号 //[DllImport("__Internal")]
//[DllImport("__Internal")] //private static extern void m_SDK_Pay(string money, string detail, string csId, string csName, string pid);
//private static extern string m_KTGetPayOrderID(); //public override void Pay(SDKPayArgs args)
//public override string GetPayOrderID() //{
//{ // m_SDK_Pay(args.price.ToString(), args.productDesc, args.productId, args.productName, args.payNotifyUrl);
// return m_KTGetPayOrderID(); //}
//}
////sdk获取支付订单号
//[DllImport("__Internal")]
//private static extern string m_SDK_CustomEvent(string eventName);
//public override void CustomEvent(string eventName, string eventDesc)
//{
// m_SDK_CustomEvent(eventName);
//}
} }
} }
#endif #endif

View File

@ -124,6 +124,11 @@ namespace SDK
{ {
proxy.Login(); proxy.Login();
} }
//sdk 登录
public void Logout()
{
proxy.Logout();
}
//sdk 数据上报 //sdk 数据上报
public void SubmitExtraData(SDKSubmitExtraDataArgs args) public void SubmitExtraData(SDKSubmitExtraDataArgs args)
{ {

View File

@ -24,6 +24,10 @@ public class AndroidDeviceInfo
private AndroidDeviceInfo() private AndroidDeviceInfo()
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
using (var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) using (var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{ {
context = up.GetStatic<AndroidJavaObject>("currentActivity"); context = up.GetStatic<AndroidJavaObject>("currentActivity");
@ -33,6 +37,7 @@ public class AndroidDeviceInfo
jo.Call("Init", context); jo.Call("Init", context);
} }
} }
#endif
} }
public void DeviceInit() public void DeviceInit()
{ {
@ -44,7 +49,11 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetDeviceBrand"); type = jo.CallStatic<string>("GetDeviceBrand");
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -58,7 +67,11 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetDeviceModel"); type = jo.CallStatic<string>("GetDeviceModel");
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -72,7 +85,11 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetSystemVersion"); type = jo.CallStatic<string>("GetSystemVersion");
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -86,7 +103,11 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetScreenRatio",context); type = jo.CallStatic<string>("GetScreenRatio",context);
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -100,7 +121,12 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetOperatorName", context); type = jo.CallStatic<string>("GetOperatorName", context);
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -115,7 +141,11 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetNetworkType", context); type = jo.CallStatic<string>("GetNetworkType", context);
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -129,7 +159,11 @@ public class AndroidDeviceInfo
string type = ""; string type = "";
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
type = jo.CallStatic<string>("GetLocalIpAddress", context); type = jo.CallStatic<string>("GetLocalIpAddress", context);
#endif
} }
catch (Exception e) catch (Exception e)
{ {
@ -140,35 +174,60 @@ public class AndroidDeviceInfo
//sdk 获取设备标识 //sdk 获取设备标识
public string GetDeviceID() public string GetDeviceID()
{ {
#if UNITY_IOS
return "";
#elif UNITY_ANDROID
return jo.CallStatic<string>("GetDeviceID"); return jo.CallStatic<string>("GetDeviceID");
#endif
} }
//sdk 获取IMEI //sdk 获取IMEI
public string GetIMEICode() public string GetIMEICode()
{ {
#if UNITY_IOS
return "";
#elif UNITY_ANDROID
return jo.CallStatic<string>("GetIMEICode"); return jo.CallStatic<string>("GetIMEICode");
#endif
} }
//sdk 获取app名 //sdk 获取app名
public string GetAppName() public string GetAppName()
{ {
#if UNITY_IOS
return "";
#elif UNITY_ANDROID
return jo.CallStatic<string>("getAppName"); return jo.CallStatic<string>("getAppName");
#endif
} }
//sdk 获取版本名称 //sdk 获取版本名称
public string GetVersionName() public string GetVersionName()
{ {
#if UNITY_IOS
return "";
#elif UNITY_ANDROID
return jo.CallStatic<string>("getVersionName"); return jo.CallStatic<string>("getVersionName");
#endif
} }
//sdk 获取版本号 //sdk 获取版本号
public int GetVersionCode() public int GetVersionCode()
{ {
#if UNITY_IOS
return 0;
#elif UNITY_ANDROID
return jo.CallStatic<int>("getVersionCode"); return jo.CallStatic<int>("getVersionCode");
#endif
} }
//sdk 获取包名 //sdk 获取包名
public string GetPackageName() public string GetPackageName()
{ {
#if UNITY_IOS
return "";
#elif UNITY_ANDROID
return jo.CallStatic<string>("getPackageName"); return jo.CallStatic<string>("getPackageName");
#endif
} }
@ -178,12 +237,22 @@ public class AndroidDeviceInfo
//暂时存放--复制粘贴功能(本不隶属于此) //暂时存放--复制粘贴功能(本不隶属于此)
public void SetCopyValue(string str) public void SetCopyValue(string str)
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
jo.CallStatic("CopyToClipBoard", str); jo.CallStatic("CopyToClipBoard", str);
#endif
} }
public string GetPastValue() public string GetPastValue()
{ {
string result = ""; string result = "";
#if UNITY_IOS
#elif UNITY_ANDROID
result = jo.CallStatic<string>("PasteFromClipBoard", context); result = jo.CallStatic<string>("PasteFromClipBoard", context);
#endif
return result; return result;
} }

View File

@ -26,6 +26,9 @@ public class NotchScreenUtil
private NotchScreenUtil() private NotchScreenUtil()
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
using (var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) using (var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{ {
context = up.GetStatic<AndroidJavaObject>("currentActivity"); context = up.GetStatic<AndroidJavaObject>("currentActivity");
@ -35,6 +38,7 @@ public class NotchScreenUtil
jo.Call("Init", context); jo.Call("Init", context);
} }
} }
#endif
} }
@ -47,15 +51,20 @@ public class NotchScreenUtil
public int GetNotchHeight() public int GetNotchHeight()
{ {
int height = 0; int height = 0;
try try
{ {
#if UNITY_IOS
#elif UNITY_ANDROID
height = jo.CallStatic<int>("getNotchHeight"); height = jo.CallStatic<int>("getNotchHeight");
#endif
} }
catch (Exception e) catch (Exception e)
{ {
Debug.LogError(e); Debug.LogError(e);
} }
return height; return height;
} }