• NGUI中处理层级问题的几个方法总结


    1、获得ui界面的UIPanel的最大层级:

     1  static int GetUIMaxDepth(Transform root)
     2         {
     3             UIPanel[] panels = root.GetComponentsInChildren<UIPanel>(false);
     4             if (panels == null || panels.Length < 1)
     5                 return 0;
     6 
     7             Array.Sort(panels, (a, b) => a.depth - b.depth);
     8             UIPanel lastPanel = panels.LastOrDefault();
     9             return lastPanel != null ? lastPanel.depth : 0;
    10         }

    2、设置ui界面中UIPanel的层级:

     1 static void SetUIDepth(Transform root, int depth)
     2         {
     3             UIPanel[] panels = root.GetComponentsInChildren<UIPanel>(true);
     4             if (panels == null || panels.Length < 1)
     5                 return;
     6 
     7             Array.Sort(panels, (a, b) => a.depth - b.depth);
     8             for (int i = 0; i < panels.Length; i++)
     9             {
    10                 UIPanel p = panels[i];
    11                 if (p != null)
    12                     p.depth = i + depth;
    13             }
    14         }

    3、游戏中打开的UI一般是保存在一个集合中的。当需要给新的UI设置层级的时候,只需要通过一个循环遍历,找出已打开的UI中的最大层级,然后在此基础上加1,即 max + 1,然后将 max +1赋值给新打开的UI即可

  • 相关阅读:
    repair grub in Ubuntu
    DNS attack experiment
    新闻随感(摩托罗拉125亿被Google收购)
    成为C++高手必须要看的书
    nginx
    Nginx Pitfalls
    gcc/gdb
    python 删除文件
    Solve nginx Error 413 Request Entity Too Large
    Solve Nginx Error 413: Request Entity Too Large
  • 原文地址:https://www.cnblogs.com/luguoshuai/p/9892070.html
Copyright © 2020-2023  润新知