changhong/wb_unity_pro/Assets/Scripts/DxyVest.cs

124 lines
3.5 KiB
C#

using System.Runtime.InteropServices;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class DxyVest
{
#if UNITY_EDITOR
public static int Start(string key)
{
return 0;
}
#elif UNITY_ANDROID
// 将jar文件放如Assets/Plugins/Android目录下
private const string packageName = "cn.ay.clinkapi.Api";
//private const string packageName = "com.dun.clinkapi.Api";
public static int Start(string key)
{
Debug.LogError("bluesheet,dxyvest:start");
AndroidJavaObject appvestObject = new AndroidJavaObject(packageName);
return appvestObject.Call<int>("start",key);
}
//public static int init(string accesskey, string uuid)
//{
// AndroidJavaObject appvestObject = new AndroidJavaObject(packageName);
// return appvestObject.CallStatic<int>("init", accesskey, uuid);
//}
//public static int getServerIPAndPort(ref securityConnection conn, string host, int port)
//{
// AndroidJavaObject appvestObject = new AndroidJavaObject(packageName);
// AndroidJavaObject connObject = appvestObject.CallStatic<AndroidJavaObject>("getServerIPAndPort", host, port);
// AndroidJavaObject intObject = connObject.Call<AndroidJavaObject>("getServerPort");
// conn.port = intObject.Call<int>("intValue");
// conn.ip = connObject.Call<string>("getServerIp");
// if (conn.ip != "" && conn.port != -1)
// {
// return 0;
// }
// return -1;
//}
//public static int getClientIP(StringBuilder buffer, int buf_size)
//{
// AndroidJavaObject appvestObject = new AndroidJavaObject(packageName);
// string clientip = appvestObject.CallStatic<string>("getClientIP");
// buffer.Append(clientip);
// return 0;
//}
#elif UNITY_IOS
[DllImport("__Internal")]
static extern int _start(string key);
public static int Start(string key)
{
return _start(key);
}
//[DllImport("__Internal")]
//static extern int _Init(string key, string id);
//[DllImport("__Internal")]
//static extern string _GetServerIPAndPort(string host, int id);
//public static int init(string key, string id)
//{
// return _Init(key, id);
//}
//public static int getServerIPAndPort(ref securityConnection conn, string host, int port)
//{
// string currentip=_GetServerIPAndPort(host, port);
// if(!string.IsNullOrEmpty(currentip))
// {
// int rc=LoadNetP(ref conn, currentip);
// if(rc==0)
// {
// return rc;
// }
// }
// return 1;
//}
//private static int LoadNetP(ref securityConnection conn, string host)
//{
// if (!string.IsNullOrEmpty(host))
// {
// string[] str = host.Split(':');
// string port = str[str.Length - 1];
// int len = str[str.Length - 1].IndexOf("/");
// if (len > 0)
// {
// port = str[str.Length - 1].Substring(0, len);
// }
// int curInt = System.Convert.ToInt32(port);
// string ip = str[str.Length - 2];
// if (str.Length > 2)
// {
// ip = str[str.Length - 1].Substring(2);
// }
// conn.ip = ip;
// conn.port = curInt;
// return 0;
// }
// return 1;
//}
#endif
}