标签:com rtc span while src 运行 percent turn yield
在设置中加入两个场景:
1 /// <summary> 2 /// 场景切换 3 /// 在unity 获取当前加载进度progress中,其中最多到0.9.只有等到加载到第二个场景才会到1 4 /// 所有在加载进度条时如果progress的值近似0.9,则直接将进度参数设置为1,实现进度到100% 5 /// 并且progress的值是在一帧加载一些资源,所以其值不会是连续的,因此设置两个参数来记录当前 6 /// 进度和页面显示的进度,进行++。 7 /// </summary> 8 public class loadScene : MonoBehaviour 9 { 10 AsyncOperation async; 11 public Slider slider; 12 public Text text;//百分制显示进度加载情况 13 14 void Start() 15 { 16 //开启协程 17 StartCoroutine("loginMy"); 18 } 19 20 void Update() 21 { 22 23 } 24 IEnumerator loginMy() 25 { 26 int displayProgress = 0; 27 int toProgress = 0; 28 AsyncOperation op = SceneManager.LoadSceneAsync(1); 29 op.allowSceneActivation = false; 30 while (op.progress < 0.9f) //此处如果是 <= 0.9f 则会出现死循环所以必须小0.9 31 { 32 toProgress = (int)op.progress * 100; 33 while (displayProgress < toProgress) 34 { 35 ++displayProgress; 36 SetLoadingPercentage(displayProgress); 37 yield return new WaitForEndOfFrame();//ui渲染完成之后 38 } 39 } 40 toProgress = 100; 41 while (displayProgress < toProgress) 42 { 43 ++displayProgress; 44 SetLoadingPercentage(displayProgress); 45 yield return new WaitForEndOfFrame(); 46 } 47 op.allowSceneActivation = true; 48 49 } 50 51 private void SetLoadingPercentage(int displayProgress) 52 { 53 slider.value = displayProgress; 54 text.text = displayProgress.ToString() + "%"; 55 } 56 }
标签:com rtc span while src 运行 percent turn yield
原文地址:https://www.cnblogs.com/unknown6248/p/11701377.html