示例#1
0
    IEnumerator DelayLoadScene()
    {
        yield return(null);

        var watchReport = new BTickWatcher();

        EventLogReport.Instance.ReportEvent(EventLogType.event_start_enter_game);

        InitCustomAbVfs();

        if (!AssetBundleLoader.Instance.Init(true))
        {
            EventLogReport.Instance.ReportEvent(EventLogType.event_fail_enter_game, "AssetBundleLoader.Init failed");

            BLogger.Error("AssetBundleLoader init failed");
            ShowText("进入游戏失败(资源错误)");
            yield break;
        }

        //读取缓存策略
        LoadAbCacheConfig();

        SceneAssetLoader loader = SceneAssetLoader.Instance;
        var watchStep           = new BTickWatcher();

        float preloadConfigPercent = 0.3f;

        EventLogReport.Instance.ReportEvent(EventLogType.event_preload_config, watchStep.ElapseTime());
        watchStep.Refresh();

        float currPercent = preloadConfigPercent;

        yield return(AssetBundleLoader.Instance.StartCoroutine(UnitySceneLoader.LoadSceneAsync(m_startScene,
                                                                                               (progress) =>
        {
            float actualProgress = currPercent + (1.0f - currPercent) * progress;
            int currProgress = (int)(actualProgress * 100);
            if (m_title != null)
            {
                m_title.text = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_GAME_ETNERING) +
                               currProgress.ToString() + "%";
                SetProgress((uint)currProgress, 100);
            }

            BLogger.Info("scene loading process:{0}", currProgress);
        }, null)));

        EventLogReport.Instance.ReportEvent(EventLogType.event_load_scene0, watchStep.ElapseTime());
        watchStep.Refresh();

        if (loader.haveError)
        {
            ShowConfirm(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_ENTER_GAME_FAILED,
                                                              loader.lastError), false, DodLib.DoQuit);
            yield break;
        }

        EventLogReport.Instance.ReportEvent(EventLogType.event_end_enter_game, watchReport.ElapseTime());
    }
示例#2
0
    IEnumerator ContinueDownloadAb(AssetVerInfo svrVerInfo)
    {
        var watchReport = new BTickWatcher();

        EventLogReport.Instance.ReportEvent(EventLogType.event_start_update_ab);

        //开始更新数据包
        ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_ASSET_UPDATE));
        yield return(StartCoroutine(AssetVersionMgr.Instance.BeginUpdateAsset(svrVerInfo.m_assetUrl, this)));

        if (AssetVersionMgr.Instance.haveErr)
        {
            EventLogReport.Instance.ReportEvent(EventLogType.event_fail_update_ab, AssetVersionMgr.Instance.error);

            ShowConfirm(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_ASSET_UPDATE_FAILED,
                                                              AssetVersionMgr.Instance.error), true, RetryUpdate);
            yield break;
        }

        EventLogReport.Instance.ReportEvent(EventLogType.event_end_update_ab, watchReport.ElapseTime());

        //判断是否更新了脚本,如果更新了脚本,那么需要重新启动进程
        if (AssetVersionMgr.Instance.scriptUpdated ||
            XGameStartParamData.fromGrayUpdate || /*如果是灰度更新界面切过来的,那么肯定要重启*/
            XGameStartParamData.fromRepairClient)
        {
            ShowConfirm(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_NEED_RESTART), false,
                        DodLib.RestartApp);
            yield break;
        }

        //如果是资源更新了,那么重新读取本地版本信息
        AssetVersionMgr.Instance.ReadBaseInfo();

        StartEnterGameScene();
    }
示例#3
0
    /// <summary>
    /// 准备预处理AB资源,从jar文件挪到data目录
    /// </summary>
    /// <returns></returns>
    IEnumerator GameStartup()
    {
        //m_process.gameObject.SetActive(false);
        AssetBundlePrepare abPrepare = AssetBundlePrepare.Instance;

        ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_GAME_ETNERING));
        m_labelVersion.text = "";

        yield return(StartCoroutine(abPrepare.CheckNeedPrepare()));

        ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_GAME_ETNERING));

        if (BaseConfigInfo.enableObbSplitMode)
        {
            if (ObbMgr.Instance.IsNeedDownloadObb())
            {
                SceneManager.LoadScene("Scene_obbdownload");
                yield break;
            }
        }

        var isReportPrepareEvent = false;
        var watchReport          = new BTickWatcher();

        if (!abPrepare.IsHaveErr() && abPrepare.NeedPrepare)
        {
            EventLogReport.Instance.ReportEvent(EventLogType.event_start_unpack);
            isReportPrepareEvent = true;
        }

        yield return(StartCoroutine(abPrepare.StartPrepareAb(this)));

        if (abPrepare.IsHaveErr())
        {
            if (isReportPrepareEvent)
            {
                EventLogReport.Instance.ReportEvent(EventLogType.event_fail_unpack, abPrepare.error);
            }

            ShowConfirm(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_PREPARE_FAILED, abPrepare.error), false,
                        DodLib.DoQuit);
            yield break;
        }

        if (isReportPrepareEvent)
        {
            EventLogReport.Instance.ReportEvent(EventLogType.event_end_unpack, watchReport.ElapseTime());
        }

        ///开始检测版本
        AssetVersionMgr.Instance.ReadBaseInfo();

        if (AssetVersionMgr.Instance.haveErr)
        {
            ShowConfirm(
                StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_ASSETVER_INIT_FAILED,
                                                      AssetVersionMgr.Instance.error), false,
                DodLib.DoQuit);
            yield break;
        }

        DBugly.Init(BaseConfigInfo.PlatformName, AssetVersionMgr.Instance.assetVersion);

//         //统计检查版本成功还是失败
//         PlatformUtil.StatisticsEventBegin("boot_update");

        //获取版本号
        string version = AssetVersionMgr.Instance.assetVersion;

        m_labelVersion.text = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_VERSION_INFO, version);

        StartTickTitle(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE));
        AssetUpdater updater = AssetUpdater.Instance;

        yield return(StartCoroutine(updater.CheckUpdate(false, this)));

        StopTickTitle();

        AssetVerInfo svrVerInfo = updater.svrVerInfo;

        if (svrVerInfo == null)
        {
//             PlatformUtil.StatisticsEventFailed("boot_update", "network");
            ShowConfirm(
                StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_VERSION_FAILED,
                                                      AssetVersionMgr.Instance.error), false, RetryUpdate);
            yield break;
        }

//         PlatformUtil.StatisticsEventEnd("boot_update");

        if (svrVerInfo.m_updateType == AssetUpdateType.UPDATE_NONE)
        {
            StartEnterGameScene();
        }
        else if (svrVerInfo.m_updateType == AssetUpdateType.UPDATE_ASSET)
        {
            ///读取本地
            AssetVersionMgr.Instance.LoadLocalAllAssetMd5();

            //获取更新的大小
            StartTickTitle(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_CONTENT));
            yield return(StartCoroutine(AssetVersionMgr.Instance.DownloadLatestIndex(svrVerInfo.m_assetUrl)));

            yield return(StartCoroutine(AssetVersionMgr.Instance.BeginUpdateIndex(svrVerInfo.m_assetUrl)));

            StopTickTitle();

            if (AssetVersionMgr.Instance.haveErr)
            {
                ShowConfirm(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_CONTENT_FAILED,
                                                                  AssetVersionMgr.Instance.error), false, RetryUpdate);
                yield break;
            }
#if !UNITY_EDITOR
            if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
            {
                //直接下载
                OnUpdateConfirmOK();
            }
            else
#endif
            ShowConfirm(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_ASSET_UPDATE_INFO,
                                                              AssetVersionMgr.Instance.GetUpdateFileCount(), GetDataSize(AssetVersionMgr.Instance.GetToUpdateSize())), true,
                        OnUpdateConfirmOK, OnUpdateConfirmCancel);
        }
        else if (svrVerInfo.m_updateType == AssetUpdateType.UPDATE_PROGRAME)
        {
            if (string.IsNullOrEmpty(svrVerInfo.m_help))
            {
                ShowConfirm(svrVerInfo.m_err, true,
                            OnUpdateConfirmOK, OnUpdateConfirmCancel);
            }
            else
            {
                ShowConfirmIos(svrVerInfo.m_err, OnUpdateConfirmOK, () =>
                {
                    Application.OpenURL(svrVerInfo.m_help);
                });
            }
        }
        else if (svrVerInfo.m_updateType == AssetUpdateType.UPDATE_ERROR)
        {
            ShowText(svrVerInfo.m_err);
        }
        else
        {
            ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_JSON_DETAIL,
                                                           svrVerInfo.m_updateType));
        }
    }