千家信息网

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

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,本篇文章为大家展示了如何进行NGUI战斗飘字及界面优化,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。1. 飘字问题:飘字会有Alpha的渐变,当渐变到0的时候
千家信息网最后更新 2025年02月04日如何进行NGUI战斗飘字及界面优化

本篇文章为大家展示了如何进行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("" + path + "time:" + Time.time+ "");    }

查找出对应的UI控件,将Animation中的Alpha的最小值修改为大于0.001(UIWidget),及TweenAlpha动画中做同样的修改

    ///         /// Update the widget's visibility and final alpha.        ///          public override void Invalidate (bool includeChildren)        {                mChanged = true;                mAlphaFrameID = -1;                 if (panel != null)                {                        bool vis = (hideIfOffScreen || panel.hasCumulativeClipping) ? panel.IsVisible(this) : true;                        UpdateVisibility(CalculateCumulativeAlpha(Time.frameCount) > 0.001f, 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战斗飘字及界面优化,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。

0