美文网首页
制作一个流畅的进度条

制作一个流畅的进度条

作者: 厚颜无齿 | 来源:发表于2019-08-17 11:37 被阅读0次

    using System;

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    using UnityEngine.UI;

    using UnityEngine.SceneManagement;

    public class LoadGame :MonoBehaviour {

        public Slider processView;

      // Use this for initialization

      void Start () {

            LoadGameMethod();

    }

      // Update is called once per frame

      void Update () {

    }

        public void LoadGameMethod()

    {

            StartCoroutine(StartLoading_4(2));

    }

        private IEnumerator StartLoading_4(int scene)

    {

            int displayProgress =0;

            int toProgress = 0;

            AsyncOperation op =SceneManager.LoadSceneAsync(scene);

            op.allowSceneActivation =false;

            while (op.progress <0.9f)

    {

                toProgress =(int)op.progress *100;

                while (displayProgress

    {

                    ++displayProgress;

                    SetLoadingPercentage(displayProgress);

                    yield return new WaitForEndOfFrame();

    }

    }

            toProgress =100;

            while (displayProgress

    {

                ++displayProgress;

                SetLoadingPercentage(displayProgress);

                yield return new WaitForEndOfFrame();

    }

            op.allowSceneActivation =true;

    }

        private void SetLoadingPercentage(float v)

    {

            processView.value =v /100;

    }

    }

    相关文章

      网友评论

          本文标题:制作一个流畅的进度条

          本文链接:https://www.haomeiwen.com/subject/gqvhsctx.html