NGUI的UIPanel双层裁剪
发布日期:2021-06-30 19:40:30
浏览次数:2
分类:技术文章
本文共 2139 字,大约阅读时间需要 7 分钟。
有时候有这样的需求,在一个滚动的列表里面,item中又有滚动列表,也就是UIPanel的嵌套裁剪。
而NGUI中,子UIPanel不会被父UIPanel正常裁剪,需要改造一下。
首先,在UIPanel中,增加一个parentClipPanel成员
//UIPanel.cs[SerializeField]public UIPanel parentClipPanel;
然后改造一下UIDrawCall的OnWillRenderObject函数
//UIDrawCall.csvoid OnWillRenderObject(){ ... if(urrentPanel.hasClipping) { float angle =0f; Vector4 cr = currentPanel.drawCallClipRange; if(currentPanel.parentClipPanel != null && currentPanel.parentClipPanel != panel && currentPanel.parentClipPanel.hasClipping) { //限制不能超过父Panel的裁剪区域 Vector4 parentCR = currentPanel.parentClipPanel.drawCallClipRange; Vector3 pos = currentPanel.parentClipPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.position); parentCR.x -= pos.x; parentCR.y -= pos.y; float pXMin = parentCR.x - parentCR.z; float pXMax = parentCR.x + parentCR.z; float pYMin = parentCR.y - parentCR.w; float pYMax = parentCR.y + parentCR.w; float xMin = cr.x - cr.z; if (xMin < pXMin) { xMin = pXMin; } float xMax = (cr.x + cr.z); if (xMax > pXMax) { xMax = pXMax; } float yMin = (cr.y - cr.w); if (yMin < pYMin) { yMin = pYMin; } float yMax = (cr.y + cr.w); if (yMax > pYMax) { yMax = pYMax; } //重现计算中心点 cr.x = (xMin + xMax) / 2; cr.y = (yMin + yMax) / 2; cr.z = (xMax - xMin) / 2; cr.w = (yMax - yMin) / 2; } //Clipping regions past the first one need additional math ... } ...}
然后再改一下UIPanelInspetor
//UIPanelInspector.csprotected override bool ShouldDrawProperties(){ ... if(mPanel.clipping == UIDrawCall.Clipping.SoftClip) { ... NGUIEditorTools.DrawProperty("应用父Panel裁剪",serializedObjet,"parentClipPanel",GUILayout.MinWidth(100f)); }}
然后,当有UIPanel嵌套裁剪的时候,只需要把子UIPanel的parentClipPanel设为父UIPanel即可。
转载地址:https://linxinfa.blog.csdn.net/article/details/86669016 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月18日 13时57分58秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!