NGUI战斗飘字及界面优化

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大量减少,尤其是飘字的,希望大家能指教更多的优化方法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值