Пример #1
0
    //从CDN上读取解析 IP port hotUpdateURL homeURL
    private IEnumerator DownloadConfigFromCDN()
    {
        Debug.Log("download config from cdn: " + cdnUrl + "Main" + AssetPathUtil.XML_SUFFIX);
        WWW www = new WWW(cdnUrl + "Main" + AssetPathUtil.XML_SUFFIX);

        yield return(www);

        if (www.error == null)
        {
            XmlDocument configDoc = new XmlDocument();
            XmlElement  elementXml;
            XmlNodeList nodeList;
            configDoc.LoadXml(www.text);
            nodeList = configDoc.SelectSingleNode("root").ChildNodes;
            for (int i = 0; i < nodeList.Count; i++)
            {
                elementXml = (XmlElement)nodeList[i];

                if (elementXml.Name == "randomIP")
                {
                    int        randomLoginIPIndex = UnityEngine.Random.Range(0, elementXml.ChildNodes.Count);
                    XmlElement node = (XmlElement)elementXml.ChildNodes[randomLoginIPIndex];
                    serverIP   = node.GetAttribute("IP");
                    serverPort = node.GetAttribute("port");
                }
                else if (elementXml.Name == "content")
                {
                    VersionManager.remoteVersion = elementXml.GetAttribute("ver");
                    _isForceUpdate = elementXml.GetAttribute("isForceUpdate") == "1";
                    homeUrl        = elementXml.GetAttribute("homeURL");
                    if (elementXml.HasAttribute(_channel))
                    {
                        homeUrl = elementXml.GetAttribute(_channel);
                    }
                    if (elementXml.HasAttribute("microphone"))
                    {
                        isOpenMicrophone = elementXml.GetAttribute("microphone") == "1";
                    }
                    if (elementXml.HasAttribute(_channel + "_ip"))
                    {
                        serverIP   = elementXml.GetAttribute(_channel + "_ip");
                        serverPort = elementXml.GetAttribute(_channel + "_port");
                    }
                }
                else if (elementXml.Name == "notice")
                {
                    noticeType    = int.Parse(elementXml.GetAttribute("noticeType"));
                    noticeTitle   = elementXml.GetAttribute("noticeTitle");
                    noticeContent = elementXml.GetAttribute("noticeContent");
                    Debug.Log(noticeType + "," + noticeTitle + "," + noticeContent);
                }
            }


            Debug.Log("remote xml:" + serverIP + " " + serverPort + " " + Application.version + " home:" + homeUrl);
            Debug.Log("本地版本:" + VersionManager.localVersion + " 远程版本" + VersionManager.remoteVersion);
            //是否强更
            if (_isForceUpdate || VersionManager.CheckNeedForceUpdate(VersionManager.localVersion, VersionManager.remoteVersion))
            {
                Debug.Log("版本过旧");
                AlertUI.Show("<color='#CC3333'>当前游戏不是最新版本</color>\n\n请点击【确认】按钮下载最新游戏客户端", GotoHomeURL);
            }
            else
            {
                //检查是否需要热更新
                if (!closeHotUpdate && VersionManager.CheckVersionIsOld(VersionManager.localVersion, VersionManager.remoteVersion))
                {
                    //创建配置缓存目录
                    string configPath = AssetPathUtil.PersistentDataPath + AssetPathUtil.configPath;
                    if (!Directory.Exists(configPath))
                    {
                        Directory.CreateDirectory(configPath);
                    }
                    //创建音效缓存目录
                    string audioPath = AssetPathUtil.PersistentDataPath + AssetPathUtil.audioPath + "/" + AssetPathUtil.PlatformString;
                    if (!Directory.Exists(audioPath))
                    {
                        Directory.CreateDirectory(audioPath);
                    }
                    //创建AB资源缓存目录
                    string abPath = AssetPathUtil.PersistentDataPath + AssetPathUtil.PlatformString;
                    if (!Directory.Exists(abPath))
                    {
                        Directory.CreateDirectory(abPath);
                    }
                    //加载资源服务器版本文件
                    LoaderManager.Load(cdnUrl + "asset/" + AssetPathUtil.PlatformString + "/" + _versionFileName, EnumResouceType.BINARY, OnCDNVersionFileLoaded);
                }
                else
                {
                    StartGame();
                }
            }
        }
        else
        {
            if (_cdnRetryTimes == 10)
            {
                Debug.LogError(www.error);
            }
            _cdnRetryTimes++;
            if (_cdnRetryTimes > 10)
            {
                _loadingView.SetTitle("网络无法连接,请检查您的网络设置...");
            }
            Debug.Log("正在尝试重新请求CDN....次数:" + _cdnRetryTimes);
            StartCoroutine(DownloadConfigFromCDN());
        }
    }