Unity - 如何更改 UI 子对象的绘制顺序(与正常绘制顺序相反)到网格布局组

Unity - How can I change the draw order (to be opposite of normal draw order) of UI Objects that are childed to a Grid Layout Group

在Unity引擎中~ 有谁知道如何更改作为网格布局组子元素的 ui 元素的绘制顺序(与绘制顺序相反) 所以我想保留元素当前的位置排序方式,但我想将 Grid Layout Group 对象的子对象更改为与平常相反的渲染顺序。因此,与其绘制子 0、1、2(渲染在顶部),不如绘制子 2、1、0(渲染在顶部)。我必须强调,我不想更改子项相对于 Grid Layout Group 父游戏对象的实际顺序。

粗暴的方法是为每个 child 创建一个 UI material 实例并手动设置队列。

您可以使用这些方法调整渲染顺序:

transform.SetAsLastSibling (); // Element is displayed on the top.
transform.SetAsFirstSibling (); // Element is displayed last.
transform.SetSiblingIndex (7); // Element is displayed based on an index
transform.GetSiblingIndex ();

直接给元素添加一个canvas,设置overrideSorting为true,手动设置顺序。

此外,要使某些其他功能正常工作,请添加图形 raycaster 组件

来自 https://www.reddit.com/r/Unity3D/comments/7psox8/ui_element_render_order_in_grid_layout/