unity2d导出apk_顺利将2D内容导入Unity的良好工作流程,第I部分:创作和导出

unity2d导出apk

Unity has been used to develop numerous high quality 2D games over the years. This article, which is based on a talk I gave at three of our regional Unite developer conferences in Korea, Japan and China, gives in-depth instruction for a solid, real-life 2D production workflow. I hope this post can be helpful for any of our readers that are creating 2D games and interactive content with Unity. Due to the length of the tutorial, I’ve split it into two blog posts. Today you can read about authoring and exporting and tomorrow I’ll post the section on importing. You can find a link to download all the files at the end of the post.

多年来,Unity已用于开发众多高质量的2D游戏。 本文基于我在韩国,日本和中国的三个地区Unite开发者大会上的演讲而给出的内容,它为扎实,真实的2D生产工作流程提供了深入的指导。 我希望这篇文章对我们使用Unity创建2D游戏和交互式内容的所有读者有所帮助。 由于教程的篇幅,我将其分为两篇博客文章。 今天您可以阅读有关创作和导出的信息,明天我将发布有关导入的部分。 您可以在文章末尾找到一个链接来下载所有文件。

The benefits of a good 2D content workflow

良好的2D内容工作流程的好处

This tutorial takes you through the implementation of a real production workflow. When we talk about workflow it means the steps and processes used all the way from the initial authoring until the content is actually running in the game. Regardless of the number of applications needed in the chain from beginning to end, at a high-level a workflow consists of 3 major steps: authoring, exporting and importing.

本教程将指导您完成实际生产工作流程的实施。 当我们谈论工作流时,它意味着从最初的创作到内容在游戏中实际使用的所有步骤和过程。 从头到尾,无论链中需要多少应用程序,工作流程总体上都包含3个主要步骤:创作,导出和导入。

For some it may seem odd that we need both an exporter and an importer since tools like Unity are able to import data directly. The reason we need both is because we’re essentially creating our own intermediate file format that acts as the glue between any two applications in your workflow, in this case between Photoshop and Unity. This eliminates the need for an external application to be able to read and parse an application’s native file format, and allows chaining of applications to process the content as it moves from one application to the next.

对于某些人来说,我们既需要导出器又需要导入器似乎很奇怪,因为Unity等工具能够直接导入数据。 我们需要两者的原因是因为我们实际上是在创建自己的中间文件格式,该文件格式充当工作流程中任何两个应用程序(在本例中为Photoshop和Unity之间)之间的粘合剂。 这消除了外部应用程序能够读取和解析应用程序的本机文件格式的需求,并允许应用程序链接来处理内容从一个应用程序移动到另一个应用程序的过程。

Authoring

创作

It all starts with great content, and the first workflow we’ll look at is using the industry standard workhorse Photoshop. One of the great things about Photoshop is it’s simplicity to get started. Creating and editing imagery and graphics is painless and easy, and as your needs grow there’s an arsenal of tools and techniques at your disposal. The problem is that image files by themselves don’t have much ability to express useful meta-data for games in the same way that 3D models are able to do. What’s more, 2D is inherently in need of more meta-data given it’s limited nature of just being pixels.

一切都从丰富的内容开始,我们将要看的第一个工作流程是使用行业标准主力Photoshop。 Photoshop的一大优点是入门非常简单。 创建和编辑图像和图形既轻松又轻松,并且随着您的需求的增长,可以使用大量的工具和技术。 问题在于,图像文件本身不具备像3D模型一样能够表达游戏有用的元数据的能力。 此外,由于2D本质上仅是像素,因此本质上需要更多的元数据。

So what we want to do is imbue the image with useful information so that ultimately we know how to use the image in a game. To do that, we can use groups and layers to organize and tag them with what we need.

因此,我们要做的是向图像注入有用的信息,以便最终我们知道如何在游戏中使用图像。 为此,我们可以使用组和图层来组织和标记所需的内容。

We also need an example of 2D content that is useful and represents a realistic use. One of the last games I worked on before joining Unity was a simple 2D hidden-object game called Goddess Chronicles, and so we’ll use that as an example. In a hidden-object game the general idea is to find certain items that are hidden in plain sight in a scene such as the example shown below.

我们还需要一个有用且代表实际用途的2D内容示例。 加入Unity之前,我参与开发的最后一款游戏是一个名为Goddess Chronicles的简单2D隐藏对象游戏,因此我们以它为例。 在隐藏对象游戏中,通常的想法是找到某些场景中隐藏在普通视线中的项目,例如下面所示的示例。

Depending upon the game you’re making, the meta-data you need to capture will be different. For this game the design called for 2 basic kinds of imagery: “scenery” and “items”.

根据您制作的游戏,您需要捕获的元数据将有所不同。 对于这款游戏,设计需要两种基本的图像:“风景”和“物品”。

The importance of layers

图层的重要性

Scenery is the non-interactive content that’s there to provide the bulk of what’s seen, communicate a theme and support the gameplay by providing an environment where items can be hidden. So scenery will be placed into a group named “scenery” and we don’t need to care about the art layers in that group because they’re non-interactive. The items are the things you’ll actually be searching for within the scene and comprise the core gameplay. These are placed in groups that are named “item” and, unlike scenery, the art layers are important and each item can have up to 4 unique layers associated with them.

风景是一种非交互性内容,通过提供可以隐藏项目的环境来提供大部分可见内容,传达主题并支持游戏玩法。 因此,风景将被放置在一个名为“风景”的组中,我们不需要关心该组中的艺术层,因为它们是非交互的。 这些项目是您实际上将在场景中搜索的内容,并构成核心游戏玩法。 它们被放置在称为“项目”的组中,与风景不同,艺术层很重要,每个项目最多可以有4个与之关联的独特层。

“Whole” layers are required for all items. Usually once an item is found there will be some effect such as zooming the item up, or placing it into the player’s inventory, and we need the whole image so that it looks right.

所有项目都需要“整个”层。 通常,一旦找到某件物品,就会产生一些效果,例如放大该物品或将其放入玩家的库存,并且我们需要整个图像以使其看起来正确。

“Obscured” layers are used when you want to create the illusion that an item is behind something when in fact it’s floating in front of it. By erasing the pixels that should be hidden it tricks the eye into thinking that it’s actually behind something. In theory we could use whole images for everything, but there are many situations when it’s tedious for the artist to draw everything as separate pieces in order to hide an item, plus using the minimal amount of images in the game will increase the runtime performance.

当您想创建一个项目在某物后面,而实际上它漂浮在某物之前时,则使用“模糊”层。 通过擦除应该隐藏的像素,它使眼睛误以为它实际上在某物后面。 从理论上讲,我们可以为所有内容使用整个图像,但是在很多情况下,对于艺术家来说,将所有内容绘制为单独的部分以隐藏项目是很繁琐的,而且在游戏中使用最少数量的图像会提高运行时性能。

“Shadow” layers are used to help visually place the items into the scene and look like they belong there. Shadows are kept separately from the whole or obscured image so that if the whole image is zoomed up or moved it doesn’t have an odd looking shadow following it, and instead we can just hide the shadow in the scene once the item is found.

“阴影”层用于帮助视觉上将项目放置到场景中,并看起来像它们属于那里。 阴影与整个图像或被遮盖的图像分开放置,因此,如果放大或移动整个图像,其后将没有奇怪的阴影,而是可以在找到该项目后将其隐藏在场景中。

“Hotspot” layers are used to increase or decrease the area which the item can be interacted with. For example if you hide a golf club in a scene it could be very difficult to click or tap on. By using a hotspot you could make the interaction area bigger and easier to use.

“热点”层用于增加或减少可以与项目进行交互的区域。 例如,如果您将高尔夫俱乐部隐藏在一个场景中,则可能很难单击或点击。 通过使用热点,您可以使交互区域更大并且更易于使用。

So putting all this together we can use groups to designate whether something in our scene is scenery or an item, and we can use the art layers for items to hold the whole image for the item and optionally include obscured, shadow and hotspot images. The image below shows a set of layers for some scenery and an item. The item group is labelled “item:Beads” and contains 2 art layers called “whole” and “hotspot”. The scenery group is labelled “scenery:Column” and it contains any number of art layers that can be named anything since scenery layers aren’t special and we don’t need to keep track of them.

因此,将所有这些放在一起,我们可以使用组来指定场景中的某物是风景还是一件物品,并且我们可以使用艺术品的艺术品图层来保存该物品的整个图像,并可以选择包括模糊,阴影和热点图像。 下图显示了一些场景和项目的一组图层。 该项目组被标记为“ item:Beads”,并包含2个称为“整个”和“热点”的艺术图层。 风光组被标记为“ scenery:Column”,它包含任意数量的可以命名的艺术层,因为风光层不是特别的,我们不需要对其进行跟踪。

The end result is that we have a well composed scene where the group and layer names are encoded with what we need to give them meaning in our game. You can download the package at the end of the post and have a look for yourself. The next step is to now get all this exported.

最终结果是,我们有一个结构良好的场景,其中组和层的名称已编码为我们需要在游戏中赋予它们的含义。 您可以在文章末尾下载该软件包,并自己看看。 下一步是现在将所有这些导出。

Exporting

出口

Once we have some content, we need some way to get it all out for the next application in our workflow, which in this case is Unity. What we want to export are the images used to construct the scene along with the meta-data describing the position, order and other information. In order to do that we need a way to interact with the application at a low level with something that understands how to do that. Fortunately for us, Photoshop is scriptable using javascript and this will do exactly what we need.

一旦有了一些内容,我们就需要某种方法将其全部用于工作流中的下一个应用程序,在本例中为Unity。 我们要导出的是用于构建场景的图像以及描述位置,顺序和其他信息的元数据。 为了做到这一点,我们需要一种与底层应用程序进行交互的方法,该方法可以理解如何做到这一点。 对我们来说幸运的是,Photoshop可使用javascript编写脚本,这将完全满足我们的需求。

In fact quite a few Adobe apps are scriptable including Fireworks, Illustrator, Flash and others. We can use this capability to write our own exporter that can prepare the images for use in Unity and also capture the meta-data we need to make them meaningful. Adobe provides useful documentation and a script editor and debugger called ExtendScript for free.

实际上,相当多的Adobe应用程序都可以编写脚本,包括Fireworks,Illustrator,Flash等。 我们可以使用此功能来编写我们自己的导出器,该导出器可以准备要在Unity中使用的图像,还可以捕获使它们有意义的元数据。 Adobe免费提供有用的文档以及名为ExtendScript的脚本编辑器和调试器。

If you have the Creative Suite, it’s probably already installed on your system. On Mac it can be found in the Utilities/Adobe Utilities – CS6/ExtendScript Toolkit CS6 folder for the latest Creative Suite. On Windows, you should be able to find it at C:\Documents and Settings\\Application Data\ Adobe\ExtendScript Toolkit\3.8.

如果您拥有Creative Suite,则它可能已经安装在系统上。 在Mac上,可以在实用程序/ Adob​​e Utilities – CS6 / ExtendScript Toolkit CS6文件夹中找到最新的Creative Suite。 在Windows上,您应该能够在C:\ Documents and Settings \\ Application Data \ Adob​​e \ ExtendScript Toolkit \ 3.8中找到它。

Pretty much anything you can do in Photoshop can be scripted, and if there isn’t an API for a particular thing you want to do, you can record actions and convert them to command codes that you can paste into your scripts (alpha channel operations, I’m looking at you!).

您可以在Photoshop中执行的几乎所有操作都可以编写脚本,并且如果没有要执行的特定操作的API,则可以记录操作并将其转换为可粘贴到脚本中的命令代码(alpha通道操作) , 我在看着你!)。

For our purposes, we need a simple script that basically:

为了我们的目的,我们需要一个简单的脚本,该脚本基本上:

    The final exporter script is in the tutorial package. To use the script you place it in the Presets/Scripts sub-directory inside your Photoshop application directory. The script contains comments that explain what it does so I won’t go through all of it, but I will cover some of the more important parts.

    最终的导出程序脚本位于教程包中。 要使用脚本,请将其放置在Photoshop应用程序目录内的“预设/脚本”子目录中。 该脚本包含一些注释,这些注释解释了该脚本的功能,因此我不会全部介绍,但我将介绍一些更重要的部分。

    Firstly, the scripts are written in javascript which makes it easy to learn and use. The javascript engine used by Adobe isn’t very fast, but it works and is debuggable with the ExtendScript editor which makes it very useful.

    首先,脚本是用JavaScript编写的,因此易于学习和使用。 Adobe使用JavaScript引擎并不是很快,但是它可以正常工作并且可以通过ExtendScript编辑器进行调试,这使其非常有用。

    Since the meta-data is actually the part that gives meaning to the data, we need to spend the most time figuring out exactly what meta-data we need and how it should be formatted. I use XML as the way to specify the meta-data since that makes it really easy to parse later on in Unity. Based on the game design we know we have certain data that will be needed in the game. An extract of that data looks like this:

    由于元数据实际上是赋予数据含义的部分,因此我们需要花费大量时间来准确确定所需的元数据以及应如何格式化。 我使用XML作为指定元数据的方式,因为这使得以后在Unity中解析起来真的很容易。 根据游戏设计,我们知道游戏中需要某些数据。 该数据的摘录如下所示:

    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值