/// <summary>
/// 修改UI背景图的层级
/// *******背景图和显示图层必须在同意级别**********
/// </summary>
/// <param name="Trans_Background">背景图</param>
/// <param name="Trans_Show">要显示的图层</param>
private void ChangeUI_Layer_Method(Transform Trans_Background, Transform Trans_Show)
{
if (Trans_Background != null && Trans_Show != null)
{
//1、获取要显示的图层信息
int Int_ShowLayer = Trans_Show.GetSiblingIndex();
Debug.Log("要显示的图层是:" + Int_ShowLayer);
//2、获取背景图层信息
int Int_BackgroundLayer = Trans_Background.GetSiblingIndex();
Debug.Log("背景图的图层是:" + Int_BackgroundLayer);
//3、修改背景图的层级
if (Int_ShowLayer == 0)
{
Trans_Background.SetAsFirstSibling();
}
else
{
//4、判断背景图和要显示的图层关系
if (Int_ShowLayer < Int_BackgroundLayer)
{
Trans_Background.SetSiblingIndex(Int_ShowLayer);
}
else
{
Trans_Background.SetSiblingIndex(Int_ShowLayer - 1);
}
}
}
}
Unity中代码修改UI层级关系
猜你喜欢
转载自blog.csdn.net/qq_34444468/article/details/85599486
今日推荐
周排行