欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

unity實(shí)現(xiàn)場(chǎng)景切換進(jìn)度條顯示

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例為大家分享了unity實(shí)現(xiàn)場(chǎng)景切換進(jìn)度條顯示的具體代碼,供大家參考,具體內(nèi)容如下

一、UI。建立slider適當(dāng)更改即可;

二、新增loadScene腳本,用來進(jìn)行場(chǎng)景切換,將其綁定任意物體上面。博主以放置主相機(jī)為例。參數(shù)分別為進(jìn)度條(用來設(shè)置value值),顯示進(jìn)度文本text;

在設(shè)置中加入兩個(gè)場(chǎng)景:

三、腳本;

/// <summary>
/// 場(chǎng)景切換
/// 在unity 獲取當(dāng)前加載進(jìn)度progress中,其中最多到0.9.只有等到加載到第二個(gè)場(chǎng)景才會(huì)到1
/// 所有在加載進(jìn)度條時(shí)如果progress的值近似0.9,則直接將進(jìn)度參數(shù)設(shè)置為1,實(shí)現(xiàn)進(jìn)度到100%
/// 并且progress的值是在一幀加載一些資源,所以其值不會(huì)是連續(xù)的,因此設(shè)置兩個(gè)參數(shù)來記錄當(dāng)前
/// 進(jìn)度和頁(yè)面顯示的進(jìn)度,進(jìn)行++。
/// </summary>
public class loadScene : MonoBehaviour
{
 AsyncOperation async;
 public Slider slider;
 public Text text;//百分制顯示進(jìn)度加載情況

 void Start()
 {
 //開啟協(xié)程
 StartCoroutine("loginMy");
 }
 
 void Update()
 {
 
 }
 IEnumerator loginMy()
 {
 int displayProgress = 0;
 int toProgress = 0;
 AsyncOperation op = SceneManager.LoadSceneAsync(1);
 op.allowSceneActivation = false;
 while (op.progress < 0.9f) //此處如果是 <= 0.9f 則會(huì)出現(xiàn)死循環(huán)所以必須小0.9
 {
  toProgress = (int)op.progress * 100;
  while (displayProgress < toProgress)
  {
  ++displayProgress;
  SetLoadingPercentage(displayProgress);
  yield return new WaitForEndOfFrame();//ui渲染完成之后
  }
 }
 toProgress = 100;
 while (displayProgress < toProgress)
 {
  ++displayProgress;
  SetLoadingPercentage(displayProgress);
  yield return new WaitForEndOfFrame();
 }
 op.allowSceneActivation = true;

 }

 private void SetLoadingPercentage(int displayProgress)
 {
 slider.value = displayProgress;
 text.text = displayProgress.ToString() + "%";
 }
}

四、運(yùn)行:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C#WinFrom導(dǎo)出Excel過程解析

欄    目:C#教程

下一篇:C#深度優(yōu)先遍歷實(shí)現(xiàn)全排列

本文標(biāo)題:unity實(shí)現(xiàn)場(chǎng)景切換進(jìn)度條顯示

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4610.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有