spotlight
On the Spotlight Team, we work with the most ambitious Unity developers to try to push the boundary of what a Unity game can be. We see all sorts of innovative and brilliant solutions for complex graphics, performance, and design problems. We also see the same set of issues and solutions coming up again and again.
在Spotlight小组中,我们与雄心勃勃的Unity开发人员一起努力扩大Unity游戏的界限。 对于复杂的图形,性能和设计问题,我们看到了各种各样的创新和出色的解决方案。 我们还会看到同样的问题和解决方案不断出现。
This blog series looks at some of the most frequent problems we encounter while working with our clients. These are lessons hard won by the teams we have worked with, and we are proud to be able to share their wisdom with all our users.
本博客系列介绍了与客户合作时遇到的一些最常见的问题。 这些是我们与之合作的团队所赢得的经验教训,我们为能够与所有用户分享他们的智慧而感到自豪。
Many of these problems only become obvious once you are working on a console or a phone, or are dealing with huge amounts of game content. If you take these lessons into consideration earlier in the development cycle, you can make your life easier and your game much more ambitious.
这些问题中的许多问题只有在您使用控制台或电话或处理大量游戏内容时才会变得明显。 如果您在开发周期的早期就考虑了这些教训,则可以使您的生活更轻松,游戏也更具野心。
把那个东西放在你想要的地方 (Putting that thing where you want it)
Despite being one of the most common things done in Unity, we see lots of teams struggling with the best way to move an object around. Specifically, it can be tricky to get objects to line up perfectly so that characters stay in the world, paths get built properly, and physics objects rest nicely on each other.
尽管这是Unity中最常见的事情之一,但我们仍然看到许多团队都在努力寻找移动对象的最佳方法。 具体来说,要使对象完美对齐可能会很棘手,以使角色留在世界中,正确构建路径,并使物理对象彼此良好地靠在一起。
Unity provides quite a few tools to make this easier, but they all can serve different roles. These tools are necessary to understand once you start trying to make lots of consistent content or try to make scenes like the one above that are dense with dynamic physics objects.
Unity提供了许多工具来简化此过程,但是它们都可以充当不同的角色。 一旦您开始尝试制作大量一致的内容或尝试制作上面场景中充满动态物理对象的场景,就必须理解这些工具。
适合该工作的Gizmo (The right Gizmo for the job)
We provide tools for Translation, Rotation, Scaling and, new in 2017.3, a universal tool that will let you do all three. Each of these Gizmos lets you alter the transform properties of your game object in 3D. Additionally we have the Rect Transform tool for working in 2D.
我们提供了用于平移,旋转,缩放的工具,并且在2017.3中新增了一个通用工具,可让您完成全部三个操作。 这些小控件均允许您更改3D游戏对象的变换属性。 此外,我们还有可用于2D的Rect变换工具。
All of these Gizmos operate based on the mode toggles that follow them. If you have your Gizmos set to Center, you will be working with the calculated middle of the object based on its bounds. This is an approximation, so may feel a bit off of true center for complicated objects. When your Gizmos are set to Pivot, you are operating on the (0,0,0) point of the object in its own frame of reference. This Pivot, hopefully, is set at a useful point by whomever created the asset in the first place. In general, we recommend operating in Pivot mode when placing objects relative to each other and keeping the Pivot location in mind when creating your assets. The second toggle, Global / Local, controls what space you are operating in. Global sets your gizmos to align with the world (x,y,z) axes, while Local sets them to the object’s own (x,y,z). Personally, I mostly work in Local space. If I am trying to get multiple objects to align to each other, however, then I will often work in Global coordinates and use the grid snapping to get things to line up nicely.
所有这些Gizmos都基于跟随它们的模式切换进行操作。 如果将Gizmos设置为Center,则将根据对象的边界处理对象的计算出的中间值。 这是一个近似值,因此对于复杂的对象可能会感觉偏离真正的中心。 当您的Gizmos设置为“透视”时,您将在对象自身的参照系中对其的(0,0,0)点进行操作。 希望此数据透视图被设置在有用的位置,无论谁首先创建资产。 通常,建议在相对放置对象时以“透视”模式进行操作,并在创建资产时牢记“透视”位置。 第二个切换是“全局/本地”,用于控制您要在哪个空间中工作。“全局”将Gizmos设置为与世界(x,y,z)轴对齐,而“本地”将其设置为对象自己的(x,y,z)。 我个人主要在本地空间工作。 但是,如果我要使多个对象彼此对齐,那么我将经常在“全局”坐标中工作,并使用网格捕捉来使事物很好地对齐。
快点! (Snap!)
The most straight forward positioning tool in Unity is holding the CTRL (Win) or Command (OSX) key to snap to a grid. Any time you are moving an object by its Axis handles (those blue red and green gizmos), holding down the snapping key will cause the object to move in increments of your current grid size… which you can change!
Unity中最直接的定位工具是按住CTRL(Win)或Command(OSX)键以捕捉到网格。 每当您通过其Axis手柄(蓝色,红色和绿色小控件)移动对象时,按住捕捉键都会使该对象以当前网格大小的增量进行移动……可以更改!
The Snap Settings menu lets you set per axis values for your grid size, gives you control of snapping for both rotation and scale, and lets you round a selected object’s current transform to the nearest grid line.
通过“捕捉设置”菜单,您可以为网格大小设置每个轴的值,可以控制旋转和缩放的捕捉,还可以将选定对象的当前变换舍入到最接近的网格线。
The Snap All Axes button is particularly useful for getting arbitrary content lined up. You can select a group of objects, snap them to the grid in all axes, and then reposition them so they line up perfectly. Like so:
“对齐所有轴”按钮对于排列任意内容特别有用。 您可以选择一组对象,将它们在所有轴上对齐到网格,然后重新放置它们,使它们完美对齐。 像这样:
This works well for regular geometry, large scale level layout, and putting in blocks of collision. If you have more complicated placement needs however…
这对于规则的几何体,大规模的水平布局以及放置碰撞块非常有效。 但是,如果您有更复杂的放置需求...
顶点捕捉 (Vertex Snapping)
Press and hold V and the Transform Gizmo will switch to vertex snapping mode, as indicated by the little square. You can then click on a vertex of your selected object’s mesh, and then drag it to snap to any vertex under your pointer. This is very useful for aligning arbitrary meshes, especially those with complex or non-existent collision. Neither the wire or the lamp above have anything like a tight collision mesh, and neither are even vaguely cube-like, so they don’t fit together with grid snapping or collision snapping.
按住V,变换Gizmo将切换到顶点捕捉模式,如小方块所示。 然后,您可以单击所选对象的网格的顶点,然后将其拖动以捕捉到指针下方的任何顶点。 这对于对齐任意网格非常有用,尤其是那些具有复杂或不存在碰撞的网格。 电线或上方的灯都没有像紧紧的碰撞网那样的东西,甚至都不是近似立方体的形状,因此它们不能与网格捕捉或碰撞捕捉配合在一起。
You can also turn on Vertex snapping mode if you are going to be placing a lot of Game Objects this way. Hit Ctrl+Shift+V to turn on and Ctrl+V to turn back off. This lets you vertex snap a lot of objects without holding down the V key the whole time.
如果您将以这种方式放置很多游戏对象,则也可以打开“顶点捕捉”模式。 按下Ctrl + Shift + V打开,然后按下Ctrl + V关闭。 这使您可以在不始终按住V键的情况下顶点捕捉很多对象。
碰撞捕捉 (Collision Snapping)
If you hold down CTRL + SHIFT, you enable Collision snapping. You have to then click and drag on the little yellowish square at the center of the Transform Gizmo, rather than using the axis controls. This will then cause the selected object to try to line its collision up with the collision of whatever is under the cursor.
如果按住CTRL + SHIFT,则启用“碰撞捕捉”。 然后,您必须单击并拖动Transform Gizmo中心的小黄色正方形,而不是使用轴控件。 然后,这将导致所选对象尝试将其碰撞与光标下方任何物体的碰撞对齐。
Lining up meshes with vertex snapping or grid snapping works great for static geometry, but if you have dynamic objects, objects that might, say, interpenetrate and launch themselves into space when touched, you really want to snap not to the visible mesh but to the collider around it.
使用顶点捕捉或网格捕捉来排列网格非常适合于静态几何,但是如果您有动态对象,则这些对象可能会相互渗透并在接触时发射到空间中,您真的想捕捉的不是捕捉到可见的网格,而是捕捉到对撞机。
碰撞解决 (Collision Settling)
If you have lots of dynamic physics objects, or very complicated joint system, it might not be feasible to use collision snapping to get everything where physics says it should be. Fortunately, we now allow you to run PhysX in the editor. This lets you simulate a few seconds of game time, let your physics come to a rest, and then save out the resulting positions.
如果您有许多动态的物理对象或非常复杂的关节系统,则使用碰撞捕捉来获取物理所应具有的一切可能是不可行的。 幸运的是,我们现在允许您在编辑器中运行PhysX。 这使您可以模拟几秒钟的游戏时间,让自己的物理状态稳定下来,然后保存结果位置。
You can find the heavily commented example code complete with debug drawing and a menu item here. Just throw that file into any “Editor” folder in your project and you should get a new GameMenu->Settle Physics menu item.
您可以在此处找到带有注释的示例代码,其中包括调试图和菜单项。 只要将该文件放入项目中的任何“ Editor”文件夹中,您就应该获得一个新的GameMenu-> Settle Physics菜单项。
Knowing when and why to use grids, vertex snapping, collision snapping in your level design workflow will come with experience. Play around with these tools, along with the Pivot vs Center and Global vs Local toggles until you find what works for you. The less time you have to spend arranging your virtual furniture, the more time you can spend finding the fun. Big thanks to Campo Santo for letting us use their assets for our examples.
在关卡设计工作流程中了解何时以及为何使用网格,顶点捕捉,碰撞捕捉将带给您丰富的经验。 使用这些工具,以及“数据透视vs中心”和“全局vs本地”切换,直到找到适合您的方法。 您花在布置虚拟家具上的时间越少,您就可以花更多的时间来寻找乐趣。 非常感谢Campo Santo让我们使用他们的资产作为示例。
翻译自: https://blogs.unity3d.com/2018/01/03/spotlight-team-best-practices-object-placement-and-physics/
spotlight