At any time while you are creating your game, you might want to see how it looks when you build and run it outside of the editor as a standalone or web player. This section will explain how to access the Build Settings and how to create different builds of your games.
在你创建游戏的时候,你可能想看看它在编辑器之外独立运行或在网页中播放的情况。本节将讲解如何使用开发(发布)设置以及如何创建游戏的不同版本。
is the menu item to access the Build Settings window. It pops up an editable list of the scenes that will be included when you build your game.
菜单File->Build Settings...用来访问编译设置窗口,它弹出一个包括你建立的游戏场景的列表。
The Build Settings window 发布设置窗口
The first time you view this window in a project, it will appear blank. If you build your game while this list is blank, only the currently open scene will be included in the build. If you want to quickly build a test player with only one scene file, just build a player with a blank scene list.
当你第一次在一个项目中查看此窗口,它是空白的。当这个列表空白时,如果你建立游戏,只有当前打开的场景将包含在列表。如果你想快速编译一个只有一个场景文件的测试程序,只需编译一个空白场景列表的播放器。
It is easy to add scene files to the list for multi-scene builds. There are two ways to add them. The first way is to click the Project View to the list.
button. You will see the currently open scene appear in the list. The second way to add scene files is to drag them from the为多场景作品添加场景文件到列表是很简单的。有两种方法来添加它们。第一种方法是点击Add Current按钮,你会看到当前打开的场景出现在列表中。第二种添加方法是从项目视图中将它们拖到列表中。
At this point, notice that each of your scenes has a different index value. Scene 0 is the first scene that will be loaded when you build the game. When you want to load a new scene, use Application.LoadLevel() inside your scripts.
注意这一点,你的每个场景都有不同的索引值。Scene 0是当你创建游戏时第一个被加载的场景。当你想要载入一个新的场景,在脚本中使用Application.LoadLevel()函数。
If you've added more than one scene file and want to rearrange them, simply click and drag the scenes on the list above or below others until you have them in the desired order.
如果你已经添加了多个场景文件,并希望重新排列它们,只需在列表中拖动它到其它场景上面或下面,直到你需要的顺序。
If you want to remove a scene from the list, click to highlight the scene and press
. The scene will disappear from the list and will not be included in the build.如果你想从列表中删除场景,单击选中,然后按删除键。该场景会从列表中消失,不会包含在你的作品中。
When you are ready to publish your build, select a Platform and make sure that the Unity logo is next to the platform; if its not then click in the button to let Unity know which platform you want to build for. Finally press the button. You will be able to select a name and location for the game using a standard Save dialog. When you click , Unity builds your game pronto. It's that simple. If you are unsure where to save your built game to, consider saving it into the projects root folder. You cannot save the build into the Assets folder.
当你准备好发布你的作品,选择一个平台(确保出现Unity标识),如果不是你想要的平台,那么点击Switch Platform按钮,选择你要的平台,最后按下Build按钮。使用标准保存对话框,你可以选择游戏的名称和位置,点击保存,Unity将很快建立你的游戏作品,就这么简单。如果你不确定在哪里保存你的游戏,可以考虑保存到项目的根目录中。不能保存到资源文件夹中。
Enabling the Debug build checkbox on any standalone player will enable Profiler functionality. Additionally, the player will be built with debug symbols, so you can use 3rd party profiling or debugging tools.
在任何独立游戏上使用Debug build调试复选框将启用Profiler函数功能,同时,游戏将带有调试标记,所以你可以使用第三方分析或调试工具。
Web Player Streaming 网络流媒体播放器
Streaming Web Players allow your Web Player games to begin playing as soon as Scene 0 is finished loading. If you have a game with 10 levels, it doesn't make much sense to force the player to wait and download all assets for levels 2-10 before they can start playing level 1. When you publish a Streaming Web Player, the assets that must be downloaded will be sequenced in the order of the Scene file they appear in. As soon as all assets contained in Scene 0 are finished downloading, the Web Player will begin playing.
流媒体播放器使你的网页游戏完成加载就立即开始播放场景0。如果你的游戏有10个关卡,并没有多大意义,这将迫使玩家要等待下载完2-10所有关卡,才可以开始玩第一关。当你发布了一个网页游戏,要让下载完的必需资源尽快按顺序出现在场景文件中,场景0所包含的资源一经加载完成,则游戏开始。
Put simply, Streaming Web Players will get players playing your game faster than ever.
The only thing you need to worry about is checking to make sure that the next level you want to load is finished streaming before you load it.
简而言之,流媒体播放器将让玩家玩你的游戏比以前更快。你唯一需要担心的,是要检查确保下一关在加载之前已经完成数据流。
Normally, in a non-streamed player, you use the following code to load a level:
游戏中,可以使用下面的代码来加载一个关卡:
Application.LoadLevel("levelName");
In a Streaming Web Player, you must first check that the level is finished streaming. This is done through the CanStreamedLevelBeLoaded() function. This is how it works:
在流播放器的网页游戏中,你必须先检查已完成数据流的关卡,通过CanStreamedLevelBeLoaded()函数来完成,它是这样工作的:
var levelToLoad = 1; function LoadNewLevel () { if (Application.CanStreamedLevelBeLoaded (levelToLoad)) { Application.LoadLevel (levelToLoad); } }
If you would like to display the level streaming progress to the player, for a loading bar or other representation, you can read the progress by accessing GetStreamProgressForLevel().
如果你想在游戏(播放器)中显示关卡数据流的进展情况,比如做一个进度条或其他表现形式,你可以进一步阅读GetStreamProgressForLevel ( )函数部分。
Offline webplayer deployment 离线部署网络播放器
If the Offline Deployment option is enabled for a webplayer then the UnityObject.js file (used to interface the player with the host page) will be placed alongside the player during the build. This enables the player to work with the local script file even when there is no network connection; normally, UnityObject.js is downloaded from Unity's webserver so as to make use of the latest version.
如果一个网络播放器离线部署选项被开启,UnityObject.js文件,(使用带有主页的播放器)播放器编译时被放置在一起。这个启用,播放器带有本地脚本文件正常工作,即使没有网络连接;通常UnityObject.js从Unity的服务器下载,因此,确保最新版本。
Building standalone players 创建独立游戏
With Unity you can build standalone applications for Windows and Mac (Intel, PowerPC or Universal, which runs on both architectures). It's simply a matter of choosing the build target in the build settings dialog, and hitting the 'Build' button. When building standalone players, the resulting files will vary depending on the build target. On Windows an executable file (.exe) will be built, along with a Data folder which contains all the resources for your application. On Mac an app bundle will be built, containing the file needed to run the application, as well as the resources.
使用Unity你可以创建可用于Windows和Mac系统(Intel, PowerPC or Universal,在这两种架构上运行)的独立应用程序,只需在创建设置对话框中选择目标,并按下了“Build”按钮。当创建独立游戏时,产生的文件将因不同的目标而决定。在Windows系统中将创建可执行文件(.exe),以及一个数据文件夹,其中包含所有应用程序的资源。在Mac系统中将创建一个应用程序包,包含程序运行所需要的文件及资源。(Intel、PowerPc、Universal在这里是指Mac系统使用的处理器。Intel英特尔不用说了,地球人都知道;PowerPc是由IBM、苹果、摩托罗拉联合开发的处理器;Universal则是通用处理器)
Distributing your standalone on Mac is just to provide the app bundle (everything is packed in there). On Windows you need to provide both the .exe file and the Data folder for others to run it. Think of it like this: Other people must have the same files on their computer, as the resulting files that Unity builds for you, in order to run your game.
在Mac系统中发布你的独立游戏,只不过是提供应用程序包(一切都封装在其中)。在Windows上则需要同时提供.exe文件和数据文件夹从而让别人来运行。想想这种情况:其他人为了运行你的游戏,必须在他们的电脑中有相同的Unity为你创建的文件。
Inside the build process 内部生成过程
The building process will place a blank copy of the built game application wherever you specify. Then it will work through the scene list in the build settings, open them in the editor one at a time, optimize them, and integrate them into the application package. It will also calculate all the assets that are required by the included scenes and store that data in a separate file within the application package.
在创建过程中将会把一个游戏程序的空白副本放到你指定的地方。然后,将通过使用发布设置中的场景列表,在编辑器中依次打开它们,对其进行优化,整合到程序包中。它还将计算包括场景在内的所有资源数据,并存储到程序包里一个单独的文件中。
- Any GameObject in a scene that is tagged with 'EditorOnly' will be not be included in the published build. This is useful for debugging scripts that don't need to be included in the final game.
任何一个标有'EditorOnly'标签的游戏对象将不包含在发布的作品中,这对于调试那些不需要包含在最终游戏里的脚本是非常有用的。 - When a new level loads, all the objects in the previous level are destroyed. To prevent this, use DontDestroyOnLoad() on any objects you don't want destroyed. This is most commonly used for keeping music playing while loading a level, or for game controller scripts which keep game state and progress.
当加载一个新的关卡时,所有上一关的对象将被销毁。为了防止这种情况,在你不想破坏的对象上使用DontDestroyOnLoad( )函数,这是最常用的方式,可以将它用于加载一个关卡时保持音乐播放,或用于保存游戏状态和进度的控制脚本。 - After the loading of a new level is finished, the message: OnLevelWasLoaded() will be sent to all active game objects.
- For more information on how to best create a game with multiple scenes, for instance a main menu, a high-score screen, and actual game levels, see the Scripting Tutorial.pdf
何以最佳方式创建一个多场景游戏,例如一个主菜单,一个记分屏,和当前关卡显示,请参阅Scripting Tutorial.pdf
Inside the iOS build process iOS内部编译过程
The iPhone/iPad application build process is a two step process:
iPhone/iPad应用程序编译过程分两步:
- XCode project is generated with all the required libraries, precompiled .NET code and serialized assets.
XCode项目生产带有所有需要的库,预编译.NET代码并序列化资源。 - XCode project is built and deployed on the actual device.
XCode项目构建并在实际的设备上部署。
When "Build" is hit on "Build settings" dialog only the first step is accomplished. Hitting "Build and Run" performs both steps. If in the project save dialog the user selects an already existing folder an alert is displayed. Currently there are two XCode project generation modes to select:
当在Build settings对话框点Build,只是完成了第一步,点"Build and Run",执行这两个步骤。如果在项目中对话框,用户选择已经一个存在的文件夹,将显示一个警告信息。目前,有两个XCode项目生成模式选择:
- replace - all the files from target folder are removed and the new content is generated
替换 - 从目标文件夹所有文件被删除并生成新的内容。 - append - the "Data", "Libraries" and project root folder are cleaned and filled with newly generated content. The XCode project file is updated according to the latest Unity project changes. XCode project "Classes" subfolder could be considered as safe place to place custom native code, but making regular backups is recommended. Append mode is supported only for the existing XCode projects generated with the same Unity iOS version.
追加 - Data,Libraries和项目根文件夹被清空,并填充新生成的内容。XCode项目文件根据最新的Unity项目变更进行更新。XCode项目Classes子文件夹被视为安全的地方,可放置自定义的本机代码,但建议定期备份。追加模式仅支持现有的Xcode项目,带有有相同的Unity iOS版本生成。
If Cmd+B is hit then the automatic build and run process is invoked and the latest used folder is assumed as the build target. In this case append mode is assumed as default.
如果点Cmd+B,那么自动build and run过程被调用,最近使用的文件夹被假定为编译目标。在这种情况下,追加模式假定为默认值。
The Android application build process is performed in two steps:
Android应用程序的生成过程中分两个步骤进行:
- Application package (.apk file) is generated with all the required libraries and serialized assets.
生成所有需要的库和序列化资源的应用程序包(.apk文件)。 - Application package is deployed on the actual device.
在实际设备上部署应用程序包。
When "Build" is hit on "Build settings" dialog only the first step is accomplished. Hitting "Build and Run" performs both steps. If Cmd+B is hit then the automatic build and run process is invoked and the latest used file is assumed as the build target.
当“Build”到“Build settings”对话框只是第一步完成。点“编译和运行”,执行这两个步骤。如果按Cmd+B然自动编译并调用运行过程。
Upon the first attempt to build an Android project, Unity would ask you to locate the Android SDK, that is required to build and install your Android application on the device. You can change this setting later in Preferences.
当第一次尝试建立一个Android项目,Unity会询问查找Android SDK,这需要在设备上安装Android应用程序。可以以后在首选项中更改此设置。
When building the app to the Android, be sure that the device has the "USB Debugging" and the "Allow mock locations" checkboxes checked in the device settings.
当编译应用到Android上,确保设备设置USB Debugging和Allow mock locations复选框被选中。
You can ensure that the operating system sees your device by running adb devices command found in your Android SDK/platform-tools folder. This should work both for Mac and Windows.
确保操作系统型号,在Android SDK/platform-tools文件夹查找,运行adb devices命令。
Unity builds an application archive (.apk file) for you and installs it on the connected device. In some cases your application cannot autostart like on iPhone, so you need to unlock the screen, and in some rare cases find the newly installed application in the menu.
Unity为您建立的应用程序包(.apk文件)和连接的设备上安装。在某些情况下,你的应用程序无法像iPhone一样自动启动,所以你需要解锁屏幕,和在某些罕见的情况下,在菜单中查找新安装的应用程序。
Texture Compression 纹理压缩
Under Build Settings you'll also find the option. By default, Unity uses ETC1/RGBA16 texture format for textures that don't have individual texture format overrides (see Texture 2D / Per-Platform Overrides).
在编译设置,你还会发现纹理压缩选项。默认,Unity为没有单独的纹理格式重写的纹理,使用ETC1/RGBA16纹理格式。
If you want to build an application archive (.apk file) targeting a specific hardware architecture, you can use the Texture Compression option to override this default behavior. Any texture that uses texture format overrides will be left alone; only textures set to
will use the format selected in the option.如果你想生成一个应用程序包(.apk 文件)针对一个特定的硬件架构,可以使用纹理压缩来覆盖默认的行为。任何纹理使用纹理格式覆盖将保留格式;仅纹理设置为自动压缩将使用纹理压缩选项中选择的格式。
To make sure the application is only deployed on devices which support the selected texture compression, Unity will edit the AndroidManifest to include tags matching the particular format selected. This will enable the Android Market filtering mechanism to only serve the application to devices with the appropriate graphics hardware.
确保应用程序部署的设备支持选择的纹理压缩格式,Unity将编辑AndroidManifest包含标签匹配所选的特定格式。这将启用 Android Market filtering mechanism 过滤机制,仅用于带有相应图形硬件的设备启用应用程序。
Preloading 预加载
Published builds automatically preload all assets in a scene when the scene loads. The exception to this rule is scene 0. This is because the first scene is usually a splashscreen, which you want to display as quickly as possible.
发布的作品将在加载场景时自动预装场景中的所有资源, scene 0是例外,这是因为第一个场景通常是一个启动画面,你要尽可能快地显示它。
To make sure all your content is preloaded, you can create an empty scene which calls Application.LoadLevel(1). In the build settings make this empty scene's index 0. All subsequent levels will be preloaded.
要想确保所有内容完成预加载,你可以创建一个空场景调用Application.LoadLevel(1),在发布设置里让这个空场景的索引为0,这样所有后续关卡将会预加载。
You're ready to build games 你已准备好建立游戏了
By now, you have learned how to use Unity's interface, how to use assets, how to create scenes, and how to publish your builds. There is nothing stopping you from creating the game of your dreams. You'll certainly learn much more along the way, and we're here to help.
现在,你已经学会如何使用Unity的界面,如何使用资源,如何创建场景,以及如何发布你的作品。没有什么能够阻止你创建游戏的梦想。你一定沿途已经学到了很多,我们在这里提供帮助。
To learn more details about using Unity itself, you can continue reading the manual or follow the Tutorials.
要了解有关使用Unity本身更详细信息,您可以继续阅读手册或跟随的教程。
To learn more about Components, the nuts & bolts of game behaviors, please read the Component Reference.
要了解更多有关组件,请阅读组件参考手册。
To learn more about Scripting, please read the Scripting Reference.
要了解更多关于脚本的内容,请阅读脚本参考手册。
To learn more about creating Art assets, please read the Assets section of the manual.
要了解有关创建资源的内容,请阅读手册的Assets section。
To interact with the community of Unity users and developers, visit the Unity Forums. You can ask questions, share projects, build a team, anything you want to do. Definitely visit the forums at least once, because we want to see the amazing games that you make.
要与Unity社区的用户和开发人员互动,请访问Unity论坛。你可以提问题,共享项目,建立团队,和其它任何你想做的事情。你应当至少访问论坛一次,因为我们希望看到的是你创建出惊人的游戏。
页面最近更新: 2011-07-06