GetStreamPrograssForLevel

制作Unity3d的prograss bar:

Unity3d在网页下有2种prograss bar:,初次打开unity时的plugin bar(少于1秒,可以简单的custmize 背景颜色和bar的样式)和之后自己可以加入的换场景bar(自己可以选择任意样式的bar),burgzerg网站有视频实例

以下例子是开始的时候loading unity plugin和第一个场景(空场景带一个button),如果build时选的streamed,load完第一个空场景,会继续在后面loading 队列里的其他level。如果没有选择streamed则直接loading完第一个场景后等待用户click button才开始load下一个场景。

1:建一个MainMenu.cs

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class MainMenu : MonoBehaviour {
 5     private float _percentageLoaded = 0;
 6     private string _levelToLoad  = "";
 7     private string _firstLevel = "MyScene";
 8     
 9     // Use this for initialization
10     void Start () {
11         
12     }
13     
14     // Update is called once per frame
15     void Update()
16     {
17         if (_levelToLoad == ""){
18             return;
19         }
20         if (Application.GetStreamProgressForLevel(_levelToLoad) == 1)
21         {
22             Debug.Log("Level Ready");
23             if (Application.CanStreamedLevelBeLoaded(_levelToLoad))
24             {
25                 Debug.Log("Level can be streamed, so lets load it up");
26                 Application.LoadLevel(_levelToLoad);
27             }
28         }
29         else
30         {
31             _percentageLoaded = Application.GetStreamProgressForLevel(_levelToLoad);
32         }
33 
34         
35     }
36     void OnGUI()
37     {
38         if (GUI.Button(new Rect(10, 40, 110, 25), "Load  Scene"))
39         {
40             _levelToLoad = _firstLevel;
41         }
42         if (_levelToLoad == "")
43         {
44             return;
45         }
46         GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height - 45, 100, 25), (_percentageLoaded * 100) + "%");
47         GUI.Box(new Rect(0, Screen.height - 20, Screen.width * _percentageLoaded, 15), "");
48     }
49 }

 

2:attach到camera下

posted @ 2013-01-12 03:13  若愚Shawn  阅读(330)  评论(0编辑  收藏  举报