有时候有这样的需求,在一个滚动的列表里面,item中又有滚动列表,也就是UIPanel的嵌套裁剪。
而NGUI中,子UIPanel不会被父UIPanel正常裁剪,需要改造一下。
首先,在UIPanel中,增加一个parentClipPanel成员
//UIPanel.cs
[Serializefield]
public UIPanel parentClipPanel;
然后改造一下UIDrawCall的OnWillRenderObject函数
//UIDrawCall.cs
void 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.cs
protected override bool ShouldDrawProperties()
{
...
if(mPanel.clipping == UIDrawCall.Clipping.softClip)
{
...
NGUIEditorTools.DrawProperty("应用父Panel裁剪",serializedobjet,"parentClipPanel",GUILayout.MinWidth(100f));
}
}
然后,当有UIPanel嵌套裁剪的时候,只需要把子UIPanel的parentClipPanel设为父UIPanel即可。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。