Exemple #1
0
    /// <summary>
    /// 断线重连
    /// </summary>
    IEnumerator Reconnect()
    {
        lastHeartTime = Time.realtimeSinceStartup;
        LoadingNode.OpenLoadingNode(LoadingType.Common);
        Close();
        reconnectTime++;
        bool isSuccess = false;

        isSuccess = Init();
        if (!isSuccess)
        {
            if (reconnectTime < 3)
            {
                yield return(new WaitForSecondsRealtime(5));

                StartCoroutine(Reconnect());
            }
            else
            {
                OpenTipNetError();
            }
        }
        else
        {
            reconnectTime = 0;
            LoadingNode.instance.Close();
            //重新登录
        }
    }
    public IEnumerator DownApk(string url)
    {
        WWW www = new WWW(url);

        do
        {
            yield return(null);

            LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在下载最新资源包...", www.progress);
        } while (!www.isDone);

        if (www.size > 0)
        {
            string filePath = Application.persistentDataPath + "/APK";
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            File.WriteAllBytes(filePath + "/version.apk", www.bytes);
            SDKManager.Instance.Install(filePath + "/version.apk");
        }
        else
        {
            SetTimeout.add(2f, () =>
            {
                LoadingNode.CloseLoadingNode();
            });
        }
    }
    /// <summary>
    /// 添加数据到发送队列
    /// </summary>
    /// <param name="c2g">消息主体</param>
    /// <param name="isPrevent">是否显示loading</param>
    public void AddSendMessageQueue(C2GMessage c2g, bool isPrevent = false)
    {
        if (!PageManager.Instance.isCanSend)
        {
            return;
        }

        if (isPrevent && mSocket.Connected)
        {
            LoadingNode.OpenLoadingNode(LoadingType.Common);
        }
        c2g.testLogicId = testLogicId;
        byte[] bytes = BuildPackage(c2g);
        if (sendList.Count > 0)
        {
            if (!sendList.Contains(bytes))
            {
                sendList.Add(bytes);
            }
            else
            {
                UIUtils.Log("消息重复");
            }
        }
        else
        {
            sendList.Add(bytes);
        }
        if (c2g.msgid != MessageId.C2G_HeartBeat)
        {
            UIUtils.Log("发送消息:" + c2g.msgid.ToString());
        }
    }
Exemple #4
0
    public void InstallAPK(string file)
    {
        LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在安装新版本中...");
        AndroidJavaObject jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");

        jo.Call("installApk", file);
    }
Exemple #5
0
 public override void Init()
 {
     base.Init();
     logo.GetComponent <CommonAnimation>().alphaEndAction = () =>
     {
         LoadingNode.OpenLoadingNode(LoadingType.Progress);
         StartCoroutine(VersionUpdate());
     };
 }
Exemple #6
0
    /// <summary>
    /// 版本/文件更新
    /// </summary>
    /// <returns></returns>
    IEnumerator VersionUpdate()
    {
        WWW www = new WWW(ConstantUtils.bundleTipsUrl);

        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            List <BundleManager.BundleInfo> bmbis = new List <BundleManager.BundleInfo>();
            JsonData jds = JsonMapper.ToObject(www.text);
            string   md5, file, path;
            for (int i = 0; i < jds.Count; i++)
            {
                JsonData jd = jds[i];
                file = jd.TryGetString("file");
                path = ConstantUtils.AssetBundleFolderPath + file;
                md5  = MiscUtils.GetMD5HashFromFile(path);
                if (string.IsNullOrEmpty(md5) || md5 != jd.TryGetString("md5"))
                {
                    bmbis.Add(new BundleManager.BundleInfo()
                    {
                        _url  = ConstantUtils.bundleDownLoadUrl + file,
                        _path = path
                    });
                }
            }
            if (bmbis.Count > 0)
            {
                StartCoroutine(BundleManager.Instance.DownloadBundleFiles(bmbis,
                                                                          (progress) =>
                {
                    LoadingNode.OpenLoadingNode(LoadingType.Progress, "自动更新中...", progress);
                },
                                                                          (isFinish) =>
                {
                    if (isFinish)
                    {
                        OnUpdateFileComplete();
                    }
                    else
                    {
                        TipManager.Instance.OpenTip(TipType.SimpleTip, "部分文件更新失败,正在重试...");
                        StartCoroutine(VersionUpdate());
                    }
                }));
            }
            else
            {
                OnUpdateFileComplete();
            }
        }
        else
        {
            UIUtils.Log(www.error);
            VersionManager.Instance.CheckVersion(OnUpdateBigFileComplete);
        }
    }
Exemple #7
0
    IEnumerator ScanQRcode()
    {
        string result = QRCode.DecodeColData(webCameraTexture.GetPixels32(),
                                             webCameraTexture.width,
                                             webCameraTexture.height);

        scaning += ".";
        if (scaning == "扫描中....")
        {
            scaning = "扫描中";
        }
        txt.text = scaning;
        if (result != "")
        {
            webCameraTexture.Stop();
            isScanner = false;
            txt.text  = "扫描成功";
            LoadingNode.OpenLoadingNode(LoadingType.Common);
            try
            {
                JsonData jd = JsonMapper.ToObject(result);
                switch (jd.TryGetString("id"))
                {
                case "1":
                    SocialModel.Instance.AddFriend(int.Parse(jd.TryGetString("content")));
                    TipManager.Instance.OpenTip(TipType.SimpleTip, "发送成功,等待通过", 1f);
                    break;

                case "2":
                    SocketClient.Instance.AddSendMessageQueue(new C2GMessage {
                        msgid          = MessageId.C2G_QueryTableInfo,
                        queryTableInfo = new QueryTableInfo()
                        {
                            tableId = jd.TryGetString("content")
                        }
                    });
                    break;

                case "3":
                    Application.OpenURL(jd.TryGetString("content"));
                    break;

                default:
                    break;
                }
            }
            catch (System.Exception)
            {
                TipManager.Instance.OpenTip(TipType.SimpleTip, "未识别的二维码");
            }
            PageManager.Instance.OpenLastPage();
        }
        yield return(new WaitForEndOfFrame());
    }
Exemple #8
0
    /// <summary>
    /// 更新结束后执行的函数
    /// </summary>
    IEnumerator VersionUpdateFinish()
    {
#if !UNITY_EDITOR
        string luaScript = BundleManager.Instance.GetLuaScript();
        if (!string.IsNullOrEmpty(luaScript))
        {
            luaenv.DoString(luaScript);
        }
#endif
        LoadingNode.OpenLoadingNode(LoadingType.Progress, null, 1);
        yield return(ConstantUtils.frameWait);

        LoadNecessaryBundle();
        MiscUtils.StartGPS();
        PageManager.Instance.OpenPage <TestPage>();
    }
    /// <summary>
    /// 断线重连
    /// </summary>
    IEnumerator Reconnect(bool isReLogin = true)
    {
        lastHeartTime = Time.realtimeSinceStartup;
        //TODO 显示重连状态
        LoadingNode.OpenLoadingNode(LoadingType.Common);
        Close();
        reconnectTime++;
        bool isSuccess = false;

        isSuccess = Init();
        if (!isSuccess)
        {
            if (reconnectTime < 3)
            {
                yield return(new WaitForSecondsRealtime(5));

                StartCoroutine(Reconnect());
            }
            else
            {
                OpenTipNetError();
            }
        }
        else
        {
            reconnectTime = 0;
            //重新登录
            if (isReLogin)
            {
                AddSendMessageQueue(new C2GMessage()
                {
                    msgid = MessageId.C2G_Login,
                    login = new Login()
                    {
                        token = LoginPage.token
                    }
                }, true);
                sendList.Add(sendList[0]);
                if (sendList.Count > 1)
                {
                    sendList.RemoveAt(0);
                }
            }
            LoadingNode.instance.Close();
        }
    }
    public void CheckVersion(CallBack onVersionUpdateFinish)
    {
        _onVersionUpdateFinish = onVersionUpdateFinish;
        LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在检测是否有新版本...", 0);
#if UNITY_EDITOR
        LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在检测是否有新版本...", 1);
        SetTimeout.add(1, () =>
        {
            LoadingNode.CloseLoadingNode();
            if (_onVersionUpdateFinish != null)
            {
                _onVersionUpdateFinish();
                _onVersionUpdateFinish = null;
            }
        });
        //StartCoroutine(BigVersionUpdate(true));
#elif UNITY_ANDROID
        StartCoroutine(BigVersionUpdate(true));
#elif UNITY_IPHONE
        onVersionUpdateFinish();
        //StartCoroutine(BigVersionUpdate());
#endif
    }
Exemple #11
0
    /// <summary>
    /// 添加数据到发送队列
    /// </summary>
    /// <param name="c2s">消息主体</param>
    /// <param name="isPrevent">是否显示loading</param>
    public void AddSendMessageQueue(Message c2s, bool isPrevent = false)
    {
        if (isPrevent && mSocket.Connected)
        {
            LoadingNode.OpenLoadingNode(LoadingType.Common);
        }
        byte[] bytes = BuildPackage(c2s);

        if (!tempSendList.Contains(bytes))
        {
            lock (tempSendList)
                tempSendList.Add(bytes);
        }
        else
        {
            UIUtils.Log("消息重复");
        }

        if (c2s.messageId != MessageId.Heart)
        {
            UIUtils.Log("发送消息:" + c2s.messageId.ToString());
        }
    }