1 using UnityEngine; 2 using System.Collections; 3 4 /// <summary> 5 /// 加载场景 6 /// </summary> 7 public class LoadSence : MonoBehaviour { 8 9 10 private IEnumerator StartLoading(string SenceName) 11 { 12 int displayProgress = 0; 13 int toProgress = 0; 14 AsyncOperation op = Application.LoadLevelAsync(SenceName); 15 op.allowSceneActivation = false; 16 while (op.progress < 0.2f) 17 { 18 toProgress = (int)op.progress * 100; 19 while (displayProgress < toProgress) 20 { 21 ++displayProgress; 22 SetLoadingPercentage(displayProgress); 23 yield return new WaitForEndOfFrame(); 24 } 25 } 26 27 toProgress = 100; 28 while (displayProgress < toProgress) 29 { 30 ++displayProgress; 31 SetLoadingPercentage(displayProgress); 32 yield return new WaitForEndOfFrame(); 33 } 34 yield return new WaitForSeconds(1.0f); 35 op.allowSceneActivation = true; 36 } 37 38 39 40 // Use this for initialization 41 void Start () { 42 43 Time.timeScale = 1.0f; 44 45 switch (GameManager.CurrentSenceIndex) 46 { 47 48 case 1: 49 50 GameManager.m_NextSence = "linjiankongdi"; 51 52 break; 53 case 2: 54 GameManager.m_NextSence = "linjiankongdi2"; 55 56 break; 57 case 3: 58 59 GameManager.m_NextSence = "huangyejiaotang"; 60 61 break; 62 case 4: 63 64 GameManager.m_NextSence = "huangyejiaotang2"; 65 66 break; 67 68 default: 69 break; 70 } 71 72 StartCoroutine(StartLoading(GameManager.m_NextSence)); 73 //StartCoroutine(StartLoading("SenceOne")); 74 75 } 76 77 public UISlider m_UISlider; 78 79 void SetLoadingPercentage(int progress) 80 { 81 m_UISlider.value = (float)progress / 100.0f; 82 } 83 84 85 86 87 // Update is called once per frame 88 void Update () { 89 90 } 91 }
时间: 2024-11-05 02:18:07