public static string Serializer <T>(T jsonData, bool needEncrypt = false) { if (jsonData == null) { return(default(string)); } string jsonString = ""; try { jsonString = JsonConvert.SerializeObject(jsonData); if (isShowLog) { //SQDebug.LogWarning("Json: " + jsonString); } } catch (Exception e) { SQDebug.Log(e.Message); return(default(string)); } if (needEncrypt) { jsonString = ResourcesEncryption.AES_Encrypt(jsonString); } return(jsonString); }
public static object DeserializByte(Type t, byte[] data, int index, int readCount, bool needShowLog = false) { bool needDecrypt = false; string jsonString = Encoding.UTF8.GetString(data, index, readCount); if (jsonString == default(string) || jsonString == "") { return(null); } if (isShowLog || needShowLog) { SQDebug.LogWarning("Json: " + jsonString); int i = 0; } if (needDecrypt) { jsonString = ResourcesEncryption.AES_Decrypt(jsonString); } try { return(JsonConvert.DeserializeObject(jsonString, t)); } catch (Exception e) { SQDebug.Log(e.Message); return(null); } }
private bool mIsLoadOver = false; //是否加载完成 void Awake() { mTran = transform; mPanel = GetComponent <UIPanel>(); if (mPanel == null) { SQDebug.Log("panel is null"); return; } mScrollView = GetComponent <UIScrollView>(); if (mScrollView == null) { SQDebug.Log("scrollview is null"); return; } //创建显示个数的item for (int i = 0; i < ShowCount; i++) { GameObject obj = new GameObject((i + 1).ToString()); obj.transform.parent = mTran; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; obj.transform.localRotation = Quaternion.Euler(Vector3.zero); ChatScrollItem item = obj.AddComponent <ChatScrollItem>(); item.indexInScroll = i; mItemList.Add(item); } mIsHorizontal = mScrollView.movement == UIScrollView.Movement.Horizontal ? true : false; mPanel.onClipMove = OnClipMove; mInitPanelPos = mTran.localPosition; mInitPanelClip = mPanel.clipOffset; mPanelHeight = mPanel.height; }
/// <summary> /// 获取回放信息 /// </summary> /// <param name="index"></param> /// <param name="call"></param> public void GetRecord(string path, CallBack <MJRecordData> call) { if (mModel.RecordDetailsDic.ContainsKey(path)) { if (call != null) { mModel.CurRecordDetailData = DeserializeData <MJRecordData>(mModel.RecordDetailsDic[path]); call(mModel.CurRecordDetailData); } } else { //path = "file://E:/Project/ZhenzhuMJ/record.txt"; Assets.LoadTxtFileCallBytes(path, (str) => { if (str == null) { Global.Inst.GetController <CommonTipsController>().ShowTips("获取回放信息失败"); } else { MJRecordData data = DeserializeData <MJRecordData>(str); string s = Json.Serializer <MJRecordData>(data); SQDebug.Log("回放数据:" + s); mModel.RecordDetailsDic[path] = str; mModel.CurRecordDetailData = data; if (call != null) { call(data); } } }); } }
/// <summary> /// 邀请微信好友 /// </summary> /// <param name="str"></param> public void InviteFriends(string nameId, string str = "") { if (!File.Exists(Application.persistentDataPath + iconPath)) { SQDebug.PrintToScreen("VistiteFriend222=" + Application.persistentDataPath + iconPath); byte[] b = icon.EncodeToPNG(); SQDebug.PrintToScreen("VistiteFriend2221=" + b.Length); try { File.WriteAllBytes(Application.persistentDataPath + iconPath, b); } catch (Exception ex) { SQDebug.PrintToScreen(ex); } SQDebug.PrintToScreen("VistiteFriend2223=" + Application.persistentDataPath + iconPath); } SQDebug.LogError(Application.persistentDataPath + iconPath); // ShareContent content = new ShareContent(); content.SetTitle("58麻将0429"); content.SetUrl("http://139.224.57.97/down/index.html"); content.SetText("房间号:" + nameId + "\n" + str); content.SetImagePath(Application.persistentDataPath + iconPath); content.SetShareType(ContentType.Webpage); SQDebug.PrintToScreen("VistiteFriend2224="); ssdk.ShareContent(PlatformType.WeChat, content); }
private void MoveTex(float distance) { if (distance < 0.20) { mTran.transform.localPosition = pressVec; } else { curIndex = curIndex + indexdirection; if (curIndex < 0) { indexdirection = 1; curIndex = 0; } else if (curIndex >= childCount) { indexdirection = -1; curIndex = childCount - 1; } SQDebug.Log(curIndex); Vector3 ve = objs[curIndex].transform.localPosition; SQDebug.Log(ve); mTran.transform.localPosition = new Vector3(ve.x * -1, ve.y * -1); } }
/// <summary> /// 协议加载txt文件 /// </summary> /// <param name="url"></param> /// <returns></returns> IEnumerator IELoadTxtFile(string url, CallBack <byte[]> call, bool isshowLoading = true) { Global.Inst.GetController <NetLoadingController>().ShowLoading(isshowLoading); yield return(null); WWW www = new WWW(url); yield return(www); if (www.isDone && www.error == null) { if (call != null) { SQDebug.Print("从连接地址:--->" + url + " 加载的txt文件内容为:--->" + www.text); call(www.bytes); } www.Dispose(); } else { if (call != null) { SQDebug.Print("从连接地址:--->" + url + " 加载txt数据失败"); call(null); } } www = null; Global.Inst.GetController <NetLoadingController>().ShowLoading(false); }
/// <summary> /// 上传图片 /// </summary> /// <param name="img"></param> /// <param name="call"></param> /// <returns></returns> IEnumerator SendPngToServer(string[] img, CallBack <List <string> > call) { List <string> imgurl = new List <string>(); if (img != null && img.Length > 0) { Global.Inst.GetController <NetLoadingController>().ShowLoading(true, true); for (int i = 0; i < img.Length; i++) { WWWForm f = new WWWForm(); f.AddField("act", "upPic"); f.AddField("picBin", img[i]); WWW www = new WWW(mSendUrl, f); yield return(www); if (www.isDone && string.IsNullOrEmpty(www.error)) { imgurl.Add(www.text); SQDebug.Log("上传图片:" + www.text); } if (!string.IsNullOrEmpty(www.error)) { SQDebug.Log("加载错误:第" + (i + 1) + "张 " + www.error); } www = null; } } Global.Inst.GetController <NetLoadingController>().ShowLoading(false); if (call != null) { call(imgurl); } yield return(0); }
IEnumerator LoadConfigIE(string url, CallBack <AssetBundle> call, int cachid) { WWW www = null; if (Application.platform == RuntimePlatform.WindowsEditor) { www = new WWW(url); } else { www = WWW.LoadFromCacheOrDownload(url, cachid); } yield return(www); if (www.isDone && string.IsNullOrEmpty(www.error)) { if (null != call) { call(www.assetBundle); } } if (!string.IsNullOrEmpty(www.error)) { SQDebug.LogError("加载错误:" + url + " " + www.error); if (null != call) { call(null); } } }
/// <summary> /// 邀请按钮点击 /// </summary> public void OnInvitateBtnClick() { string rule = GamePatternModel.Inst.DeserializeRuleJosn(NiuniuModel.Inst.mRoomRules, false); SQDebug.Log(rule); SixqinSDKManager.Inst.InviteFriends(NiuniuModel.Inst.mRoomId, rule, cn.sharesdk.unity3d.PlatformType.WeChat); }
public void OnStartClick() { // SQDebug.Log("获取当前转盘奖励"); if (prizeData.drawNum - prizeData.drawTotal <= 0) { Global.Inst.GetController <CommonTipsController>().ShowTips("您没有抽奖次数"); return; } Global.Inst.GetController <MainController>().SendPrizeBack((data) => { prizeData.drawTotal++; mCount.text = string.Format("{0}次", prizeData.drawNum - prizeData.drawTotal); mPlayCount.text = string.Format("[7F6E36]游戏局数:[-][FFA70B]{0}[-] [7F6E36]已抽奖次数:[-][FFA70B]{1}[-]", prizeData.games, prizeData.drawTotal); int index = prizeData.info.FindIndex((p) => p.prizeId == data.prizeInfo.prizeId); reward = data.prizeInfo; float angle = 18 + index * mItemAgle + UnityEngine.Random.Range(-mItemAgle * 0.35f, mItemAgle * 0.35f); angle += 360 * UnityEngine.Random.Range(6, 10); StartCoroutine(StartRun(Vector3.forward * angle)); }); }
/// <summary> /// 获取房间信息 /// </summary> public void SendJoinRoom(string roomId) { MJJoinRoomRequest req = new MJJoinRoomRequest(); req.roomId = roomId; NetProcess.SendRequest <MJJoinRoomRequest>(req, MJProtoMap.CMD_GoIntoRoom, (msg) => { StartGameBackData data = msg.Read <StartGameBackData>(); if (data.code == 1) { //发送位置信息给服务器 if (PlayerModel.Inst.address != null) { NetProcess.SendRequest <SendAddrReq>(PlayerModel.Inst.address, MJProtoMap.CMD_SendAddress, (msgData) => { SQDebug.Log("gps 返回"); }, false); } if (mGameUI != null) { mGameUI.ReSetUI(true); MJGameModel.Inst.ResetData(); } HandleStartGameData(data.data); } else { GameUtils.ShowErrorTips(data.code); } }); }
//联系客服 public void OnServiceClick() { string str = string.Format(mData.url, PlayerModel.Inst.UserInfo.userId, PlayerModel.Inst.UserInfo.userId); SQDebug.Log("客服:" + str); Application.OpenURL(str); }
public static void PlaySound(string szSoundName, float rate = 1.0f) { if (szSoundName == "") { return; } SQDebug.Log(szSoundName); AudioClip ClipData = GetSoundClip(m_sSoundPath, szSoundName); if (ClipData == null) { return; } for (int i = 0; i < m_aAudioPlayList.Count; i++) { AudioSource AudioObj = m_aAudioPlayList[i]; if (AudioObj.enabled == false) { AudioObj.enabled = true; AudioObj.clip = ClipData; AudioObj.volume = m_fSoundVolume * rate; AudioObj.Play(); return; } } }
/// <summary> /// 下载进度 /// </summary> /// <param name="progress"></param> private void OnDownLoadProgress(string progress) { SQDebug.Log("下载进度:" + progress + "%"); //if (mDownLoadAPkUI == null) //mDownLoadAPkUI = DownLoadAPkUI.OpenWindow(); //mDownLoadAPkUI.SetDownloadProgress(int.Parse(progress)); }
/// <summary> /// 授权回调 /// </summary> /// <param name="reqID"></param> /// <param name="state"></param> /// <param name="type"></param> /// <param name="result"></param> void OnAuthResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { SQDebug.Log("caonima===" + reqID + " state=" + state + " type=" + type); if (state == ResponseState.Success) { SQDebug.Log("微信授权成功正在获取微信信息"); print("authorize success !" + "Platform :" + type); ssdk.GetUserInfo(type); } else if (state == ResponseState.Fail) { Global.Inst.GetController <NetLoadingController>().ShowLoading(false); Global.Inst.GetController <CommonTipsController>().CloseWindow(); SQDebug.Log("授权失败"); #if UNITY_ANDROID print("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]); #elif UNITY_IPHONE print("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); #endif } else if (state == ResponseState.Cancel) { Global.Inst.GetController <NetLoadingController>().ShowLoading(false); Global.Inst.GetController <CommonTipsController>().CloseWindow(); SQDebug.Log("微信授权失败"); print("cancel !"); } }
public static void getIPType(String serverIp, String serverPorts, out String newServerIp, out AddressFamily mIPType) { mIPType = AddressFamily.InterNetwork; newServerIp = serverIp; try { string mIPv6 = GetIPv6(serverIp, serverPorts); if (!string.IsNullOrEmpty(mIPv6)) { string[] m_StrTemp = System.Text.RegularExpressions.Regex.Split(mIPv6, "&&"); if (m_StrTemp != null && m_StrTemp.Length >= 2) { string IPType = m_StrTemp[1]; if (IPType == "ipv6") { newServerIp = m_StrTemp[0]; mIPType = AddressFamily.InterNetworkV6; } } } } catch (Exception e) { SQDebug.Log("GetIPv6 error:" + e); } }
/// <summary> /// 语音聊天抬起 /// </summary> public void OnVoiceRelase() { mVoceRecordShow.gameObject.SetActive(false); #if YYVOICE uint mCurRecordTime = 0; YunVaImSDK.instance.RecordStopRequest((data1) => { mCurRecordTime = data1.time; SQDebug.Log("停止录音返回:" + data1.strfilepath); }, (data2) => { SQDebug.Log("上传返回:" + data2.fileurl); XXGoldFlowerGameController mCtr = Global.Inst.GetController <XXGoldFlowerGameController>(); SendReceiveGameChat req = new SendReceiveGameChat(); req.fromSeatId = XXGoldFlowerGameModel.Inst.mMySeatId; req.chatType = (int)eGameChatContentType.Voice; req.content = data2.fileurl; req.voiceChatTime = (int)mCurRecordTime; mCtr.SendGameChat(req); }, (data3) => { SQDebug.Log("识别返回:" + data3.text); }); #endif }
/// <summary> /// 重连 /// </summary> public void ReConnet() { mLastReconnetTime = Time.realtimeSinceStartup;//重连时间 LoginModel.Inst.mSessionId = -1; Global.Inst.GetController <NetLoadingController>().ShowLoading(false); GameManager.Instance.CancelHeartBreath(); NetProcess.ReleaseAllConnect(); CallBack call = () => { SQDebug.Log("重连次数" + mAutoReConnectNum); if (mBreathCallBack == null) { Global.Inst.GetController <MainController>().BackToMain(Ip, port); } else { mBreathCallBack(MainViewModel.Inst.mNowIp, MainViewModel.Inst.mNowPort); } }; if (mAutoReConnectNum < 3)//如果自动重连次数少于两次就弹出提示 { mAutoReConnectNum++; call(); } else { Global.Inst.GetController <CommonTipsController>().ShowTips("网络连接失败", "尝试连接|退出游戏", true, call, () => { Application.Quit(); }, null, "网络异常"); } }
IEnumerator PostData(string url, WWWForm form, Dictionary <string, string> header, HttpCallBack callBack = null) { if (isShowLog) { SQDebug.LogWarning(url); } WWW w = new WWW(url, form.data, header); yield return(w); if (!string.IsNullOrEmpty(w.error)) { if (callBack == null) { SQDebug.Log("WWW : " + " erro info " + w.error); yield break; } ResultCallBack(callBack, w.error); yield break; } if (callBack != null) { ResultCallBack(callBack, w.text); } }
public void ChoiseRoomState(MJInstructionsProto data) { switch (data.optList[0].ins) { case eMJInstructionsType.CHANGETHREE: //换3张 MJGameModel.Inst.mStartGameData.roomInfo.roomState = eRoomState.CHANGETHREE; SQDebug.Log("房间状态为:====>>>换3张"); mGameUI.DelayRun(1f, () => { mGameUI.ChangeThreeUI(data); }); mGameUI.SetLeftTime(MJGameModel.Inst.TurnFixedTime, true); break; case eMJInstructionsType.FIXEDCOLOR: //定缺 if (MJGameModel.Inst.mStartGameData.roomInfo.roomState == eRoomState.START) { break; } MJGameModel.Inst.mStartGameData.roomInfo.roomState = eRoomState.FIXEDCOLOR; SQDebug.Log("房间状态为:====>>>定缺"); mGameUI.DelayRun(0.1f, () => { mGameUI.ChangeFixeDcolorUI(data); }); mGameUI.SetLeftTime(MJGameModel.Inst.TurnFixedTime, true); break; default: // MJGameModel.Inst.mStartGameData.roomInfo.roomState = eRoomState.START; //改变房间状态 SQDebug.Log("房间状态为:====>>>游戏中"); bool isHasDataBefore = (MJGameModel.Inst.hasCanHuListCards != null && MJGameModel.Inst.hasCanHuListCards.Count != 0); //处理数据之前是否有数据 List <OptItemStruct> optList = MergeInsData(data.optList); bool isHasDataBehind = (MJGameModel.Inst.hasCanHuListCards != null && MJGameModel.Inst.hasCanHuListCards.Count != 0); //处理数据之后是否有数据 mGameUI.ServerShowInstructions(optList, isHasDataBefore != isHasDataBehind); break; } }
IEnumerator GetData(string url, HttpCallBack callBack = null) { if (isShowLog) { SQDebug.LogWarning(url); } WWW w = new WWW(url); // w.he.Add("cookies", "openid=736455D011F599A8177806850F1839F5&&appid=1106110196&&openkey=3F6E4816A09D42953A5FF399A9C0A577"); yield return(w); if (!string.IsNullOrEmpty(w.error)) { if (callBack == null) { SQDebug.Log("WWW error info " + w.error); yield break; } ResultCallBack(callBack, w.error); yield break; } if (callBack != null) { ResultCallBack(callBack, w.text); } }
/// <summary> /// 下载失败 /// </summary> /// <param name="progress"></param> private void OnDownLoadFail(string progress) { SQDebug.Log("下载失败"); Global.Inst.GetController <CommonTipsController>().ShowTips("下在失败,请检测网络设置后重新下载", "确定", () => { StartDownLoad(mDownloadUrl); }); }
/// <summary> /// 开始下载 /// </summary> /// <param name="downloadUrl">下载链接</param> public void StartDownLoad(string downloadUrl) { mDownloadUrl = downloadUrl; SQDebug.Log("开始下载"); //if (mDownLoadAPkUI == null) //mDownLoadAPkUI = DownLoadAPkUI.OpenWindow(); //mDownLoadAPkUI.SetDownloadProgress(0); //mAJ.Call("DownLoadAPK", downloadUrl, gameObject.name); }
void OnApplicationPause(bool b) { if (b)//最小化游戏 { SQDebug.Log("程序失去焦点"); NetProcess.ReleaseAllConnect(); GameManager.Instance.ResetConnetTime(); } }
public static void SendGet(string url, HttpCallBack callBack = null) { if (Instance == null || Instance.gameObject.activeSelf == false) { SQDebug.Log("Instance is null or active self == false,please send wait"); return; } Instance.StartCoroutine(Instance.GetData(url, callBack)); }
public void CheckGetRewardNote() { SQDebug.Log("打开中奖纪录面板"); Global.Inst.GetController <MainController>().SendGetPrizeRecord((data) => { ActivityRecordWidget wid = GetWidget <ActivityRecordWidget>("Windows/Mainview/ActivityRecordWidget", transform.parent); wid.ShowData(data); }); }
IEnumerator StartGPS() { // Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置 // LocationService.isEnabledByUser 用户设置里的定位服务是否启用 if (!Input.location.isEnabledByUser) { SQDebug.Log("isEnabledByUser value is:" + Input.location.isEnabledByUser.ToString() + " Please turn on the GPS"); if (OnGetGpsInfoCall != null) { OnGetGpsInfoCall(GPSType.Error, mGpsN, mGpsN, Input.location.lastData.timestamp); } yield return(false); } // LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用 Input.location.Start(10.0f, 10.0f); SQDebug.PrintToScreen("Input.location.status=" + Input.location.status); int maxWait = 20; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { SQDebug.PrintToScreen("status=" + Input.location.status); // 暂停协同程序的执行(1秒) yield return(new WaitForSeconds(1)); maxWait--; } if (maxWait < 1) { SQDebug.Log("Init GPS service time out"); yield return(false); } if (Input.location.status == LocationServiceStatus.Failed) { SQDebug.Log("Unable to determine device location"); yield return(false); } else { SQDebug.PrintToScreen("N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude); SQDebug.Log("N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude); mGpsN = Input.location.lastData.latitude; mGpnE = Input.location.lastData.longitude; if (OnGetGpsInfoCall != null) { OnGetGpsInfoCall(GPSType.Normal, mGpsN, mGpnE, Input.location.lastData.timestamp); } //this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp; yield return(new WaitForSeconds(100)); } }
/// <summary> /// 播放 换牌动画 /// </summary> public void PlayChangeThreeAnim(MJoptInfoData data) { UpdataHandCardsAfterGetMsg(); SQDebug.Log("换牌动画"); SetPlayAnim(data); DelayRun(2.1f, () => { Global.Inst.GetController <MJGameController>().ExcuteOptInChange(); }); }
/// <summary> /// 设置看牌状态 /// </summary> /// <param name="show"></param> public void SetLookCarsState(bool show) { SQDebug.Log("look:" + show); mBasePlayerInfo.SetLookCarsState(show); if (show) { mBasePlayerInfo.SetInsTips(eGFOptIns.LookCard); } }