本帖最后由 u75379946 于 2016-4-7 09:45 编辑 今天Achor为大家带来的是进度条制作,大家都知道如果加载一些资源较多的时候,如果采用同步处理将会产生卡顿,所以需要应道异步处理用Loading过渡,下面是Achor做好的UI和Loading,方便给大家讲解。 ![]() 实现功能:点击开始游戏以后UI界面进入Loading界面,Loading结束以后自动进入游戏场景。 在这之前先在Build Settings中Add要使用的场景 在场景A中添加StartGame方法: Application.LoadLevel(1);//同步加载Loading界面(因为Loading界面资源较少速度快所以此处用同步方法) 在Loading场景中加入进度条图片:分为上下两层,上层负责显示进度 ![]() 将上层的进度条Image组件中的Image Ttpe改为Filled ![]() 接下来再Loading场景Cam中添加以下代码(通过改变Fill Amount显示Loading效果): 本帖隐藏的内容public class Loading : MonoBehaviour {AsyncOperation asyncOperation; //声明一个异步变量 public GameObject progress; //声明进度条对象 public GameObject Text; //声明进度条上的显示文本 //对以上变量进行初始化 void Start() { progress.SetActive(true); progress = GameObject.FindWithTag("Fader"); Text = GameObject.FindWithTag("Text"); Text.GetComponent<Text>().text = "0"; progress.GetComponent<Image>().fillAmount = 0f; DontDestroyOnLoad(gameObject); StartCoroutine(loadScene()); //开启异步任务,进入loadScene方法 } void Update() { Text.GetComponent<Text>().text = (float)asyncOperation.progress*100+10+"%"; //文本更新异步进度 progress.GetComponent<Image>().fillAmount = (float)asyncOperation.progress+.1f;//进度条更新异步进度 } IEnumerator loadScene() { yield return asyncOperation = Application.LoadLevelAsync(2);//读取完毕自动进入下一个场景 } } 我的公众微信:黑客画家 以及我的 个人博客 :anchorart9.com 定期为大家分享游戏开发经验和行业最新资讯还有各种答疑,需要的朋友可以关注一下我们相互学习哦! 最终效果如下: ![]() u3d 下载进度;u3d 圆形进度条; |
|