Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        ZLog.D(this, "start");
        StringBuilder sb = new StringBuilder();

        sb.AppendFormat("absoluteURL:{0}\n", Application.absoluteURL);
        sb.AppendFormat("dataPath:{0}\n", Application.dataPath);
        sb.AppendFormat("consoleLogPath:{0}\n", Application.consoleLogPath);
        sb.AppendFormat("persistentDataPath:{0}\n", Application.persistentDataPath);
        sb.AppendFormat("streamingAssetsPath:{0}\n", Application.streamingAssetsPath);
        sb.AppendFormat("temporaryCachePath:{0}\n", Application.temporaryCachePath);
        sb.AppendFormat("UserDocumentPath:{0}\n", OSTools.GetUserDocumentPath());


        _component.iptFight.text = sb.ToString();
        Text txt = _component.btnSend.GetComponentInChildren <Text>();

        txt.text = "加载配置";
        SetClickEventOnce(_component.btnSend, ClickCall, null);
        //_component.btnSend.Text = "hello";
    }
Exemple #2
0
        IEnumerator SwitchSceneUseBlankScene(string sceneName, bool useAnimate, bool useFade, string tips, System.Action callback)
        {
            Scene c = SceneManager.GetActiveScene();
            Scene b = SceneManager.GetSceneByName(blankScene);

            if (!b.isLoaded)
            {
                SceneManager.LoadScene(blankScene, LoadSceneMode.Additive);
                yield return(new WaitProcess(10));

                b = SceneManager.GetSceneByName(blankScene);
            }
            yield return(new WaitProcess(20));

            {
                var op = SceneManager.UnloadSceneAsync(c);
                while (!op.isDone)
                {
                    yield return(new WaitProcess(40));
                }
            }

            {
                AsyncOperation op = null;
                if (!isLowMemory)
                {
                    if (OSTools.GetCurrentMemory() > AssetManager.MemoryThreshold)
                    {
                        isLowMemory = true;
                    }
                }
                if (isLowMemory)
                {
                    Debug.LogWarning("CheckMemoryThread low memory unload all asset");
                    isLowMemory = false;
                    op          = AssetManager.UnloadAll(true);
                }
                else
                {
                    op = Resources.UnloadUnusedAssets();
                }

                while (op != null && !op.isDone)
                {
                    yield return(new WaitProcess(50));
                }
            }

            {
                var async = AssetManager.LoadScene(sceneName);
                while (async != null && !async.completed)
                {
                    yield return(new WaitProcess(65));
                }

                if (BeforeSceneUnload != null)
                {
                    BeforeSceneUnload();
                }
                var op = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
                while (!op.isDone)
                {
                    yield return(new WaitProcess(80));
                }
                if (AfterSceneReady != null)
                {
                    AfterSceneReady();
                }
                yield return(null);
            }

            {
                SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName));
                yield return(new WaitProcess(90));

                if (callback != null)
                {
                    callback();
                    callback = null;
                }
            }
            process = 100;
        }
Exemple #3
0
        IEnumerator LoadPatch()
        {
            string platfrom = GetPlatformName();

            if (string.IsNullOrEmpty(platfrom))
            {
                platfrom = Application.platform.ToString();
            }
            step = Step.Check;
            string fullURL = gameURL + "patch/index2.php?" + HTTPQueryStr; // He platform=" + platfrom + "&v=" + Application.version + "&t=" + versionTag;

            Debug.LogFormat(fullURL);

            WWW www = new WWW(fullURL);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log(www.error);
                message.text = "加载补丁列表失败";

                if (reloadButton != null && (versionTag == "test" || versionTag == "dev"))
                {
                    reloadButton.SetActive(true);
                }

                yield break;
            }

#if UNITY_EDITOR
            if (!AssetManager.SimulateMode)
#endif
            {
                ResourceBundle.Clear();
                AssetManager.Clear();
            }

            LoadingInfo info = JsonUtility.FromJson <LoadingInfo>(www.text);
            Debug.Log(www.text);

            if (!string.IsNullOrEmpty(info.bundleURL))
            {
                bundleURL = info.bundleURL;
            }

            server_list = info.server_list;

            serverTag = info.tag;

            if (string.IsNullOrEmpty(info.asset_version))
            {
                info.asset_version = AssetVersion.Version;
            }
            versionString    = string.Format("{0}:{1}:{2}", Application.version, AssetVersion.Version, info.asset_version);
            versionText.text = versionString;
            Debug.Log("version:" + versionString);

            Dictionary <string, string> localbundles = new Dictionary <string, string>();
            do
            {
#if UNITY_EDITOR
                if (AssetManager.SimulateMode)
                {
                    break;
                }
#endif
                if (AssetVersion.Version == info.asset_version)
                {
                    break;
                }

                List <PatchInfo> lpds = GetLocalBundles(info, ref localbundles);

                total_count  = lpds.Count;
                loaded_count = 0;

                int patchDownLoadTotalSize = 0;
                for (int i = 0; i < total_count; ++i)
                {
                    patchDownLoadTotalSize += lpds[i].size;
                }

                OSTools.AlertDialog("提示", string.Format("您将下载 {0} MB 的资源", patchDownLoadTotalSize / 1024 / 1024),
                                    "确认", () =>
                {
                    patchDownLoadTotalSize = 0;
                },
                                    "取消", () =>
                {
                    Application.Quit();
                });

                while (patchDownLoadTotalSize > 0)
                {
                    yield return(null);
                }

                for (int i = 0; i < total_count; ++i)
                {
                    var    patch = lpds[i];
                    string url   = patch.file;
                    if (!url.StartsWith("http://"))
                    {
                        url = info.patchURL + "/" + url;
                    }

                    step = Step.Down;

                    // current_file = patch.file;
                    Debug.LogFormat("down patch {0}", url);
                    loading_www = new WWW(url);
                    yield return(loading_www);

                    if (loading_www.error != null && !loading_www.error.Equals(""))
                    {
                        message.text = "下载补丁文件失败";
                        yield break;
                    }

                    if (loading_www.bytesDownloaded != patch.size)
                    {
                        Debug.LogError("down load patch error, patch file:" + patch.file);
                        break;
                    }

                    step         = Step.Unzip;
                    message.text = "解压文件..."; process = 1; yield return(new WaitForSeconds(0.1f));

                    List <string> files = new List <string>();
                    unzipFile(loading_www.bytes, Application.persistentDataPath + "/" + patch.version, (string name) =>
                    {
                        files.Add(name);
                    });

                    step         = Step.Install;
                    message.text = "安装补丁..."; process = 0; yield return(new WaitForSeconds(0.1f));

                    bool flag = false;
                    AssetVersion.StartAddBundle(patch.version);
                    int c = 0;
                    foreach (var p in files)
                    {
                        if (!MergePatch(p, patch, ref localbundles))
                        {
                            flag = true;
                            break;
                        }
                        AssetVersion.AddBundle(p.Replace(".patch", ""));
                        message.text = string.Format("正在安装补丁:{0}/{1}", ++c, files.Count);
                        process      = c / (float)files.Count; yield return(null);
                    }
                    AssetVersion.EndAddBundle();
                    message.text = "安装补丁结束"; process = 1; yield return(null);

                    if (flag)
                    {
                        AssetVersion.ClearBundle(patch.version);
                        break;
                    }

                    AssetVersion.Version = patch.version;
                    AssetVersion.Flush();
                    loaded_count += 1;
                }

                if (loaded_count != total_count)
                {
                    break;
                }

                versionText.text = string.Format("{0}:{1}:{2}", Application.version, AssetVersion.Version, info.asset_version);
                loading_www      = null;
                Caching.ClearCache();
            } while (false);

            if (loaded_count != total_count || total_count == 0)
            {
                localbundles.Clear();
                GetLocalBundles(info, ref localbundles);
            }

            foreach (var iter in localbundles)
            {
                var    v          = iter.Value;
                string bundlename = iter.Key;
                string abrepath   = v + "/" + bundlename;
                string fullpath   = Application.persistentDataPath + "/" + abrepath;
                if (Path.GetFileName(abrepath).StartsWith("hotfix"))
                {
                    ResourceBundle.Replace(bundlename, fullpath);
                }
                else
                {
                    if (PatchFiles.ContainsKey(bundlename))
                    {
                        PatchFiles[bundlename] = v;
                    }
                    else
                    {
                        PatchFiles.Add(bundlename, v);
                    }
                }
            }

            SetVersionList(info);

            Statistics.GetCache(this);

            AssetManager.Init();
            message.text = total_count != 0 && loaded_count != total_count ? "补丁更新失败,正在使用本地版本进入游戏" : "加载游戏中...";
            step         = Step.Enter;
            process      = 0;

            versionString = string.Format("{0}:{1}:{2}", Application.version, AssetVersion.Version, info.asset_version);
            yield return(new WaitForSeconds(0.22f));

            patch_is_ready = true;
            StartCoroutine(BundleManager.DownAndLoadThread());
            StartCoroutine(AssetManager.CheckMemoryThread());
        }