1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Unity制作圆环进度条加载场景资源

Unity制作圆环进度条加载场景资源

时间:2019-04-12 11:29:22

相关推荐

Unity制作圆环进度条加载场景资源

第一步:场景内UI圆环的搭建

新建一张Panel作为背景图,在Panel下新建一张Image命名为RoundImage作为外圆环,在外圆环下新建一张image命名为RoundLoading作为内圆环,用来显示进度的,新建两个Text文本,一个作为文字说明,一个作为进度值显示用。调整每个图的位置大小。大概如下图:

第二步:关键的地方:Image的设置

外圆环和内圆环必须是大小一致、有颜色差的图片。

RoundImage默认设置就好了,需要注意的是将RoundLoading属性设置为如下图:

第三步:代码实现进度条的加载

[SerializeField] private Image LoadingImage;//[SerializeField] private Text LoadingText;private bool isLoading=false;private AsyncOperation asyn;private void Start(){StartCoroutine(LoadScene());}void Update(){if (isLoading&&LoadingImage!=null&&LoadingText!=null&&LoadingImage.fillAmount<1){LoadingImage.fillAmount += Time.deltaTime * 0.05f * (asyn.isDone ? 10 : 1);LoadingText.text = string.Format("{0:P0}", LoadingImage.fillAmount);//对数值进行百分比格式化}else if (LoadingImage.fillAmount>=1){asyn.allowSceneActivation = true;print("加载完成");}}IEnumerator LoadScene(){asyn = SceneManager.LoadSceneAsync("New");asyn.allowSceneActivation = false;yield return asyn;}private void OnGUI(){if (GUI.Button(new Rect (200,200,100,100),"加载环形进度条")){isLoading = true;}}

实现的效果

初始:

加载:

加载完成跳转场景:

这里是为了方便测试用,所以使用了GUI的按钮形式开启加载进度条,加载一个简单的场景,实际使用当中可以用来预加载资源用,写一个状态机轮询加载资源,将代码中的三目运算符改为到达相应状态时将加载速度加快,则进度条加快完成加载,完成需求。

额外的知识点:

Image的显示类型:图片的排列类型 Simple (普通模式),Sliced (九宫格),Tiled (平铺),Filed (填充)

此处仅相似做一下Filed的笔记。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。