Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        UIManager.AdaptiveUI();

        GlobalConst.IS_DEVELOP = false;

        goLogoPanel = goLogo;
        UpdateVersionScript.SetLogoActive(true);

        labLoading      = this.transform.FindChild("Update/Progress/Tips").GetComponent <UILabel>();
        labCheckingTips = this.transform.FindChild("Update/UpdateCheckingTips").GetComponent <UILabel>();
        labVersion      = this.transform.FindChild("Update/Version").GetComponent <UILabel>();
        ProgressBar     = this.transform.FindChild("Update/Progress/BarBack").GetComponent <UIProgressBar>();

        MessageTips.SetActive(false);

        int local_version = VersionUpdateManager.VersionTag;

        if (local_version != 0)
        {
            GlobalConst.RES_VERSION = VersionUpdateManager.VersionIntToStr(local_version);
        }
        this.ChangeVersionLabel(VersionUpdateManager.VersionStrToInt(GlobalConst.RES_VERSION));

        VersionUpdateManager.Instance.onDownLoadPeracent      = OnDownLoadPeracentChanged;
        VersionUpdateManager.Instance.onDecompressionPeracent = OnDecompressionPeracent;
        VersionUpdateManager.Instance.onUpdateFinished        = OnUpdateFinished;
        VersionUpdateManager.Instance.onUpdateFaild           = OnUpdateFaild;
        VersionUpdateManager.Instance.onUpdateTips            = OnUpdateTips;

        VersionUpdateManager.AddUpdateCmd(UpdateCmdType.GetStreamAssetInfo);
    }
Exemplo n.º 2
0
    public IEnumerator LoadVersionList()
    {
        WWW wwwVerList = new WWW(urlRoot + "/version_list.txt");

        yield return(wwwVerList);

        if (!string.IsNullOrEmpty(wwwVerList.error))
        {
            Debug.Log("网络故障或没有找到更新列表文件=>" + urlRoot + "/version_list.txt");
            if (this.onUpdateFaild != null)
            {
                this.onUpdateFaild();
            }

            yield return(null);
        }
        else
        {
            verList.Clear();

            //版本描述信息 版本号@文件数 换行
            Debug.Log("version_list:" + wwwVerList.text);
            byte[]       strBytes = Encoding.UTF8.GetBytes(wwwVerList.text);
            MemoryStream stream   = new MemoryStream(strBytes);
            StreamReader reader   = new StreamReader(stream);

            string lineInfo;
            bool   isFirstLine      = true;
            bool   isUpdate         = false; //是否需要更新
            long   iUpdateTotalSize = 0;

            while ((lineInfo = reader.ReadLine()) != null)
            {
                var list = SplitString(lineInfo, '@');
                if (list == null || list.Count != 3)
                {
                    continue;
                }

                //大版本更新检查
                if (isFirstLine && localVersion > 0)
                {
                    isFirstLine = false;
                    int sBig = list[0] / 1000000;
                    int lBig = localVersion / 1000000;
                    if (sBig > lBig)
                    {
                        iUpdateTotalSize = -1;
                        break;
                    }
                }

                VersionInfo info = new VersionInfo();
                info.ver      = list[0];
                info.file_num = list[1];
                info.zip_size = list[2];
                verList.Add(info.ver, info);

                //计算本次更新总共需要下载资源大小
                if (info.ver > localVersion)
                {
                    isUpdate = true;
                    string directory = string.Format("{0}/update/{1}/{2}.zip", persistentDataPath, info.ver, GamePlat);
                    if (!File.Exists(directory))
                    {
                        iUpdateTotalSize += info.zip_size;
                    }
                }
            }

            if (iUpdateTotalSize == -1)
            {
                UpdateVersionScript.SetLogoActive(false);
                Debug.Log("需要大版本更新游戏,请市场下载最新版本!");
                if (onUpdateTips != null)
                {
                    onUpdateTips(UpdateVersionTipsScript.TipsMessageType.VersionUpdateBig, 0);
                }
            }
            else if (iUpdateTotalSize == 0)
            {
                if (isUpdate) //已下载好资源,没解压。需要下载的资源流量也是0
                {
                    this.StartUpdate();
                }
                else
                {
                    Debug.Log("已是最新版本,无需要更新游戏");
                    if (this.onUpdateFinished != null)
                    {
                        this.onUpdateFinished(localVersion);
                    }
                }
            }
            else
            {
                if (!isRetry)
                {
                    UpdateVersionScript.SetLogoActive(false);
                    Debug.Log("提示玩家是否现在更新");
                    if (onUpdateTips != null)
                    {
                        onUpdateTips(UpdateVersionTipsScript.TipsMessageType.VersionUpdateSmall, iUpdateTotalSize);
                    }
                }
                else
                {
                    VersionUpdateManager.Instance.StartUpdate();
                }
            }
        }
    }
Exemplo n.º 3
0
    public IEnumerator StreamAssetInit()
    {
        if (localVersion != 0)
        {
            VersionUpdateManager.AddUpdateCmd(UpdateCmdType.LoadVersionList);
        }
        else
        {
            UpdateVersionScript.SetLogoActive(false);
            bool   isOk    = true;
            int    curPos  = 0;
            string name    = GamePlat;
            string desPath = persistentDataPath + "/" + name + ".zip";
            if (File.Exists(desPath))
            {
                File.Delete(desPath);
            }
            FileStream stream = new FileStream(desPath, FileMode.Create);

            for (int index = 1; index <= streamAssetVersionInfo.pack_num; index++)
            {
                string srcPath = streamingAssetsPath + "/" + name + index.ToString();

                WWW www = new WWW(srcPath);
                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                {
                    isOk = false;
                    Debug.LogWarning(srcPath);
                    Debug.LogError("StreamAssetCopyToPersistentDataPath Error!!! " + www.error);
                    if (this.onUpdateFaild != null)
                    {
                        this.onUpdateFaild();
                    }

                    //失败了,则从网络获取更新列表(最小打包的方式,本地不放置资源包)
                    VersionUpdateManager.AddUpdateCmd(UpdateCmdType.LoadVersionList);

                    break;
                }
                else
                {
                    stream.Seek(curPos, SeekOrigin.Begin);
                    stream.Write(www.bytes, 0, www.bytes.Length);
                    stream.Flush();
                    curPos += www.bytes.Length;
                }
            }

            stream.Close();
            stream.Dispose();

            if (isOk)
            {
                streamAssetVersionInfo.path = desPath;

                Thread thread = new Thread(new ParameterizedThreadStart(StreamAssetInitVersion));
                thread.Start(streamAssetVersionInfo);
            }
        }
    }