unity场景假处理方式_Unity中的场景处理

unity场景假处理方式

To understand this we first have to realise what scenes are. Scenes refer to the objects which contain a particular scenario of the game.

要了解这一点,我们首先必须了解什么是场景。 场景是指包含游戏特定场景的对象。

Consider you have a game that has a world consisting of 2 parts: a city and a forest. Here we can say that this world can be defined in 2 scenes (though for larger games this may not be the case), one for the city and one for the forest.

假设您有一个游戏,游戏的世界由两部分组成:城市和森林。 在这里,我们可以说这个世界可以定义为2个场景(尽管对于大型游戏可能并非如此),一个场景用于城市,一个场景用于森林。

Quoting from Unity Manuals:

从Unity手册中引用:

Scenes contain the objects of your game. They can be used to create a main menu, individual levels, and anything else. Think of each unique Scene file as a unique level. In each Scene, you will place your environments, obstacles, and decorations, essentially designing and building your game in pieces.
场景包含游戏的对象。 它们可用于创建主菜单,各个级别以及其他任何内容。 将每个唯一的场景文件视为一个唯一的级别。 在每个场景中,您都将放置环境,障碍物和装饰品,从根本上设计和构建游戏

Scince the few latest updates, Unity has started using a new library to access Scenes and traversing between them. This library is called the SceneManagement.

除少数最新更新外,Unity已开始使用新的库来访问场景并在它们之间进行遍历。 该库称为SceneManagement。

To use this library we have to first include it. We do this by writing

要使用此库,我们必须首先包含它。 我们通过写来做到这一点

using UnityEngine.SceneManagement

at the start of the script.

在脚本的开头。

In this library the class that you will encounter and use the most will be the SceneManager.

在此库中,您将遇到和使用最多的类是SceneManager。

在构建中包括场景 (Including Scenes in Build)

To be able to access a scene via the SceneManager class we first we need to add the scene to the Build Settings

为了能够通过SceneManager类访问场景,我们首先需要将场景添加到“构建设置”中

To do this save the scene by CTRL+S. It will be saved in the Assets folder.

为此,通过CTRL + S保存场景。 它将保存在Assets文件夹中。

Now go to File in the menu bar and select Build Settings.

现在转到菜单栏中的“文件”,然后选择“ 构建设置”

In the window that opens up, drag and drop the scene icon from the Project tab into the space under Scenes In Build.

在打开的窗口中,将场景图标从“项目”选项卡拖放到“ 构建中的场景”下的空间中。

We can add multiple scenes in a similar way and reorder them. The order in which the scenes are, decides their scene number and the scene which will load first when the game begins.

我们可以以类似的方式添加多个场景并对其重新排序。 场景的顺序决定了它们的场景编号以及在游戏开始时将首先加载的场景。

现场经理 (The Scene Manager)

The Scene Manager class has the following:

Scene Manager类具有以下内容:

描述: (Description:)

Scene management at run-time.

运行时的场景管理。

静态属性: (Static Properties:)
sceneCountThe total number of currently loaded Scenes
sceneCountInBuildSettings Number of Scenes in Build Settings.
sceneCount 当前加载的场景总数
sceneCountInBuildSettings 构建设置中的场景数。
静态方法: (Static Methods:)
CreateSceneCreate an empty new Scene at runtime with the given name.
GetActiveSceneGets the currently active Scene.
GetSceneAt Get the Scene at index in the SceneManager's list of loaded Scenes.
GetSceneByBuildIndex Get a Scene struct from a build index.
GetSceneByNameSearches through the Scenes loaded for a Scene with the given name.
GetSceneByPathSearches all Scenes loaded for a Scene that has the given asset path.
LoadSceneLoads the Scene by its name or index in Build Settings
LoadSceneAsyncLoads the Scene asynchronously in the background.
MergeScenesThis will merge the source Scene into the destinationScene.
MoveGameObjectToScene Move a GameObject from its current Scene to a new Scene.
SetActiveScene Set the Scene to be active.
UnloadSceneAsyncDestroys all GameObjects associated with the given Scene and removes the Scene from the SceneManager.
CreateScene 在运行时使用给定名称创建一个空的新场景。
GetActiveScene 获取当前活动的场景。
GetSceneAt 在SceneManager的已加载场景列表中的索引处获取场景。
GetSceneByBuildIndex 从构建索引获取一个Scene结构。
GetSceneByName 在加载的场景中搜索具有给定名称的场景。
GetSceneByPath 在所有加载的场景中搜索具有给定资产路径的场景。
加载场景 通过其名称或“构建设置”中的索引加载场景
LoadSceneAsync 在后台异步加载Scene。
合并场景 这会将源场景合并到destinationScene中。
MoveGameObjectToScene 将GameObject从其当前场景移动到新场景。
SetActiveScene 将场景设置为活动状态。
UnloadSceneAsync 销毁与给定场景关联的所有GameObject,并将场景从SceneManager中删除。
大事记: (Events:)
activeSceneChangedSubscribe to this event to get notified when the active Scene has changed.
sceneLoadedAdd a delegate to this to get notifications when a Scene has loaded.
sceneUnloadedAdd a delegate to this to get notifications when a Scene has unloaded.
activeSceneChanged 订阅此事件以在活动场景已更改时得到通知。
SceneLoaded 向其添加委托以在加载场景时获得通知。
sceneUnloaded 向场景添加委托以获得场景卸载后的通知。

Courtesy: Unity Scene Manager

礼貌: Unity Scene Manager

翻译自: https://www.studytonight.com/game-development-in-2D/scene-handling

unity场景假处理方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值