Unity按多个标准对渲染器进行排序,例如层顺序或其与摄像机的距离。Unity的图形设置(菜单:编辑 > 项目设置 > 图形)提供了一个名为 透明度排序模式 的设置,您可以使用该设置根据精灵相对于摄像机的位置来控制如何排序精灵。更具体地说,它使用精灵在一个轴上的位置来确定哪些精灵相对于其他精灵是透明的。
使用此设置的示例之一是对沿 y 轴排列的 精灵2D 图形对象。如果您习惯了3D工作环境,精灵实际上只是标准纹理,但有一些特殊的组合和管理技巧,可以在开发过程中提高效率和便捷性。 更多信息
见同义词 进行排序。这在2D游戏中相当常见,其中 y 轴上方的精灵排序在下方精灵之后,使其看起来更远。
有四个可用的 透明度排序模式 选项
排序模式 | 描述 |
---|---|
默认 | 根据摄像机投影模式是否设置为透视或正交进行排序。 |
透视 | 根据透视视图进行排序。透视视图根据摄像机位置到精灵中心的距离进行排序精灵。 |
正交 | 根据正交视图进行排序。正交视图根据视野方向上的距离进行排序精灵。 |
自定义轴 | 根据在 透明度排序轴 中设置的给定轴进行排序。 |
如果您将 透明度排序模式 设置为 自定义轴,您还需要设置 透明度排序轴。
如果 透明度排序模式 设置为 自定义轴,则在 场景一个包含游戏环境和菜单的场景。请将每个独特的场景文件视为一个独特的关卡。在场景中,您可以放置环境、障碍物和装饰,从而在多个部分中进行游戏设计和构建。 更多信息
见同义词 视图中,渲染器按与摄像机在此轴上的距离进行排序。用介于 -1 和 1 之间的值定义该轴。例如:X=0,Y=1,Z=0 将轴方向设置为向上。X=1,Y=1,Z=0 将轴设置为 X 和 Y 之间的对角线方向。
例如,如果您想使精灵的行为像上面的图像中一样,请将 透明度排序模式 设置为 自定义轴,并将 透明度排序轴 的 Y 值设置为大于 0 的值。
您还可以通过脚本一段代码,允许您创建自己的组件、触发游戏事件、随时间修改组件属性,并以您喜欢的任何方式响应用户输入。更多信息
查看词汇表来按相机构对精灵进行排序,通过修改相机的以下属性来实现
例如
var camera = GetComponent<Camera>();
camera.transparencySortMode = TransparencySortMode.CustomAxis;
camera.transparencySortAxis = new Vector3(0.0f, 1.0f, 0.0f);
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.