Exemple #1
0
    void LaunchUpdater()
    {
        m_Updater = gameObject.GetComponent <Updater>();
        if (m_Updater == null)
        {
            m_Updater = gameObject.AddComponent <Updater>();
        }

        List <string> url_group = new List <string>();

        url_group.Add(m_URL);

        m_Updater.OnUpdate += (Args) =>
        {
            if (Args.CurrentState == Updater.emState.UpdateAssetBundle)
            {
                if (m_ServerVersion != 0)
                {
                    return;
                }

                string            file = Common.GetCacheFileFullName(Common.RESOURCES_MANIFEST_FILE_NAME);
                ResourcesManifest server_resources_manifest = Common.LoadResourcesManifestByPath(file);
                m_ServerVersion = server_resources_manifest.Data.Version;
                string version = m_TxtVersion.text + "\n" + string.Format("服务器版本号:{0}", m_ServerVersion);
                m_TxtVersion.text = version;

                if (m_ServerVersion == m_CllientVersion)
                {
                    m_Updater.AbortUpdate();
                    m_Updater = null;
                    m_Slider.gameObject.SetActive(false);
                    m_UpdateTips.text = "版本一致,准备进入游戏";
                    if (m_Complate != null)
                    {
                        m_Complate(string.Empty);
                    }
                }
            }
        };

        m_Updater.OnDone += (Args) => {
            m_Slider.gameObject.SetActive(false);
            m_Updater         = null;
            m_UpdateTips.text = "更新成功,准备进入游戏";
            if (m_Complate != null)
            {
                m_Complate(string.Empty);
            }
        };

        m_Updater.StartUpdate(url_group);
    }
    void OnGUI_Example_Ready()
    {
        //启动成功
        GUI.Label(new Rect(0f, 0f, Screen.width, 20f), "AssetBundlePacker launch succeed, Version is " + AssetBundleManager.Instance.strVersion);
        //下载地址
        GUI.Label(new Rect(0f, 20f, 100f, 20f), "下载地址:");
        URL = GUI.TextField(new Rect(100f, 20f, Screen.width - 100f, 20f), URL);

        //启动更新器
        if (updater_ == null)
        {
            if (GUI.Button(new Rect(0f, 40f, Screen.width, 30f), "启动更新器"))
            {
                LaunchUpdater();
            }
        }
        else
        {
            //当前更新阶段
            GUI.Label(new Rect(0, 40f, Screen.width, 20f), STATE_DESCRIBE_TABLE[(int)updater_.CurrentState]);
            //当前阶段进度
            GUI.HorizontalScrollbar(new Rect(0f, 60f, Screen.width, 30f)
                                    , 0f, updater_.CurrentProgress
                                    , 0f, 1f);

            if (!updater_.IsDone && !updater_.IsFailed)
            {
                if (GUI.Button(new Rect(0, 80f, Screen.width, 20f), "中断更新"))
                {
                    Debug.Log("Abort Update");
                    updater_.AbortUpdate();
                    Destroy(updater_);
                }
            }
            else if (updater_.IsDone)
            {
                if (updater_.IsFailed)
                {
                    if (GUI.Button(new Rect(0, 80f, Screen.width, 20f), "更新失败,重新开始"))
                    {
                        Destroy(updater_);
                    }
                }
                else
                {
                    GUI.Label(new Rect(0, 80f, Screen.width, 20f), "更新成功");
                }
            }
        }
    }