可通过多种方法来创建新场景:
Unity 从场景模板创建每个新场景。有关创建和管理场景模板的信息,请参阅场景模板。
使用 New Scene 对话框在项目中从特定场景模板创建新场景。您还可以使用 New Scene 对话框来查找和管理场景模板。有关详细信息,请参阅 New Scene 对话框。
默认情况下,从菜单 (File > New Scene) 或使用快捷方式 (Ctrl/Cmd + n) 创建新场景时,将打开 New Scene 对话。
要创建新场景:
注意: |
---|
附加方式加载意味着 Unity 会在已打开的任何其他场景之外加载场景。有关更多信息,请参阅多场景编辑。 |
如果模板没有任何可克隆的依赖项,Unity 会在内存中加载新场景,但不保存。
如果模板有可克隆的依赖项,Unity 会提示您在项目中选择一个位置保存场景。当您保存场景时,Unity 会在相同位置创建一个与新场景同名的文件夹。然后将可克隆的依赖项克隆到新文件夹中,并更新新场景以使用克隆的资源而不是模板场景使用的原始资源。
使用菜单 (Assets > Create > Scene) 创建新场景,无需打开 New Scene 对话框。
当您从菜单创建新场景时,Unity 会自动复制项目的 Basic 模板,并将新场景添加到 Project 窗口中当前打开的文件夹中。
使用 Project 窗口中的上下文菜单创建新场景,无需打开 New Scene 对话框。
当您从菜单创建新场景时,Unity 会自动复制项目的 Basic 模板,并将新场景添加到选定的文件夹中。
要从 C# 脚本使用特定场景模板创建新场景,请使用 Instantiate 方法。
Tuple<Scene, SceneAsset> SceneTemplate.Instantiate(SceneTemplateAsset sceneTemplate, bool loadAdditively, string newSceneOutputPath = null);
该 Instantiate
方法从场景模板中实例化一个新场景。它返回新创建的 Scene
句柄,及其匹配的 SceneAsset
。您可以以附加方式创建此场景。如果场景包含需要克隆的资源,您必须为 Unity 提供将场景保存到磁盘的路径。
当您从模板创建新场景时,无论是从脚本还是使用 New Scene 对话框,Unity 都会触发一个事件。Unity 在模板实例化之后触发这个事件,然后还会触发 EditorSceneManager.newSceneCreated
或 EditorSceneManager.sceneOpened
事件。
public class SceneTemplate
{
public delegate void NewTemplateInstantiated(SceneTemplateAsset sceneTemplateAsset, Scene scene, SceneAsset sceneAsset, bool additiveLoad);
public static event NewTemplateInstantiated newSceneTemplateInstantiated;
}
要打开场景,请执行以下操作之一:
如果当前场景包含未保存的更改,Unity 会询问是要保存该场景还是丢弃更改。
您可以同时打开多个场景进行编辑。有关详细信息,请参阅多场景编辑。
要保存当前正在处理的场景,请从菜单中选择 File > Save Scene,或按 Ctrl + S (Windows) 或 Cmd + S (macOS)。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.