IEnumerator progress(UnityAction <bool> onComplate)
    {
        //拉取服务器版本
        MsgDispatcher.GetInstance().Fire(GameEvents.UpdateAsset.ShowUpdateAssetInfo, "检测版本号...");

        UnityWebRequest req = UnityWebRequest.Get(GameConfigs.ServerVersionUrl);

        yield return(req.SendWebRequest());

        if (req.isHttpError || req.isNetworkError)
        {
            Debug.LogError(req.error);
            yield break;
        }

        onlineVersion = new System.Version(req.downloadHandler.text);
        curVersion    = new System.Version(Application.version);

        if (onlineVersion != curVersion)
        {
            Debug.LogFormat("当前版本不是最新版本({0}),请及时更新到最新版本({1})", curVersion, onlineVersion);
            IsNeedUpdate = true;
        }

        Debug.Log("版本检测完成!");

        if (onComplate != null)
        {
            onComplate(IsNeedUpdate);
        }

        yield return(null);
    }
Ejemplo n.º 2
0
    IEnumerator _init()
    {
#if UNITY_EDITOR
        Debug.unityLogger.logEnabled = true;
#else
        Debug.unityLogger.logEnabled = false;
#endif


        AssetManager.Instance.InitMode(GameConfigs.LoadAssetMode);
        UIManager.Instance.OpenView(ViewID.PrepareView, null);
        yield return(new WaitForEndOfFrame());

        Debug.Log("跳过版本检测...");
        //UpdateVersionManager.Instance.CheckVersion((bool needUpdate) => {
        //    if (needUpdate) {
        //        MsgBox.SetActive(true);
        //    } else {
        //        UpdateAssetManager.Instance.CheckAsset(() => {
        //            MsgDispatcher.GetInstance().Fire(GameEvents.Msg_DownloadFinish);
        //        });
        //    }
        //});


        // load and parse config data
        MsgDispatcher.GetInstance().Fire(GameEvents.UpdateAsset.ShowUpdateAssetInfo, "加载配置...");
        ConfigManager.Instance.ParseConfigData(AssetManager.Instance.LoadAsset <TextAsset>(GameConfigs.GetConfigPath("DataConfig")).bytes);

        MsgDispatcher.GetInstance().Fire(GameEvents.UpdateAsset.UpdateAssetFinish);


        yield return(null);
    }
    IEnumerator progress(UnityAction onComplete)
    {
        //第一次进入游戏 把streamingassets文件夹数据解压缩到指定的下载目录
        if (true || PlayerPrefs.GetString("IsFirstLaunch", "true") == "true")
        {
            yield return(StartCoroutine(streamingAssetfolderCopyToDownloadFolder()));
        }

        // 加载本地 manifest文件
        if (File.Exists(GameConfigs.LocalManifestPath))
        {
            var manifestAB = AssetBundle.LoadFromFile(GameConfigs.LocalManifestPath);
            curManifest = manifestAB.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            manifestAB.Unload(false);
        }
        else
        {
            Debug.Log("本地资源文件丢失:" + GameConfigs.LocalManifestPath);
        }

        //获取资源服务器端manifest
        Debug.Log("获取资源服务器资源manifest :" + GameConfigs.OnlineManifestPath);
        MsgDispatcher.GetInstance().Fire(GameEvents.Msg_ShowLoadingContent, "检测是否更新资源...");

        UnityWebRequest webReq = UnityWebRequest.Get(GameConfigs.OnlineManifestPath);

        yield return(webReq.SendWebRequest());

        if (webReq.isNetworkError || webReq.isHttpError)
        {
            Debug.Log(webReq.error);
        }
        else
        {
            if (webReq.responseCode == 200)
            {
                byte[]      result           = webReq.downloadHandler.data;
                AssetBundle onlineManifestAB = AssetBundle.LoadFromMemory(result);
                onlineManifest = onlineManifestAB.LoadAsset <AssetBundleManifest>("AssetBundlemanifest");
                onlineManifestAB.Unload(false);
                //更新本地manifest
                writeFile(GameConfigs.LocalManifestPath, webReq.downloadHandler.data);
            }
            yield return(StartCoroutine(download()));


            if (onComplete != null)
            {
                onComplete();
            }
        }
    }
    IEnumerator download()
    {
        var downloadFileList = getDownloadFileName();
        int totalCount       = downloadFileList.Count;
        int count            = 0;

        if (totalCount <= 0)
        {
            Debug.Log("没有需要更新的资源");
        }
        else
        {
            foreach (var iter in downloadFileList)
            {
                string path = GameConfigs.ResServerUrl + "/" + GameConfigs.CurPlatformName + "/" + iter;

                UnityWebRequest req = UnityWebRequest.Get(path);
                yield return(req.SendWebRequest());

                if (req.isNetworkError)
                {
                    Debug.Log(req.error);
                    yield return(null);
                }
                else
                {
                    if (req.responseCode == 200)
                    {
                        byte[] result = req.downloadHandler.data;

                        //save file
                        string downloadPath = GameConfigs.LocalABRootPath + "/" + iter;
                        writeFile(downloadPath, result);
                        Debug.LogFormat("写入:{0} 成功 -> {1} | len =[{2}]", path, downloadPath, result.Length);

                        AssetBundle onlineManifestAB = AssetBundle.LoadFromMemory(result);
                        onlineManifest = onlineManifestAB.LoadAsset <AssetBundleManifest>("AssetBundlemanifest");
                        onlineManifestAB.Unload(false);
                    }
                }
                count++;
                MsgDispatcher.GetInstance().Fire(GameEvents.Msg_DownloadProgress, string.Format("下载资源...({0}/{1})", count, totalCount));
                yield return(new WaitForEndOfFrame());
            }
        }
    }
Ejemplo n.º 5
0
 public override void Execute(Hero entity)
 {
     //throw new System.NotImplementedException();
     //Log.Print(entity.Desc());
     if (index >= contents.Length)
     {
         return;
     }
     if (index < contents.Length)
     {
         Log.Print(contents[index]);
         index++;
         if (index == contents.Length)
         {
             MsgDispatcher.GetInstance().DispatchMessage(0, EntityDef.MAIN_HERO, EntityDef.GLOBAL, MsgDef.MSG_CANJIAKAOSHI);
         }
     }
 }
Ejemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        Btn.gameObject.SetActive(false);
        Img.gameObject.SetActive(false);
        MsgBox.SetActive(false);

        Btn.onClick.AddListener(onClickedBtn);

        UpdateVersionManager.Instance.CheckVersion((bool needUpdate) => {
            if (needUpdate)
            {
                MsgBox.SetActive(true);
            }
            else
            {
                UpdateAssetManager.Instance.CheckAsset(() => {
                    MsgDispatcher.GetInstance().Fire(GameEvents.Msg_DownloadFinish);
                });
            }
        });
    }
Ejemplo n.º 7
0
    public override void OnShowing()
    {
        base.OnShowing();

        MsgDispatcher.GetInstance().Subscribe(GameEvents.Msg_ShowLoadingContent, this);
        MsgDispatcher.GetInstance().Subscribe(GameEvents.Msg_DownloadProgress, this);
        MsgDispatcher.GetInstance().Subscribe(GameEvents.Msg_DownloadFinish, this);

        Transform skinTrans = skin.transform;

        closeBtn = skinTrans.Find("CloseBtn").GetComponent <Button>();

        closeBtn.onClick.AddListener(OnCloseClick);

        testImg     = skinTrans.Find("TestImage").GetComponent <Image>();
        progressTxt = skinTrans.Find("Progress").GetComponent <Text>();

        UpdateVersionManager.Instance.CheckVersion((bool needUpdate) => {
            UpdateAssetManager.Instance.CheckAsset(() => {
                progressTxt.text = "已经是最新资源";
                MsgDispatcher.GetInstance().Fire(GameEvents.Msg_DownloadFinish);
            });
        });
    }
    // streamingAsset文件夹数据解压缩到下载文件夹
    IEnumerator streamingAssetfolderCopyToDownloadFolder()
    {
        Debug.Log("初次运行,解压缩包数据到本地下载文件夹!");
        MsgDispatcher.GetInstance().Fire(GameEvents.Msg_ShowLoadingContent, "解压缩包数据...");

        string srcmanifestpath = GameConfigs.StreamingAssetManifestPath;

        // way 1
        if (Directory.Exists(GameConfigs.GameResExportPath))
        {
            Debug.Log("存在:" + GameConfigs.GameResExportPath);

            //获取该文件夹下所有文件(包含子文件夹)
            var list  = PathUtils.GetFilesPath(GameConfigs.GameResExportPath);
            int total = list.Length;
            int count = 0;
            foreach (var iter in list)
            {
                string srcPath = iter;
                string tarPath = iter.Replace(GameConfigs.GameResExportPath, GameConfigs.LocalABRootPath);

                UnityWebRequest req = UnityWebRequest.Get(srcmanifestpath);
                yield return(req.SendWebRequest());

                if (req.isNetworkError || req.isHttpError)
                {
                    Debug.Log(req.error);
                }
                else
                {
                    if (File.Exists(tarPath))
                    {
                        File.Delete(tarPath);
                    }
                    else
                    {
                        PathUtils.CreateFolderByFilePath(tarPath);
                    }
                    FileStream fs2 = File.Create(tarPath);
                    fs2.Write(req.downloadHandler.data, 0, req.downloadHandler.data.Length);
                    fs2.Flush();
                    fs2.Close();
                    Debug.LogFormat("->解压缩文件{0}到{1}成功", srcPath, tarPath);
                }
                count++;
                MsgDispatcher.GetInstance().Fire(GameEvents.Msg_DownloadProgress, string.Format("解压缩包数据...({0}/{1})", count, total));
            }
        }
        else
        {
            Debug.Log("无需解压缩!");
        }



        //// way 2
        //if (File.Exists(srcmanifestpath)) {
        //    Debug.Log("存在:" + srcmanifestpath);

        //    UnityWebRequest req = UnityWebRequest.Get(srcmanifestpath);
        //    yield return req.SendWebRequest();

        //    if (req.isNetworkError) {
        //        Debug.Log(req.error);
        //    } else {
        //        string tarmanifestpath = GameConfigs.LocalManifestPath;

        //        // copy manifest file
        //        if (File.Exists(tarmanifestpath)) {
        //            File.Delete(tarmanifestpath);
        //        } else {
        //            PathUtils.CreateFolderByFilePath(tarmanifestpath);
        //        }
        //        FileStream fs2 = File.Create(tarmanifestpath);
        //        fs2.Write(req.downloadHandler.data, 0, req.downloadHandler.data.Length);
        //        fs2.Flush();
        //        fs2.Close();
        //        Debug.LogFormat("解压缩文件{0}到{1}成功", srcmanifestpath, tarmanifestpath);



        //        var manifestAB = AssetBundle.LoadFromMemory(req.downloadHandler.data);
        //        var manifest = manifestAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
        //        manifestAB.Unload(false);



        //        var allABList = manifest.GetAllAssetBundles();


        //        foreach (var iter in allABList) {
        //            string oriPath = GameConfigs.GameResExportPath + "/" + iter;
        //            string tarPath = GameConfigs.DownLoadAssetPath + "/" + iter;

        //            req = UnityWebRequest.Get(oriPath);
        //            yield return req.SendWebRequest();

        //            if (req.isNetworkError) {
        //                Debug.Log("加载文件失败:" + oriPath);
        //            } else {
        //                if (File.Exists(tarPath)) {
        //                    File.Delete(tarPath);
        //                } else {
        //                    PathUtils.CreateFolderByFilePath(tarPath);
        //                }

        //                Debug.LogFormat("解压缩文件{0}到{1}成功", oriPath, tarPath);


        //                FileStream fs = File.Open(tarPath, FileMode.OpenOrCreate);
        //                fs.Write(req.downloadHandler.data, 0, req.downloadHandler.data.Length);
        //                fs.Flush();
        //                fs.Close();
        //            }
        //        }

        //        Debug.Log("解压缩完成!");
        //    }

        //} else {
        //    Debug.Log("不存在:" + GameConfigs.StreamingAssetManifestPath);
        //}
    }
 public void CheckAsset(UnityAction onComplete = null)
 {
     MsgDispatcher.GetInstance().Fire(GameEvents.Msg_ShowLoadingContent, "检测资源...");
     Debug.Log("GameConfigs.LocalABRootPath:" + GameConfigs.LocalABRootPath);
     StartCoroutine(progress(onComplete));
 }
Ejemplo n.º 10
0
 void OnDisable()
 {
     MsgDispatcher.GetInstance().UnSubscribe(GameEvents.Msg_ShowLoadingContent, this);
     MsgDispatcher.GetInstance().UnSubscribe(GameEvents.Msg_DownloadProgress, this);
     MsgDispatcher.GetInstance().UnSubscribe(GameEvents.Msg_DownloadFinish, this);
 }
Ejemplo n.º 11
0
 public void CheckAsset(UnityAction onComplete = null)
 {
     MsgDispatcher.GetInstance().Fire(GameEvents.UpdateAsset.ShowUpdateAssetInfo, "检测资源...");
     StartCoroutine(progress(onComplete));
 }
Ejemplo n.º 12
0
 public void EnterGame()
 {
     MsgDispatcher.GetInstance().Fire(GameEvents.GameProcess.EnterGame);
     UIManager.Instance.OpenView(ViewID.SignInView, OpenViewTag.HidePrevious, true, null);
 }
Ejemplo n.º 13
0
 public void CheckAsset(UnityAction onComplete = null)
 {
     MsgDispatcher.GetInstance().Fire(GameEvents.Msg_ShowLoadingContent, "检测资源...");
     StartCoroutine(progress(onComplete));
 }
Ejemplo n.º 14
0
 void OnDisable()
 {
     MsgDispatcher.GetInstance().UnSubscribe(GameEvents.UpdateAsset.ShowUpdateAssetInfo, this);
     MsgDispatcher.GetInstance().UnSubscribe(GameEvents.UpdateAsset.UpdateAssetFinish, this);
 }