Unity3d 2种重要方法的使用

来源:互联网 发布:大数据可视化技术综述 编辑:程序博客网 时间:2024/05/22 01:49

Unity3d 2种重要方法的使用

GetStreamProgressForLevel()

  in the webplayer, returns the progress of the actual level (from theofficial documentation). With "progress" it's intended the loading progress...Since the game will be stored on a server (generally), a certain time period is required to send the data of a particular scene to the client. The documentation reports a clear example:

Code:

function Update() {    if(Application.GetStreamProgressForLevel(1) == 1) {        guiText.text = "Level at index 1 has been fully streamed!";    } else {        percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;        guiText.text = percentageLoaded.ToString();    }}

Easy, uh? With this, you can know what percentage of the scene has been "loaded". That is, what percentage of the level has been "streamed" from the server to the client. And you can fill you loading bar accordingly, for the sake of your question. Even with the free version of Unity.


LoadLevelAsync() 

(THAT REQUIRES UNITY PRO), instead, loads the level asynchronously in the background (always from the documentation). See this example:

Code:

function Start () {    // Load the level named "MyBigLevel".    var async : AsyncOperation = Application.LoadLevelAsync ("MyBigLevel");    yield async;    Debug.Log ("Loading complete");}

A message will be printed on the console as soon as "MyBigLevel" has been loaded (or, as we said before, "streamed"). It is indicated for performance reasons, that's why it (wisely) requires Unity Pro.

原创粉丝点击