1. 飘字问题:飘字会有Alpha的渐变,当渐变到0的时候,会触发UIPanel的Rebuild
解决问题:查找哪些地方触发了Rebuild,在UIPanel中添加日志代码,查找出对应的UI控件,将Animation中的Alpha的最小值修改为大于0.001,并将label的位置设置到无穷远处,同时不要做显隐操作
public UIDrawCall FindDrawCall (UIWidget w)
{
Material mat = w.material;
Texture tex = w.mainTexture;
int depth = w.depth;
for (int i = 0; i < drawCalls.Count; ++i)
{
UIDrawCall dc = drawCalls[i];
int dcStart = (i == 0) ? int.MinValue : drawCalls[i - 1].depthEnd + 1;
int dcEnd = (i + 1 == drawCalls.Count) ? int.MaxValue : drawCalls[i + 1].depthStart - 1;
if (dcStart <= depth && dcEnd >= depth)
{
if (dc.baseMaterial == mat && dc.mainTexture == tex)
{
if (w.isVisible)
{
w.drawCall = dc;
if (w.hasVertices) dc.isDirty = true;
return dc;
}
}
else mRebuild = true;
if (mRebuild)
{
DebugShow(w);
}
return null;
}
}
DebugShow(w);
mRebuild = true;
return null;
}
private void DebugShow(UIWidget w)
{
string path = "";
Transform t = w.transform;
while(null != t)
{
path += t.transform.name + "/";
t = t.parent;
}
Debug.LogWarning("<color=white>" + path + "time:" + Time.time+ "</color>");
}
查找出对应的UI控件,将Animation中的Alpha的最小值修改为大于0.001(UIWidget),及TweenAlpha动画中做同样的修改
/// <summary>
/// Update the widget's visibility and final alpha.
/// </summary>
public override void Invalidate (bool includeChildren)
{
mChanged = true;
mAlphaFrameID = -1;
if (panel != null)
{
bool vis = (hideIfOffScreen || panel.hasCumulativeClipping) ? panel.IsVisible(this) : true;
<span style="color:#3366ff;">UpdateVisibility(CalculateCumulativeAlpha(Time.frameCount) > 0.001f</span>, vis);
UpdateFinalAlpha(Time.frameCount);
if (includeChildren) base.Invalidate(true);
}
}
2. 战斗界面 由技能倒计时、连击数等组成
1). 修改倒计时结束时候的label不隐藏,改为设置为空,设置的string 方法使用U3d内存优化(一)之UILabel使用String的问题 。
2). 对经常刷新的区域单独加UIPanel
3). 尽量减少对界面元素的显隐操作,以减少UIpanel的Rebuild过程,从而减少DrawCall
经测试 UIPanel的 Rebuild大量减少,尤其是飘字的,希望大家能指教更多的优化方法