SetProgressbarValue() public static method

public static SetProgressbarValue ( int rProgress ) : void
rProgress int
return void
    IEnumerator LoadSceneInternal()
    {
        displayProgress = 5;
        LoadingLayer.SetProgressbarTips("Scene Initialize ...");
        LoadingLayer.SetProgressbarValue(displayProgress);

        async     = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(loadSceneName); //Application.LoadLevelAsync(loadSceneName);
        IsLoading = true;
        async.allowSceneActivation = false;

        while (async.progress < 0.9f)
        {
            progress = (int)async.progress * 100;
            while (displayProgress < progress)
            {
                ++displayProgress;
                LoadingLayer.SetProgressbarValue(displayProgress);
                yield return(new WaitForEndOfFrame());
            }
            yield return(new WaitForEndOfFrame());
        }

        progress = 90;
        while (displayProgress < progress)
        {
            ++displayProgress;
            LoadingLayer.SetProgressbarValue(displayProgress);
            yield return(new WaitForEndOfFrame());
        }

        async.allowSceneActivation = true;
        InitializeScene();

        IsLoading = false;
    }
    IEnumerator OnInitializeComplete()
    {
        progress = 100;

        while (displayProgress < progress)
        {
            ++displayProgress;
            LoadingLayer.SetProgressbarValue(displayProgress);
            yield return(new WaitForEndOfFrame());
        }

        loadSceneName   = null;
        async           = null;
        progress        = 0;
        displayProgress = 0;
        sceneBundle.Unload(false);

        LoadingLayer.Hide();

        if (OnInitializeSceneComplete != null)
        {
            OnInitializeSceneComplete.Invoke();
            OnInitializeSceneComplete = null;
        }
    }
Esempio n. 3
0
    void LoadAssetbundleManifest()
    {
        LoadingLayer.SetProgressbarTips("游戏初始化中");
        LoadingLayer.SetProgressbarValue(5);
        string bundlName = AppPlatform.GetAssetBundleDirName();

        Global.AssetLoadManager.DownloadingURL = AppPlatform.GetRuntimeAssetBundleUrl();
        Global.AssetLoadManager.LoadManifest(bundlName, () =>
        {
            onStartupFunc();
        });
    }
    IEnumerator LoadSceneBundle()
    {
        LoadingLayer.SetProgressbarTips("Loading Scene...");
        LoadingLayer.SetProgressbarValue(1);

        var rUrl = AppPlatform.GetRuntimeSceneBundleUrl() + loadSceneName.ToLower() + "." + Global.BundleExtName;

        Debug.Log("[DownloadSceneBundle]:>" + rUrl);
        var download = new WWW(rUrl);

        yield return(download);

        if (download.error != null)
        {
            Debug.LogError(download.error);
            yield break;
        }

        sceneBundle = download.assetBundle;

        StartCoroutine(LoadSceneInternal());
    }
Esempio n. 5
0
    IEnumerator OnUpdateResource()
    {
        LoadingLayer.Show();

        if (!AppConst.UpdateMode)
        {
            ResourceUpdateEnd();
            yield break;
        }

        string dataPath = AppPlatform.DataPath;  //数据目录
        string url      = AppConst.WebUrl + AppPlatform.GetCurPackageResPath();
        string listUrl  = url + "files.txt";

        Debuger.Log("LoadUpdate---->>>" + listUrl);

        WWW www = new WWW(listUrl);

        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        //if (www.error != null)
        {
            Debuger.Log(www.error);
            LoadingLayer.Hide();
            yield break;
        }

        if (!Directory.Exists(dataPath))
        {
            Directory.CreateDirectory(dataPath);
        }

        File.WriteAllBytes(dataPath + "files.txt", www.bytes);

        string filesText = www.text;

        string[] files = filesText.Split('\n');
        for (int i = 0; i < files.Length; i++)
        {
            float percent = (float)i / (files.Length - 1);
            LoadingLayer.SetProgressbarValue(percent);

            if (string.IsNullOrEmpty(files[i]))
            {
                continue;
            }

            string[] keyValue  = files[i].Split('|');
            string   f         = keyValue[0];
            string   localfile = (dataPath + f).Trim();

            string path = Path.GetDirectoryName(localfile);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string fileUrl   = url + f;
            bool   canUpdate = !File.Exists(localfile);
            if (!canUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = Utility.Md5file(localfile);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfile);
                }
            }

            if (canUpdate)
            {
                //本地缺少文件
                Debuger.Log(fileUrl);

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

                if (!string.IsNullOrEmpty(www.error))
                //   if (www.error != null)
                {
                    Debuger.Log(www.error);
                    LoadingLayer.Hide();
                    yield break;
                }

                File.WriteAllBytes(localfile, www.bytes);
            }
        }

        yield return(new WaitForEndOfFrame());

        ResourceUpdateEnd();
    }
Esempio n. 6
0
    IEnumerator OnExtractResource()
    {
        string streampath = AppPlatform.StreamingAssetsPath;
        string datapath   = AppPlatform.DataPath;
        string infile     = streampath + "files.txt";
        string outfile    = datapath + "files.txt";

        if (File.Exists(outfile))
        {
            File.Delete(outfile);
        }

        if (Directory.Exists(datapath))
        {
            Directory.Delete(datapath);
        }

        Directory.CreateDirectory(datapath);

        LoadingLayer.Show();

        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(infile);
            yield return(www);

            if (www.isDone)
            {
                File.WriteAllBytes(outfile, www.bytes);
            }

            yield return(0);
        }
        else
        {
            File.Copy(infile, outfile, true);
        }

        yield return(new WaitForEndOfFrame());

        //释放所有文件到数据目录
        string[] files = File.ReadAllLines(outfile);
        for (int i = 0; i < files.Length; i++)
        {
            float    percent = (float)i / (files.Length - 1);
            string   file    = files[i];
            string[] fs      = file.Split('|');
            infile  = streampath + fs[0]; //
            outfile = datapath + fs[0];

            Debuger.Log("正在解包文件:>" + infile);
            LoadingLayer.SetProgressbarValue(percent);

            string dir = Path.GetDirectoryName(outfile);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }

                yield return(0);
            }
            else
            {
                if (File.Exists(outfile))
                {
                    File.Delete(outfile);
                }

                File.Copy(infile, outfile, true);
            }

            yield return(new WaitForEndOfFrame());
        }

        yield return(new WaitForSeconds(0.1f));

        StartCoroutine(OnUpdateResource());
    }
Esempio n. 7
0
    static IEnumerator OnUnpackAssets()
    {
        LoadingLayer.SetProgressbarTips("开始解包资源");

        //解包config server
        string infile  = Application.streamingAssetsPath + "/" + "server.ini";
        string outfile = AppPlatform.RuntimeAssetsPath + "server.ini";

        if (infile != outfile)
        {
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            if (AppPlatform.PlatformCurrent == Platform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(null);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            DebugConsole.Log("[extracting config]:>" + infile + "[TO]" + outfile);
            yield return(new WaitForEndOfFrame());
        }


        //解包config user
        if (infile != outfile)
        {
            infile  = Application.streamingAssetsPath + "/" + "user.ini";
            outfile = AppPlatform.RuntimeAssetsPath + "user.ini";
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            if (AppPlatform.PlatformCurrent == Platform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(null);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            DebugConsole.Log("[extracting config]:>" + infile + "[TO]" + outfile);
            yield return(new WaitForEndOfFrame());
        }


        //检查是否有预装package需要解包
        bool needExtractPackage = true;

        if (AppPlatform.PlatformCurrent == Platform.Android)
        {
            var ver = AppPlatform.GetPackagePath() + Global.PackageVersionFileName;
            WWW www = new WWW(ver);
            yield return(www);

            if (www.error != null)
            {
                DebugConsole.Log("没有预装的Package");
                www.Dispose();
                needExtractPackage = false;
            }
        }
        else
        {
            var ver = AppPlatform.GetPackagePath() + Global.PackageVersionFileName;
            if (!File.Exists(ver))
            {
                DebugConsole.Log("没有预装的Package");
                needExtractPackage = false;
            }
        }

        if (needExtractPackage)
        {
            //清理package文件夹
            if (Directory.Exists(AppPlatform.GetRuntimePackagePath()))
            {
                Directory.Delete(AppPlatform.GetRuntimePackagePath(), true);
            }
            Directory.CreateDirectory(AppPlatform.GetRuntimePackagePath());

            //解包package的checklist
            infile  = AppPlatform.GetPackagePath() + Global.PackageManifestFileName;
            outfile = AppPlatform.GetRuntimePackagePath() + Global.PackageManifestFileName;
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            if (AppPlatform.PlatformCurrent == Platform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(null);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            DebugConsole.Log("[extracting checklist]:>" + infile + "[TO]" + outfile);
            yield return(new WaitForEndOfFrame());

            //解包package
            string[] files           = File.ReadAllLines(outfile);
            float    downloadedCount = 0f;
            for (int i = 0; i < files.Length; i++)
            {
                var      file      = files[i];
                string[] rKeyValue = file.Split('|');
                infile  = AppPlatform.GetPackagePath() + rKeyValue[0];
                outfile = AppPlatform.GetRuntimePackagePath() + rKeyValue[0];

                DebugConsole.Log("[extracting package]:>" + infile + "[TO]" + outfile);

                string rDirName = Path.GetDirectoryName(outfile);
                if (!Directory.Exists(rDirName))
                {
                    Directory.CreateDirectory(rDirName);
                }

                if (AppPlatform.PlatformCurrent == Platform.Android)
                {
                    WWW www = new WWW(infile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(outfile, www.bytes);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(outfile))
                    {
                        File.Delete(outfile);
                    }
                    File.Copy(infile, outfile, true);
                }
                yield return(new WaitForEndOfFrame());

                downloadedCount++;
                float p = (downloadedCount / (float)files.Length) * 100f;
                p = Mathf.Clamp(p, 0, 100);
                LoadingLayer.SetProgressbarValue((int)p);
            }
        }

        LoadingLayer.SetProgressbarTips("解包资源文件完成");
        yield return(new WaitForSeconds(0.1f));

        Global.TaskManager.StartTask(OnUpdatePackage());
    }
Esempio n. 8
0
    static IEnumerator OnUpdatePackage()
    {
        if (!Global.IsUpdateMode)
        {
            AssetsUpdateEnd();
            yield break;
        }

        LoadingLayer.SetProgressbarTips("开始更新资源");

        //比对服务器版本
        WWW www = new WWW(Global.ServerPackageVersionURL);

        yield return(www);

        if (www.error != null)
        {
            DebugConsole.Log("未在服务器上找到最新版本文件");
            www.Dispose();
            yield break;
        }
        var lastestVer = www.text;
        var curVer     = "";

        if (File.Exists(AppPlatform.GetRuntimePackagePath() + Global.PackageVersionFileName))
        {
            curVer = FileUtil.ReadFile(AppPlatform.GetRuntimePackagePath() + Global.PackageVersionFileName);
        }

        if (curVer == lastestVer)
        {
            DebugConsole.Log("当前package已是最新版本,无需更新");
            www.Dispose();
            yield break;
        }


        // 获取更新文件列表
        string listUrl = Global.PackageUpdateURL + lastestVer + "/" + AppPlatform.GetPackageName() + "/" + Global.PackageManifestFileName;

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

        if (www.error != null)
        {
            DebugConsole.Log("未在服务器上找到checklist");
            www.Dispose();
            yield break;
        }

        if (!Directory.Exists(AppPlatform.GetRuntimePackagePath()))
        {
            Directory.CreateDirectory(AppPlatform.GetRuntimePackagePath());
        }

        File.WriteAllBytes(AppPlatform.GetRuntimePackagePath() + Global.PackageManifestFileName, www.bytes);

        //按照更新列表增量更新文件
        string fileslist = www.text;

        string[] files           = fileslist.Split('\n');
        float    downloadedCount = 0f;

        for (int i = 0; i < files.Length; i++)
        {
            if (string.IsNullOrEmpty(files[i]))
            {
                continue;
            }
            string[] keyValue      = files[i].Split('|');
            string   fileName      = keyValue[0];
            string   localfilePath = (AppPlatform.GetRuntimePackagePath() + fileName).Trim();
            string   path          = Path.GetDirectoryName(localfilePath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //检查是否可以更新这个文件
            bool canUpdate = !File.Exists(localfilePath);
            if (!canUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = Util.MD5File(localfilePath);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfilePath);
                }
            }

            //可以更新这个文件
            if (canUpdate)
            {
                string fileUrl = Global.PackageUpdateURL + lastestVer + "/" + AppPlatform.GetPackageName() + "/" + fileName;
                Debug.Log(fileUrl);
                www = new WWW(fileUrl);
                yield return(www);

                if (www.error != null)
                {
                    Debug.Log(www.error + path);
                    yield break;
                }
                File.WriteAllBytes(localfilePath, www.bytes);

                downloadedCount++;
                float p = (downloadedCount / (float)files.Length) * 100f;
                p = Mathf.Clamp(p, 0, 100);
                LoadingLayer.SetProgressbarValue((int)p);
            }
        }

        www.Dispose();
        LoadingLayer.SetProgressbarTips("更新资源完成");
        yield return(new WaitForEndOfFrame());

        AssetsUpdateEnd();
    }