using System; using UnityEngine; using GameCore; using System.Net; using GameLogic; using System.Collections; using System.Text.RegularExpressions; using System.Collections.Generic; using System.IO; using LuaInterface; using System.Runtime.InteropServices; using System.Text; using Umeng; namespace GameLogic { public class SDKManager : UnitySingleton { //#if UNITY_IPHONE || UNITY_IOS // [DllImport("__Internal")] // private static extern void InitSDK(string gameObjectNameP); // [DllImport("__Internal")] // private static extern void WXLogin(string successCallBack, string cancleCallBack); // [DllImport("__Internal")] // private static extern void ShareWebUrlToWX(string title, string desc, string url, string imagePath, int type, string successP, string cancleP); // [DllImport("__Internal")] // private static extern void ShareLocalImageToWX(string imagePath, int type, string successP, string cancleP); // [DllImport("__Internal")] // private static extern void ShareTextToWX(string text, int type, string successP, string cancleP); // [DllImport("__Internal")] // private static extern void _CopyText2Clipboard(string text); // [DllImport("__Internal")] // private static extern string Unity3dGetClipBoard(); //#endif // private LuaFunction wechatAuthCallback; // private LuaFunction wechatShareSuccess; // private LuaFunction wechatShareCancle; //#if UNITY_ANDROID // private static AndroidJavaObject mainActivity; // public static AndroidJavaObject GameActivity // { // get // { // if (mainActivity == null) // { // using (var jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) // { // mainActivity = jc.GetStatic("currentActivity"); // } // } // return mainActivity; // } // } //#endif //void Awake() //{ // // 开启SDK的日志打印,发布版本请务必关闭 // BuglyAgent.ConfigDebugMode(AppConst.ShowDebug); // BuglyAgent.ConfigAutoQuitApplication(false); // // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式 //#if UNITY_IPHONE || UNITY_IOS // BuglyAgent.InitWithAppId ("c07e578650"); //#elif UNITY_ANDROID // BuglyAgent.InitWithAppId("9b909facba"); //#endif // // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可 // BuglyAgent.EnableExceptionHandler(); // BuglyAgent.ConfigAutoReportLogLevel(LogSeverity.LogError); // Init(gameObject.name); // // UMStart(); //} void Awake() { if (AppConst.isSDK) { //BuglyAgent.InitWithAppId("b67b061643"); BuglyAgent.InitWithAppId(VersionManager.Instance.GetVersionInfo("buglyId")); BuglyAgent.EnableExceptionHandler(); } } public bool IsInit { get; private set; } public void Initialize() { KTSDK.Helper.Instance.onInitLaunchCallback = InitCallBack; //KTSDKInit(); IsInit = true; } public void SetInitCallBack(KTSDK.Helper.InitLaunchAction action) { KTSDK.Helper.Instance.onInitLaunchCallback += action; } //void KTSDKInit() //{ // var initArgs = new KTSDK.KTSDKInitArgs(); // initArgs.appid = AppConst.AppID; // initArgs.appkey = AppConst.AppKey; // initArgs.privateKey = AppConst.PrivateKey; // KTSDK.Helper.Instance.InitLaunch(initArgs); //} private void InitCallBack(string data) { string[] strArray = data.Split('#'); string code = strArray[0]; string result = strArray[1]; Debug.LogFormat("InitResult>>code:{0},result:{1}", code, result); } //public void SaveSession(int curPlatform) //{ // StartCoroutine(SaveSession_Co(curPlatform)); //} //IEnumerator SaveSession_Co(int curPlatform) //{ // yield return new WaitForEndOfFrame(); // AppConst.SessionPlatform = curPlatform; // PlayerPrefs.SetInt("SessionPlatform", AppConst.SessionPlatform); // PlayerPrefs.SetString("Session", AppConst.Session); // PlayerPrefs.SetString("Code", AppConst.Code); // PlayerPrefs.Save(); //} //public void ClearSession() //{ // AppConst.SessionPlatform = -1; // AppConst.Session = string.Empty; // AppConst.Code = string.Empty; // PlayerPrefs.DeleteKey("SessionPlatform"); // PlayerPrefs.DeleteKey("Session"); // PlayerPrefs.DeleteKey("Code"); //} // public void Init(string objName) // { // AppConst.SessionPlatform = PlayerPrefs.GetInt("SessionPlatform", -1); // AppConst.Session = PlayerPrefs.GetString("Session", string.Empty); // AppConst.Code = PlayerPrefs.GetString("Code", string.Empty); // //Debug.LogError("SDKManger...........HideSplash Init"); //#if !UNITY_EDITOR //#if UNITY_ANDROID // GameActivity.Call("initSDK", objName); // GameActivity.Call("HideSplash"); // Debug.LogError("HideSplash Init SDKManager::::"); //#elif UNITY_IPHONE || UNITY_IOS // InitSDK(objName); //#endif //#endif // } // /// // /// 登录成功后调用 // /// // /// // //public void SetUserId(string userId) // //{ // // BuglyAgent.SetUserId(userId); // //} // //public void BuglySetVersion(string channel, string version, string user, long delay) // //{ // // BuglyAgent.ConfigDefault(channel, version, user, delay); // //} // public static string GetPackageName() // { // return Application.identifier; // } // public static string GetAppVersion() // { // return Application.version; // } // public static string GetDeviceID() // { // return SystemInfo.deviceUniqueIdentifier; // } // public static string GetPlatform() // { // return Application.platform.ToString(); // } // //获取设备型号 // public static string GetDeviceSystemModel() // { // if (SystemInfo.deviceType == DeviceType.Handheld) // { //#if !UNITY_EDITOR //#if UNITY_ANDROID // if (GameActivity != null) // { // string info = GameActivity.Call("getPhoneInfo"); // var infos= info.Split(new string[] { "|" }, StringSplitOptions.None); // if(infos.Length>3) // return infos[3]; // else // return GetPlatform(); // } // else // { // return GetPlatform(); // } //#elif UNITY_IOS // return GetIosSystemName(); //#endif //#else // return GetPlatform(); //#endif // } // else // return SystemInfo.deviceType.ToString(); // } // public static String GetDeviceSystemVersion() // { //#if !UNITY_EDITOR //#if UNITY_ANDROID // if(GameActivity!=null) // { // string info = GameActivity.Call("getPhoneInfo"); // var infos= info.Split(new string[] { "|" }, StringSplitOptions.None); // if(infos.Length>2) // return infos[2]; // else // return "Unknown"; // } // else // { // return "Unknown"; // } //#elif UNITY_IOS // return GetIosSystemVersion(); //#endif //#else // return GetPlatform(); //#endif // } // public static string GetDeviceSystemInfo() // { // return SystemInfo.deviceUniqueIdentifier; // } // public static string GetLocalIP() // { // IPAddress ipAddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];//获得当前IP地址 // return ipAddr.ToString(); // } // //同步获取公共IP // public static string GetPublicIp() // { // string ip=""; // try // { // WebClient client = new WebClient(); // client.Encoding = System.Text.Encoding.Default; // string response = client.DownloadString("http://ip.chinaz.com/");//站长之家 // string myReg = @"
([\s\S]+?)<\/dd>"; // Match mc = Regex.Match(response, myReg, RegexOptions.Singleline); // if (mc.Success && mc.Groups.Count > 1) // { // ip = mc.Groups[1].Value; // } // return ip; // } // catch (Exception e) // { // return ""; // } // } // //获取公共IP // [LuaInterface.NoToLua] // public static IEnumerator GetPublicIpAsyn(GameEventHandler scuessEvent, GameEventHandler failEvent = null) // { // string tempInfo = ""; // GameEventHandler scuessEventHandle = (pars) => // { // if (pars.Length > 0) // { // var bytes = pars[0] as byte[]; // string textStr = System.Text.Encoding.UTF8.GetString(bytes); // Match m = Regex.Match(textStr, @"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}"); // if (m.Success) // { // tempInfo = m.Value; // } // } // }; // GameEventHandler failEventHandle = (pars) => // { // tempInfo = pars[0] as string; // }; // yield return WWWUtils.WWW("http://www.ip138.com/ips138.asp", null, null, scuessEventHandle, failEventHandle, 0); // if (scuessEvent != null) // { // scuessEvent(tempInfo); // } // if (failEvent != null) // { // failEvent(tempInfo); // } // } // public static void GetRegionName(string publicIp, GameEventHandler scuessEvent, GameEventHandler failEvent = null) // { // string tempInfo = ""; // GameEventHandler scuessEventHandle = (pars) => // { // var txtStr = pars[0] as string; // var ipInfo = (Hashtable)MiniJSON.jsonDecode(txtStr); // if (ipInfo.ContainsKey("code") && ipInfo["code"] != null && ipInfo["code"].ToString() == "0") // { // if (ipInfo.ContainsKey("data") && ipInfo["data"] != null) // { // var regionInfo = ipInfo["data"] as Hashtable; // if (regionInfo.ContainsKey("region") && regionInfo["region"] != null) // { // tempInfo = regionInfo["region"].ToString(); // if (scuessEvent != null) // { // scuessEvent(tempInfo); // return; // } // } // else // { // tempInfo = "Region Error"; // } // } // else // { // tempInfo = "Data Error"; // } // } // else // { // tempInfo = "Code Error"; // } // if (failEvent != null) // { // failEvent(tempInfo); // } // }; // GameEventHandler failEventHandle = (pars) => // { // tempInfo = pars[0] as string; // if (failEvent != null) // { // failEvent(tempInfo); // } // }; // WWWUtils.RequestText("http://ip.taobao.com/service/getIpInfo.php?ip=" + publicIp, scuessEventHandle, failEventHandle); // } // public static float GetDeviceBattary() // { //#if !UNITY_EDITOR //#if UNITY_ANDROID // if(GameActivity!=null) // { // string batt = GameActivity.Call("MonitorBatteryState"); // float battarry_value = 0; // if (float.TryParse(batt, out battarry_value)) // { // return battarry_value; // } // else // { // XDebug.Log.error("错误参数!"); // return 1; // } // } // else // { // return 1; // } //#elif UNITY_IOS // return GetiOSBatteryLevel(); //#endif //#else // return 1; //#endif // } // enum NetType // { // None = 0, // G,//4G // W,//wifi // D,//未连接 // } // public int GetNetType() // { // if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) // { // return (int)NetType.W; // } // else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork) // { // return (int)NetType.G; // } // else if (Application.internetReachability == NetworkReachability.NotReachable) // { // return (int)NetType.D; // } // return (int)NetType.None; // } // public int GetWifiInfo() // { //#if !UNITY_EDITOR //#if UNITY_ANDROID // if(GameActivity!=null) // { // var wifiData = GameActivity.Call("getWifiState"); // string[] args = wifiData.Split('|'); // int xinhao = 0; // if (int.TryParse(args[0], out xinhao)) // { // if (xinhao == 4) // { // print("信号很好"); // return 3; // } // else if (xinhao == 3) // { // print("信号一般"); // return 2; // } // else // { // print("信号很弱"); // return 1; // } // } // else // { // return 0; // } // } // else // { // return 0; // } //#elif UNITY_IOS // return GetSignalInfo(); //#endif //#else // return 4; //#endif // } // public void Wechat_Authorize(LuaFunction callback) // { //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("onClickWXLogin", "onAuthorize_Success", "onAuthorize_Cancle"); //#elif UNITY_IPHONE || UNITY_IOS // WXLogin("onAuthorize_Success","onAuthorize_Cancle"); //#endif // wechatAuthCallback = callback; // } // public void onAuthorize_Success(string data) // { // Debug.LogWarning("Authorize Callback Data: " + data); // if (data == null) // { // return; // } // Hashtable res = (Hashtable)MiniJSON.jsonDecode(data); // if (res == null || res.Count <= 0) // { // return; // } // AppConst.WeChat_AccessToken = (string)res["access_token"]; // AppConst.WeChat_OpenID = (string)res["openid"]; // if (wechatAuthCallback != null) // { // wechatAuthCallback.Call(Convert.ToInt32(res["status"])); // wechatAuthCallback.Dispose(); // wechatAuthCallback = null; // } // } // public void onAuthorize_Cancle(string data) // { // if (wechatAuthCallback != null) // { // wechatAuthCallback.Call(-1); // wechatAuthCallback.Dispose(); // wechatAuthCallback = null; // } // } // public Action downloadProcessUpdateCallBack; // public Action downloadErrorCallBack; // public void DownloadApk(string url, Action downMsgDelegate, Action downloadErrorDelegate) // { //#if UNITY_ANDROID // GameActivity.Call("downAndInstallApk", "onDownLoadUpdate", "onDownLoadError"); // downloadProcessUpdateCallBack = downMsgDelegate; // downloadErrorCallBack = downloadErrorDelegate; //#endif // } // /// // /// 50.0%|200 KB/s|64M // /// // /// // public void onDownLoadUpdate(string data) // { // //string[] msg = data.Split('|'); // if (downloadProcessUpdateCallBack != null) // { // downloadProcessUpdateCallBack(data); // } // } // public void onDownLoadError(string data) // { // if (downloadErrorCallBack != null) // { // downloadErrorCallBack(); // } // } // /// // /// 分享webUrl // /// // /// // /// // /// // /// 1:微信好友 2:微信朋友圈 // public void Wechat_ShareWebUrlToWX(string title, string description, string url, string imagePath, int type, LuaFunction wechatShareSuccessP, LuaFunction wechatShareCancleP) // { // if(string.IsNullOrEmpty(imagePath)) // { // imagePath = Util.DataPath + "Resources/share_img.png"; // } //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("ShareWebUrlToWX", title, description, url, imagePath, type, "Wechat_ShareWebUrlToWX_Success", "Wechat_ShareWebUrlToWX_Cancle"); //#elif UNITY_IPHONE || UNITY_IOS // ShareWebUrlToWX(title,description,url,imagePath,type,"Wechat_ShareWebUrlToWX_Success", "Wechat_ShareWebUrlToWX_Cancle"); //#endif // wechatShareSuccess = wechatShareSuccessP; // wechatShareCancle = wechatShareCancleP; // } // public void Wechat_ShareWebUrlToWX_Success(string msg) // { // if (wechatShareSuccess != null) // { // wechatShareSuccess.Call(); // } // } // public void Wechat_ShareWebUrlToWX_Cancle(string msg) // { // if (wechatShareCancle != null) // { // wechatShareCancle.Call(); // } // } // /// // /// 分享本地图片到wx // /// // /// // /// // /// // /// // public void Wechat_ShareLocalImageToWX(string imagePath, int type, LuaFunction wechatShareSuccessP, LuaFunction wechatShareCancleP) // { //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("ShareLocalImageToWX", imagePath, type, "Wechat_ShareLocalImgToWX_Success", "Wechat_ShareLocalImgToWX_Cancle"); //#elif UNITY_IPHONE || UNITY_IOS // ShareLocalImageToWX(imagePath,type,"Wechat_ShareLocalImgToWX_Success","Wechat_ShareLocalImgToWX_Cancle"); //#endif // wechatShareSuccess = wechatShareSuccessP; // wechatShareCancle = wechatShareCancleP; // } // public void Wechat_ShareLocalImgToWX_Success(string msg) // { // if (wechatShareSuccess != null) // { // wechatShareSuccess.Call(); // } // } // public void Wechat_ShareLocalImgToWX_Cancle(string msg) // { // if (wechatShareCancle != null) // { // wechatShareCancle.Call(); // } // } // private int screenShotIndex = 0; // private string picName = string.Empty; // private int ShareScreenType = 1; // public void ShareScreenShot(LuaFunction wechatShareSuccessP, LuaFunction wechatShareCancleP) // { // wechatShareSuccess = wechatShareSuccessP; // wechatShareCancle = wechatShareCancleP; // picName = "screen_" + screenShotIndex + ".png"; // ScreenCapture.CaptureScreenshot(picName); // StartCoroutine(CaptureScreeShotWait_Co()); // screenShotIndex = (screenShotIndex + 1) % 5; // } // IEnumerator CaptureScreeShotWait_Co() // { // yield return new WaitForSeconds(0.5f); // App.CompressMgr.CompressPicture(128, Application.persistentDataPath + "/" + picName, Application.persistentDataPath + "/" + picName, OnScreenShotCompress); // } // void OnScreenShotCompress(bool isSuccess) // { // if (!isSuccess) // return; // Wechat_ShareLocalImageToWX(Application.persistentDataPath + "/" + picName, ShareScreenType, wechatShareSuccess, wechatShareCancle); // } // /// // /// 分享文字到微信 // /// // /// // /// // public void Wechat_ShareTextToWX(string text, int type, LuaFunction wechatShareSuccessP, LuaFunction wechatShareCancleP) // { //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("ShareTextToWX", text, type, "Wechat_ShareLocalImgToWX_Success", "Wechat_ShareLocalImgToWX_Cancle"); //#elif UNITY_IPHONE || UNITY_IOS // ShareTextToWX(text,type,"Wechat_ShareLocalImgToWX_Success","Wechat_ShareLocalImgToWX_Cancle"); //#endif // wechatShareSuccess = wechatShareSuccessP; // wechatShareCancle = wechatShareCancleP; // } // /// // /// 分享musicUrl到微信 // /// // /// // /// // /// // /// // /// // /// // /// // public void Wechat_ShareMusicUrlToWX(string title, string description, string musicUrl, string imagePath, int type, LuaFunction wechatShareSuccessP, LuaFunction wechatShareCancleP) // { //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("ShareMusicUrl", title, description, musicUrl, imagePath, type, "Wechat_ShareLocalImgToWX_Success", "Wechat_ShareLocalImgToWX_Cancle"); //#endif // wechatShareSuccess = wechatShareSuccessP; // wechatShareCancle = wechatShareCancleP; // } // /// // /// 分享视频地址到微信 // /// // /// // /// // /// // /// // /// // /// // /// // public void Wechat_ShareVideoUrlToWX(string title, string description, string videoUrl, string imagePath, int type, LuaFunction wechatShareSuccessP, LuaFunction wechatShareCancleP) // { //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("ShareVideoUrl", title, description, videoUrl, imagePath, type, "Wechat_ShareLocalImgToWX_Success", "Wechat_ShareLocalImgToWX_Cancle"); //#endif // wechatShareSuccess = wechatShareSuccessP; // wechatShareCancle = wechatShareCancleP; // } // /// // /// 拷贝文本到剪切板 // /// // /// // public void CopText2Clipboard(string text) // { //#if UNITY_EDITOR //#elif UNITY_ANDROID // GameActivity.Call("CopyTextToClipboard", text); //#elif UNITY_IPHONE || UNITY_IOS // _CopyText2Clipboard(text); //#endif // } // /// // /// 获取剪贴板内容 // /// // /// // public string GetTextFromClipboard() // { //#if UNITY_EDITOR // return ""; //#elif UNITY_ANDROID // return GameActivity.Call("GetTextFromClip"); //#elif UNITY_IPHONE || UNITY_IOS // Unity3dGetClipBoard(); //#endif // return ""; // } // //**************************************UmengSDK Start******************************** // void UMStart() // { // //请到 http://www.umeng.com/analytics 获取app key //#if UNITY_ANDROID // GA.StartWithAppKeyAndChannelId("595cabca677baa73be000abe", "App Store"); //#elif UNITY_IPHONE // GA.StartWithAppKeyAndChannelId("595cac0fa325110ac80018ca","App Store"); //#endif // //调试时开启日志 发布时设置为false // GA.SetLogEnabled(true); // } // int lv = 1; // /// // /// 登录成功后调用 // /// // /// 用户id // /// 渠道 微信 // public void InitLoginUmengSdk(string UserId, string qudao) // { // GA.ProfileSignIn(UserId, qudao); // } // /// // /// 玩家等级改变 // /// // /// 当前等级 // public void PlayLvUp(int lv) // { // GA.SetUserLevel(lv); // } // /// // /// 玩家支付统计 // /// // /// 付款人民币 // /// 购买道具数量 // public void Pay(string UserId, int Rmb, int daojuCount) // { // string Time = System.DateTime.Now.ToLocalTime().ToString(); // GA.Pay(Rmb, GA.PaySource.AppStore, daojuCount); // // GA.Event("Recharge", "UserId:" + UserId + ";PayMoney:" + Rmb + "(" + Time + ")"); // } // /// // /// 退出统计 // /// // public void Exit() // { // GA.ProfileSignOff(); // } // /// // /// 玩家注册时间统计 // /// // public void RegisterTimeClec(string UserId) // { // string Time = System.DateTime.Now.ToLocalTime().ToString(); // print("注册时间事件统计" + Time); // GA.Event("RegisterTime", Time + "(UserId:" + UserId + ")"); // } // /// // /// 登录时间统计 // /// // /// // public void LoginTime(string UserId) // { // string Time = System.DateTime.Now.ToLocalTime().ToString(); // print("登录时间" + Time); // GA.Event("LoginEvent", Time + "(UserId:" + UserId + ")"); // } // /// // /// 登出时间 // /// // /// // public void LogOutTime(string UserId) // { // string Time = System.DateTime.Now.ToLocalTime().ToString(); // print("登出时间" + Time); // GA.Event("LogoutEvent", Time + "(UserId:" + UserId + ")"); // } // /// // /// 用户信息统计 // /// // /// // /// // /// // /// // /// // public void UserInfoClec(string UserId, string UName, string Gold, string Diamond, string HeadPic) // { // string Time = System.DateTime.Now.ToLocalTime().ToString(); // var dict = new Dictionary(); // dict["ID"] = UserId + ";Name:" + UName + "G:" + Gold + ";D:" + Diamond + ";Headpic:" + HeadPic + ";Time:" + Time;//钻石 // GA.Event("UserInfo", dict); // } // /// // /// 游戏结束时统计调用 // /// // /// // /// // /// // /// // /// // /// // public void JoinGameInfoClec(string UserId, string gametype, string roomId, string cardInfo, string GameResult, string systemGetMoney) // { // string Time = System.DateTime.Now.ToLocalTime().ToString(); // print("游戏信息" + Time); // GA.Event("JoinGameInfo", UserId + ";GameType:" + gametype + "RoomId:" + roomId + ";CardInfo:" + cardInfo + ";Result:" + GameResult + ";SystemGetMoney:" + systemGetMoney + ";Time:" + Time); // } // /// // /// 系统抽水 // /// // public void SystemGetMoneyClec(string money, string type) // { // GA.Event("SystemGetMoney", money + "(" + type + ")");//5 进入房间抽水的钱数 // } // /// // /// 系统总输赢统计 // /// // /// // public void SystemWinLoseClec(string winLoseType) // { // GA.Event("systemWinLose", winLoseType);//参数 win lose进入房间抽水的钱数 // } // /// // /// 开局人数统计(游戏开局时调用) // /// // public void PeopleAndGameClec(string startGamePeopleCount) // { // GA.Event("GameAndPeople", startGamePeopleCount);//参数5开局的个数 // } // //**************************************UmengSDK End******************************** } }