基于Unity3D的魔方游戏设计外文翻译资料

 2022-05-19 10:05

节选自Game Development with Unity

第7部分直第10部分

7. Assets

Page 19

Copyright copy; 2003-2010 Technicat, LLC All rights reserved.

Game Development with Unity

7.1. Importing

Assets are imported into Unity simply by placing them in the project Assets directory. You can also use the Asset-gt;Import Asset menu item. An automatic import then takes place and the asset then shows up in the Unity editor project display.

You can then adjust the import settings (there#39;s no way to do it beforehand) and then hit the reimport button.

Note:

One of the less helpful defaults in Unity is the Scale Factor used in import. The sharp-eyed user may notice the default is 0.01, for legacy reasons. So adjust the Scale Factor and reimport as necessary.

7.2. Standard Assets

When you create a new project, you#39;ll be prompted whether to immediately import Standard Assets. If you#39;re new to Unity, you definitely should include these, at least to reference as examples. Don#39;t worry about bloating your game - unused assets don#39;t contribute (much) to the final game size.

Page 20

Copyright copy; 2003-2010 Technicat, LLC All rights reserved.

Game Development with Unity

If you need import or reimport Standard Assets later, (e.g. if you modify elements of Standard Assets and want to revert to the original), you can find the corresponding .unitypackage in the Unity installation.

Page 21

Copyright copy; 2003-2010 Technicat, LLC All rights reserved.

Game Development with Unity

Note:

When you upgrade to new versions of Unity, be sure to also reimport the standard assets, so you get the latest stuff (and fixes).

7.3. Pro Assets

If you have Unity Pro, you also have the option of including the Pro Standard Assets.

7.4. Organizing Assets

Note:

Once an asset has been imported, you can move or delete it in the Project pane, but don#39;t move or delete it from within the Finder. Unity tracks relationships among the assets in a project, so moving or deleting those assets outside Unity will mess up your project.

7.5. Animation

Animation is imported as FBX (or Collada?) files. If character animations are set up and imported according to one of the conventions for Importing Character Animation then the resulting character contain a list of the named animations that can be controlled by the script.

Note that animations tend to take a lot of memory. If an animation is simple, the like the HyperBowl logo rotation, it#39;s better to let a script handle it.

7.6. Meshes

Officially, several formats are supported, (see Meshes (User Manual) but the most reliable is FBX. OBJ and Collada support appear to be implemented by using those importers in the FBX SDK, so they are only as worthy as the FBX SDK support. For example, OBJ files created by PolyTrans hang during import and also when run through the Autodesk FBX

Page 22

Copyright copy; 2003-2010 Technicat, LLC All rights reserved.

Game Development with Unity

converter, so no surprise. Watch out, the default conversion scale during import is 0.01 for legacy support reasons.

7.7. References

8. Scripting

8.1. Languages

The scripting system is based on Mono, an open-source version of .NET. Like .NET, mono supports many programming languages, but Unity only supports C#, Boo, and Javascript. Each language has it#39;s pros and cons. C# has the advantage of having an official definition and many instructional books and online tutorials, is the closest thing to a main language on

.NET and Mono, and thus used in a lot of commercial and open-source software. But C# is the most verbose choice.

Boo seems to be well-liked by Python programmers but is probably used by the smallest number of Unity users and correspondingly has the least support.

The version of Javascript in Unity is more succinct but apparently derived from the Boo implementation and not quite standard Javascript (so it#39;s been suggested that it be called UnityScript). Most of the scripts supplied with Standard Assets are in Javascript, although a few are in C#. I mainly use Javascript, with the exception of some C# code from open-source libraries, so I#39;m only going to show Javascript examples here.

Note:

While it is possible to combine scripts written in different languages in the same Unity project, it is tricky. See Script Reference section on Script Compilation. Sticking with one language makes things a lot easier.

8.2. Scripts are Assets

Scripts are assets just like textures and models. Several scripts are provided in the Standard Assets.

Page 23

Copyright copy; 2003-2010 Technicat, LLC All rights reserved.

Game Development wit

全文共18921字,剩余内容已隐藏,支付完成后下载完整资料


节选自Game Development with Unity第7部分至第10部分

7. 资源

7.1. 导入

只需将资源放在项目资源目录中,就可以将资源导入到Unity中。您还可以使用资源-gt;导入资源菜单项。然后自动导入,然后资源出现在Unity编辑器项目显示中。

然后,您可以调整导入设置(无法事先执行),然后点击重新导入按钮。

注意:

Unity中不太有用的默认值之一是导入中使用的比例因子。 由于传统原因,敏锐的用户可能会注意到默认值为0.01。 因此调整比例因子并根据需要重新导入。

7.2. 标准资源

当您创建新项目时,系统会提示您是否立即导入标准资源。 如果你是Unity的新手,你绝对应该包括这些,至少可以作为例子参考。 不要担心你的游戏膨胀 - 未使用的资源对最终游戏规模没有贡献(很大)。

如果您稍后需要导入或重新导入标准资源(例如,如果您修改标准资源的元素并想要恢复为原始资源),则可以在Unity安装中找到相应的.unity包。

注意:

当您升级到Unity的新版本时,请务必重新导入标准资产,以便获取最新内容(和修复程序)。

7.3. 专业资源

如果您拥有Unity Pro,则还可以选择包含专业标准资源。

7.4. 组织资源

注意:

资源导入后,您可以在“项目”窗格中移动或删除它,但不要在Finder中移动或删除它。 Unity会跟踪项目中资源之间的关系,因此在Unity之外移动或删除这些资源会混淆您的项目。

7.5. 动画

动画导入为FBX(或Collada?)文件。 如果根据导入角色动画的其中一个约定设置和导入角色动画,则结果字符将包含可由脚本控制的指定动画列表。

请注意,动画往往需要大量的内存。 如果动画很简单,就像HyperBowl标志旋转一样,最好让脚本处理它。

7.6. 网格

官方支持多种格式(见网格(用户手册),但最可靠的是FBX。OBJ和Collada支持似乎是通过在FBX SDK中使用这些导入器来实现的,所以它们只和FBX SDK支持一样有价值。例如,在导入过程中由PolyTrans hang创建的OBJ文件,以及在Autodesk FBX转换器中运行时所创建的文件,所以并不奇怪。注意,在导入期间默认的转换规模为0.01,因为遗留支持的原因。

7.7. 参考文献

8. 脚本

8.1. 语言

脚本系统基于.NET的开源版Mono。 像.NET一样,mono支持许多编程语言,但Unity只支持C#,Boo和Javascript。 每种语言都有其优点和缺点。 C#具有官方定义的优点,许多教学书籍和在线教程都是与主要语言最接近的.NET和Mono,因此被用于许多商业和开源软件。 但C#是最详细的选择。

Boo似乎很受Python程序员的喜爱,但可能被最少数量的Unity用户使用,并相应地得到最少的支持。

在Unity中的Javascript版本更加简洁,但显然是从Boo实现中派生出来的,并且不是很标准的Javascript(因此有人建议将它称为UnityScript)。 标准资产提供的大多数脚本都使用Javascript,尽管少数使用C#。 我主要使用Javascript,除了一些来自开源库的C#代码外,所以我只打算在这里显示Javascript示例。

注意:

尽管可以在同一个Unity项目中组合使用不同语言编写的脚本,但这很棘手。 请参阅脚本编译的脚本参考部分。 坚持一种语言让事情变得更容易。

8.2. 脚本是资源

脚本就像纹理和模型一样是资源。 标准资源中提供了几个脚本。

可以像其他资源一样导入脚本(通过“资源导入”菜单项或拖到“资源”文件夹中)。

8.3. 脚本是组件

Unity使用脚本进行编程 - 不涉及C 编程(除非您编写插件或购买源许可证)。 Unity中的脚本编程与传统编程有点不同,但类似于在Second Life中使用Linden脚本语言和在CryEngine中使用Lua - 个别脚本附加到游戏中的对象。 这适用于一种面向对象的设计,在这种设计中,您可以编写特定的脚本来控制特定的游戏实体。

在Unity中,脚本是组件,并像其他组件一样附加到游戏对象。 有关使用脚本的Unity手册部分详细介绍了如何创建脚本并将其附加到对象。 具体来说,脚本是MonoBehaviour类,它是Behavior的直接子类,正如我们前面提到的那样,它是一个可以启用/禁用的Component。

注意:

术语“对象”通常是松散的,在Unity中通常指的是游戏对象或游戏对象及其组件。 但记住一个脚本组件是一个与其父游戏对象不同的对象。

8.4. 脚本是类

每个脚本实际上都定义了一个MonoBehaviour的新子类。 使用Javascript脚本,Unity会将此定义视为隐式 - 新类根据文件名进行命名,并且脚本的内容被视为在周围类定义中发生。 在C#脚本中,类定义是明确的。

MonoBehaviour实际上是行为的子类,正如我们前面提到的那样,它是一个可以启用/禁用的组件。

注意:

请注意,您不要使用与现有.NET类相同的名称来定义新类。 通常,您会定义一个名称空间以避免与现有名称冲突,但Unity目前不支持名称空间。 在我的FuguType打字游戏中,我创建了一个名为Dictionary的类来包含游戏中的所有单词。 不幸的是,我有一个.NET Dictionary类。 游戏会运行一段时间,但最终会崩溃。

8.5. 脚本结构

如果没有一个代码执行,附加到一个对象上的代码不是很有趣。 脚本通过实现在游戏的生命周期内由Unity引擎调用的回调函数,将行为添加到对象中。

当对象加载时调用唤醒。

在唤醒之后调用启动,但仅在对象处于活动状态时(并且仅在第一次激活后,如果对象活动状态开启和关闭并再次开启则不再重复)。

在开始之后,对象处于活动状态时,每帧调用一次更新。

在每个固定的更新间隔(用于物理更新的相同间隔)之后调用FixedUpdate

有时你想在游戏对象被激活或停用时执行操作。 例如,HyperBowl记分板每次启动时都会播放动画。 如果我们将这些代码放在Start函数中,它最多只能运行一次。 相反,我们使用OnEnable

并有一个相应的OnDisable

其他回调在特定事件下被调用,如物理。

你不需要指定每一个 - 只需要你需要的一个。 有关每个脚本的完整说明,请参阅Unity脚本参考。

8.6. 接触

即使有回调,如果它们不能至少控制它们的父游戏对象,脚本也不会有用。一个脚本可以通过它的gameObject成员变量引用它的父游戏对象。一个脚本可以调用GetComponent来访问游戏对象的任何组件,但是一些成员变量作为通用组件的快捷方式。

注意:

在使用快捷方式变量时,还有一些额外的性能开销,最好将结果分配给一个脚本变量,如果您想要重复地引用该组件,特别是在OnUpdate中。

8.7. 积极和启用

我们一直在用“积极”的词语快速放松。 当我们说当一个游戏对象处于活动状态时调用脚本回调函数时,我们确实意味着游戏对象处于活动状态,并且脚本已启用(因此指定了OnEnable和OnDisable回调函数。

除了回调之外,我们还可以检查并设置游戏对象的活动成员变量和脚本的启用成员变量。

8.8. 协同程序

Unity操作不是线程安全的,所以Unity脚本支持协程。 具体见 Coroutines overview

8.9. 状态机

协程提供了一种实现有限状态机的简单方法。 FSM是定义对象行为的绝佳方式,以至于某些脚本系统明确支持它们(例如Second Life和CryEngine)。

8.9.1. 单个状态机

function Start ()

{

state = 'BowlInit';

while (true) {

yield;

yield StartCoroutine(state);

}

}

8.10. 编辑脚本

当您双击Project窗口中的脚本或单击编辑检查器中显示的脚本时,Unity会显示一个脚本编辑器。 Unity有一个名为Unitron的默认脚本编辑器,但您可以在首选项中指定不同的编辑器。 例如,我使用名为 Aquamacs 的Mac版Emacs。

Unity附带的Javascript模式并不包含Unitron的Unity功能颜色编码,但Unity员工提供了类似的Emacs Unity-Javascript mode

8.11. 第三方库和工具

Unify community wiki 拥有许多大大小小的脚本。

UnitySteer OpenSteer Ninja Portal 提供Unity对话引擎后开源的Unity转向包。

Angry Ant 提供寻路和行为树库。

FeedReader 是一

全文共6339字,剩余内容已隐藏,支付完成后下载完整资料


资料编号:[12107],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。