本帖最后由 u75379946 于 2016-4-7 09:45 編輯 今天Achor為大家?guī)淼氖沁M度條制作,大家都知道如果加載一些資源較多的時候,如果采用同步處理將會產生卡頓,所以需要應道異步處理用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 定期為大家分享游戲開發(fā)經驗和行業(yè)最新資訊還有各種答疑,需要的朋友可以關注一下我們相互學習哦!
最終效果如下:u3d 下載進度;u3d 圓形進度條;
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請
點擊舉報。