返回介绍

Application.LoadLevelAsync 异步加载关卡

发布于 2019-12-18 15:37:19 字数 3332 浏览 1120 评论 0 收藏 0

JavaScript => static function LoadLevelAsync(index: int): AsyncOperation;
JavaScript => static function LoadLevelAsync(levelName: string): AsyncOperation;
C# => static AsyncOperation LoadLevelAsync(int index);
C# => static AsyncOperation LoadLevelAsync(string levelName);

Description 描述

Loads the level asynchronously in the background.

在后台异步加载关卡,也就是说,在后台非同步加载新的场景。

Unity will completely load all assets and all objects in the scene in a background loading thread. This allows you to load new levels while still playing the current one, show a progress bar or create a completely streaming world where you constantly load and unload different parts of the world based on the player position, without any hiccups in game play.

Unity将在后台线程完整加载场景所有资源和物体。这允许你加载一个新的关卡,同时当前的关卡仍在播运行,显示进度条或者创建一个完整的流世界,在那里你不断的加载和卸载基于程序位置不同的部分,在游戏中不会有任何的中断。

isDone variable from the resulting AsyncOperation can be used to query if the level load has completed. The result of a LoadLevelAsync can also be used to yield in a coroutine.

isDone变量来自AsyncOperation异步操作的结果,可以用于如果关卡加载完成的查询。

When building a player Unity automatically optimizes assets in such a way that LoadLevelAsync will load them from disk linearly to avoid seek times. Note that background loading performance in the Unity Editor is much lower than in the web player or standalone build. In the Editor you might also get more loading hiccups than in the player.

当编译一个游戏Unity自动优化资源,LoadLevelAsync将从硬盘以线性加载它们避免从磁盘寻道时间。

注意,背景加载优先级在Unity编辑器远远低于网络播放器或独立版编译。在编辑器你或许也得到比播放器更多的加载中断。

This function requires Unity Pro.

这个函数需运行在Unity专业版。

JavaScript:

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

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    IEnumerator Start() {
        AsyncOperation async = Application.LoadLevelAsync("MyBigLevel");
        yield return async;
        Debug.Log("Loading complete");
    }
}

See Also: AsyncOperation, Application.backgroundLoadingPriority, Application.LoadLevel, Application.LoadLevelAdditive, Application.LoadLevelAdditiveAsync.

Application

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文