欢迎访问 如意编程网!

如意编程网

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Ngui之UI框架的层级处理

发布时间:2024/7/5 编程问答 4 豆豆
如意编程网 收集整理的这篇文章主要介绍了 Ngui之UI框架的层级处理 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1 #region 处理层级问题 2 3 void DepthIncrease(UIWndBase uiWnd) 4 { 5 DepthIncrease(uiWnd.transform, UIFlag); 6 } 7 8 public static void DepthIncrease(Transform root, UIFlag selfUIFlag) 9 { 10 if (UIManager.SingleUIMgr.AllUIWnd == null) 11 return; 12 13 int maxDepth = 0; 14 foreach (var pair in UIManager.SingleUIMgr.AllUIWnd) 15 { 16 if (pair.Value.UIID != selfUIFlag && pair.Value.UIID != UIFlag.ui_novice_guide) 17 { 18 int d = GetUIMaxDepth(pair.Value.transform); 19 if (d > maxDepth) 20 maxDepth = d; 21 } 22 } 23 24 // lua wnd 25 GameObject objNguiRoot = NGUIAssetHelp.NGUIRoot; 26 if (objNguiRoot) 27 { 28 LuaComponentLoader[] luaLoaders = objNguiRoot.transform.GetComponentsInChildren<LuaComponentLoader>(); 29 for (int i = 0; i < luaLoaders.Length; i++) 30 { 31 LuaComponentLoader luaLoader = luaLoaders[i]; 32 if (luaLoader && !string.IsNullOrEmpty(luaLoader.ComponentName) && luaLoader.ComponentName.ToLower().Contains("wnd")) 33 { 34 int d = GetUIMaxDepth(luaLoader.transform); 35 if (d > maxDepth) 36 maxDepth = d; 37 } 38 } 39 } 40 41 SetUIDepth(root, maxDepth + 1); 42 } 43 44 // 设置ui界面中UIPanel的层级 45 static void SetUIDepth(Transform root, int depth) 46 { 47 UIPanel[] panels = root.GetComponentsInChildren<UIPanel>(true); 48 if (panels == null || panels.Length < 1) 49 return; 50 51 Array.Sort(panels, (a, b) => a.depth - b.depth); 52 for (int i = 0; i < panels.Length; i++) 53 { 54 UIPanel p = panels[i]; 55 if (p != null) 56 p.depth = i + depth; 57 } 58 } 59 60 // 获得ui界面的UIPanel的最大层级 61 static int GetUIMaxDepth(Transform root) 62 { 63 UIPanel[] panels = root.GetComponentsInChildren<UIPanel>(false); 64 if (panels == null || panels.Length < 1) 65 return 0; 66 67 Array.Sort(panels, (a, b) => a.depth - b.depth); 68 UIPanel lastPanel = panels.LastOrDefault(); 69 return lastPanel != null ? lastPanel.depth : 0; 70 } 71 72 #endregion

转载请注明出处:https://www.cnblogs.com/jietian331/p/10911991.html

转载于:https://www.cnblogs.com/jietian331/p/10911991.html

总结

以上是如意编程网为你收集整理的Ngui之UI框架的层级处理的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得如意编程网网站内容还不错,欢迎将如意编程网推荐给好友。