打开多个背包界面(或者其他UI界面,UI下有多层子级UI),鼠标点击某个界面后,该界面显示在最上面,同时其他面板的功能也可以正常使用。
之前想在每个界面中加一个全覆盖的Panle,通过控制Panle的Raycast Target属性来解决。点击面板A,面板A显示在最上面,所有功能正常,在此情况下,鼠标移动到(不点击)旁边的面板B,面板B的功能无法使用。因为没有点击面板B,所以没法通过currentSelectedGameObject得到对象,就没法设置面板B上Panle的Raycast Target,鼠标就会被Panle挡住,功能无法实现。求解。
想知道一种能够实现的思路。点击A后该界面显示最上面,同时B的功能可用;此情况下,点击B,B现实最上面。
让不同层级子级UI显示到最上面的一种方法:每个需要显示到顶层的ui添加canvas和graphic raycaster组件,勾选overrider sorting选项,通过修改sort order设置其最后渲染。添加graphic raycaster使其接收鼠标响应.
也可以利用API修改UI的顺序
//
// 摘要:
// Move the transform to the start of the local transform list.
public void SetAsFirstSibling();
//
// 摘要:
// Move the transform to the end of the local transform list.
public void SetAsLastSibling();
//
// 摘要:
// Sets the sibling index.
//
// 参数:
// index:
// Index to set.
public void SetSiblingIndex(int index);