资源表示 Unity 项目中用来创建游戏或应用的任何项。资源可以代表项目中的视觉或音频元素,例如 3D 模型、纹理、精灵、音效或音乐。资源还可以表示更抽象的项目,例如任何用途的颜色渐变、动画遮罩或任意文本或数字数据。
资源可能来自 Unity 外部创建的文件,例如 3D 模型、音频文件、图像。还可以在 Unity 编辑器中创建一些资源类型,例如 ProBuilder 网格 (ProBuilder Mesh)、Animator Controller、混音器 (Audio Mixer) 或渲染纹理 (Render Texture)。
上图显示了在 Unity 中使用资源时的典型工作流程。每列代表一个单独的步骤,如下所述:
导入是将源文件载入 Unity 编辑器以进行处理的过程。在将文件保存或复制到项目的 Assets
文件夹时,Unity 将导入该文件,从而使您可以在编辑器中使用该文件。
It’s important to learn some fundamentals of importing assets into Unity, such as where the files are stored in your Project, how to adjust the Import Settings for each kind of asset, what the meta files are for, and how the Asset Database stores imported data. See Importing Assets for more detail about these topics.
通过使用 Unity Accelerator,您可以在与团队合作时加快 Unity 对资源的处理速度。
一旦您将一些资源导入到您的项目中,就可以开始创建您的游戏或应用。这通常涉及将资源作为游戏对象放置到一个或多个场景中,并添加脚本来控制用户如何与它们交互。
随着项目开发的发展,您可能需要将资源分成不同的组,这样您的游戏就可以在运行时逐步下载选定的额外内容。
在创建过程中,您可以决定如何将您的资源分组为单独的包并实现选择何时加载它们的代码。
Grouping your assets into bundles allows you reduce the size of your initial download and load some assets later at runtime. This can help you optimize the download size and memory usage of your game or app. The recommended way to do this is to use Unity’s Addressables system.
Building refers to the process of exporting your completed project to binary files which you can then distribute and run on the platform of your choice. For example, when building for Windows, Unity generates an .EXE
file, along with some accompanying data files which you can then distribute.
如果您使用 Addressables 或 Asset Bundles 将您的资源分组为单独的下载包中,您还需要构建这些包文件以进行分发。
您可以在自己的计算机上构建项目,也可以使用 Unity 的 Cloud Build 服务,它可为您的 Unity 项目提供自动构建生成和持续集成。
在完成游戏或应用及其内容包的构建后,用户需要一种方式对其进行访问。分发方法的选择取决于您的目标平台。
例如,移动平台有自己的应用商店,您可以使用专业发布商,或者可在自己的服务器上自行托管。
Unity 提供了自己的 Cloud Content Delivery 服务,可托管您的游戏或应用及其内容,并将其提供给您的用户,该服务完全集成到 Unity 开发平台中。这样可节省大量的时间,对于内容丰富的实时游戏或需要定期更新内容的应用程序很有价值。
When users load and use your game or app, the loading process and experience is defined by the rules and programming that you set up, and the way that you grouped and bundled your assets.
结合使用此处描述的技术和服务,您可以提供快速的初始下载,并在项目的整个生命周期内推出持续更新和额外内容。
Unity’s asset workflow has tools and features which make it easy to edit and design directly in the Unity Editor:
When working with assets in Unity there are different strategies you can use. Which one suits your project depends on factors such as the size of your team, the size of your project, your target platforms, the memory availability on those platforms, and whether you want to release updates, patches, and DLC after publishing it.
For example, if you are working in a team, you could use a Cache Server alongside your version control system to cache Unity’s import results, to save time across the team.
如果您使用大量作为单独包发布的资源,可能会发现将部分资源组分离为单独的项目很有帮助,这样您的团队成员就不需要一次性加载大型项目来使用这些资源包。
If you keep all your assets in a single project, Unity automatically builds them in the correct format for the current selected platform when you run a build. However, if you split your assets across multiple projects to build your bundles separately, you must make a build for each platform you support. See the Addressables documentation Building for multiple platforms for more information.
The characteristics of a platform also determine the restrictions and possibilities of how you organize your runtime assets. For example, on the standalone platforms (PC or macOS), virtual memory provides a almost unbounded pool of memory, so using the Resources folder or large asset bundles doesn’t typically pose a memory challenge. Conversely, mobile devices and console platforms typically have limited or nonexistent virtual memory, so apps built for those platforms must manage asset loading and unloading more efficiently.
用户对平台的期望也是一个重要的考虑因素。例如,在移动平台上,漫长的初始下载和安装过程可能会导致玩家尚未尝试就放弃了您的应用。出于这个原因,移动应用通常在初始构建中只包含最少的资源集,并在用户第一次运行您的应用时从远程服务器下载剩余的资源。