public void ParseFromJson(string json) { try { JsonNode root = JsonNode.FromJson(json); JsonNode urlNode = root["url"]; if (urlNode != null) { Url = urlNode; } JsonNode statusCodeNode = root["statusCode"]; if (statusCodeNode != null) { StatusCode = statusCodeNode; } JsonNode contentNode = root["content"]; if (contentNode != null) { Content = contentNode; } JsonNode pathNode = root["path"]; if (pathNode != null) { Path = pathNode; } } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
/// <summary> /// /// </summary> /// <param name="url"></param> /// <returns>json:{"status"}</returns> private void EditorGetString(object obj) { DownloadResult result = obj as DownloadResult; try { string content = ""; HttpWebRequest request = WebRequest.Create(result.Url) as HttpWebRequest; request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; int statusCode = (int)response.StatusCode; if (response.StatusCode == HttpStatusCode.OK) { XLog.Log(TAG, "请求成功"); Stream stream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(stream, Encoding.GetEncoding("utf-8")); content = streamReader.ReadToEnd(); streamReader.Close(); response.Close(); } result.StatusCode = statusCode; result.Content = content; Results.Add(result); } catch (Exception exception) { XLog.LogError(TAG, exception.Message); result.StatusCode = -1; Results.Add(result); } }
public void OnFail(string message, AssertionHandlingMethod method) { switch (method) { case AssertionHandlingMethod.Console: { Console.WriteLine(message); return; } case AssertionHandlingMethod.Log: { XLog.LogError(new DebugLogMessage() { Message = new Message() { Value = message } }); return; } case AssertionHandlingMethod.Throw: { throw XExceptions.Exception(message); } default: { Console.WriteLine(method); return; } } }
public void AlipayPayFailed(string json) { XLog.Log(TAG, "alipay failed:" + json); Trade trade = new Trade(); try { trade.FromJson(json); foreach (AlipayListener listener in Listeners) { listener.PayFailed(trade); } } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
public void WxShareResult(string json) { XLog.Log(TAG, "share result : " + json + ",last share:" + (LastShareInfo == null?"":LastShareInfo.ToString())); try { JsonNode node = JsonNode.FromJson(json); JsonNode errorCodeNode = node["errorCode"]; int code = errorCodeNode; WxErrorCode errorCode = (WxErrorCode)code; foreach (ShareResultListener listener in Listeners) { listener.Result(errorCode, LastShareInfo); } } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
/// <summary> /// 额外奖励 /// </summary> /// <param name="item">奖励物品ID </param> /// <param name="number">奖励物品数量</param> /// <param name="price">物品的虚拟币单价 </param> /// <param name="trigger"> /// 触发奖励的事件, 取值在 1~99 之间, 1~20 已经被预先定义, 21~99 需要在网站设置含义。 /// 1: 玩家赠送 /// 2:开发商赠送 /// 3:游戏奖励 /// </param> public static void Bonus(string item, int number, double price, int trigger) { try { #if UNITY_ANDROID using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) { AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.umeng.UnityUmeng"); cls.CallStatic("bonus", item, number, price, trigger); } } #elif UNITY_IPHONE _umengBonus(item, number, price, trigger); #endif } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
public static void FinishLevel(string level) { try { #if UNITY_ANDROID using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) { AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.umeng.UnityUmeng"); cls.CallStatic("finishLevel", level); } } #elif UNITY_IPHONE _umengFinishLevel(level); #endif } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
/// <summary> /// 支付,可以使安卓支付,也可以是iOS支付宝支付 /// </summary> /// <param name="trade"></param> public static void Pay(string subject, string body, string totalFee, string outTradeNo, string notifyUrl) { XLog.Log(TAG, "alipay pay"); try { #if UNITY_IPHONE _alipayPay(subject, body, totalFee, outTradeNo, notifyUrl); #elif UNITY_ANDROID using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) { AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.alipay.UnityMorlnAlipay"); cls.CallStatic("pay", subject, body, totalFee, outTradeNo, notifyUrl); } } #endif } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
/// <summary> /// 初始化 /// </summary> public static void Init(string partnerId, string sellerId, string rsaPrivateKey) { XLog.Log(TAG, "alipay init"); try { #if UNITY_IPHONE _alipayInit(partnerId, sellerId, rsaPrivateKey); #elif UNITY_ANDROID using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) { AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.alipay.UnityMorlnAlipay"); cls.CallStatic("init", activity, partnerId, sellerId, rsaPrivateKey); } } #endif } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
public void DownloadFile(string url, string path, OnResult callback) { try { lock (locker) { DownloadResult result = new DownloadResult(); result.Url = url; result.Path = path; result.Callback = callback; if (Application.platform == RuntimePlatform.Android) { #if UNITY_ANDROID CacheList.Add(result); AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.http.HttpUtils"); cls.CallStatic("httpGetFile", url, path); #endif } else if (Application.platform == RuntimePlatform.IPhonePlayer) { CacheList.Add(result); Thread thread = new Thread(IosGetFile); thread.Start(result); } else { Thread thread = new Thread(EditorGetFile); thread.Start(result); } } } catch (Exception exception) { XLog.LogError(TAG, exception.Message); } }
private void EditorGetFile(object obj) { DownloadResult result = obj as DownloadResult; try { HttpWebRequest request = WebRequest.Create(result.Url) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; int statusCode = (int)response.StatusCode; if (response.StatusCode == HttpStatusCode.OK) { XLog.Log(TAG, "请求成功"); Stream stream = response.GetResponseStream(); FileStream fs = File.Create(result.Path); byte[] tmp = new byte[1024]; int size = 0; while ((size = stream.Read(tmp, 0, 1024)) > 0) { fs.Write(tmp, 0, size); } stream.Close(); fs.Close(); XLog.Log(TAG, "写文件成功"); } result.StatusCode = statusCode; Results.Add(result); } catch (Exception exception) { XLog.LogError(TAG, exception.Message); result.StatusCode = -1; Results.Add(result); } }
void OnEnable() { XLog.logMask = mMask; XLog.LogError("bla", 2); }