如何进行NGUI战斗飘字及界面优化

发布时间:2022-01-14 09:07:30 作者:柒染
来源:亿速云 阅读:203

本篇文章为大家展示了如何进行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 >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大量减少,尤其是飘字的。

上述内容就是如何进行NGUI战斗飘字及界面优化,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 【unity实用技能】NGUI图片镜像
  2. NGUI HUD Text怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ngui

上一篇:Singleton Class的对象模型设计有哪些

下一篇:springboot整合quartz定时任务框架的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》