uGUI Text富文本的顶点数优化
来源:互联网 发布:java技术 编辑:程序博客网 时间:2024/06/05 11:11
uGUI的Text组件勾选Rich Text复选框后支持富文本,支持的富文本标签可以参见https://docs.unity3d.com/Manual/StyledText.html
当文本中的富文本标签非常多时,会发现虽然显示的字符数很少,但是生成的顶点数却非常多,有时候会多到报错
搜索发现是unity的问题,在根据字符生成顶点数时,没有对富文本做优化,导致富文本标签也会生成顶点数,生成了大量重复的顶点
https://issuetracker.unity3d.com/issues/ui-rich-text-hidden-characters-are-taken-into-account-in-statistics-tris-and-verts-count?_ga=2.103842752.1929093838.1495006719-913292091.1467768613
一个字符会生成6个顶点,6个顶点构成2个三角面,可以将下面的脚本挂到Text组件下,将重复的三角面过滤掉
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class UIVertexOptimize : BaseMeshEffect
{
struct Triangle
{
public UIVertex v1;
public UIVertex v2;
public UIVertex v3;
}
List<UIVertex> verts = new List<UIVertex>();
public override void ModifyMesh(VertexHelper vh)
{
vh.GetUIVertexStream(verts);
Debug.Log(verts.Count);
OptimizeVert(ref verts);
Debug.Log(verts.Count);
vh.Clear();
vh.AddUIVertexTriangleStream(verts);
}
void OptimizeVert(ref List<UIVertex> vertices)
{
List<Triangle> tris = new List<Triangle>();
for (int i = 0; i < vertices.Count - 3; i += 3)
{
tris.Add(new Triangle() { v1 = vertices[i], v2 = vertices[i + 1], v3 = vertices[i + 2] });
}
vertices = tris.Distinct().SelectMany(tri =>
new[]{
tri.v1,
tri.v2,
tri.v3
}).ToList();
}
}
阅读全文
0 0
- uGUI Text富文本的顶点数优化的优化
- uGUI Text富文本的顶点数优化
- UGUI富文本
- Text使用富文本
- 查看uGUI UI组件生成的顶点数
- UGUI Text组件实际文本宽高的获取
- Unity富文本(UGUI/NGUI/Debug)
- UGUI 设置Text控件文本颜色
- 【Unity】UGUI Text文本描线。。
- UGUI研究院之Text文本渐变
- 【Unity&UGUI】代码控制 text文本
- Rich Text Processing富文本处理
- [微信小程序] rich-text富文本
- Unity自学之路——UGUI 富文本
- Lable的富文本
- Lable的富文本
- 富文本的使用
- UGUI—ScrollBar与Image以及Text实现文本的可移动
- 告别龟速:基于Chrome插件的百度云下载链接提取
- Android 异步任务AsyncTask
- 【网络】Select服务器的实现
- 用户名(手机号)和密码的后台校验
- Sybase、DB2数据导入导出
- uGUI Text富文本的顶点数优化
- 把对象先存起来,后面再用
- C/C++中const与define应用上该怎么取舍
- 数据库中的游标
- 微信小程序 收藏成功提示(九)
- 递归
- 机器学习:误差分析
- Building Graphs
- 妈妈回忆录1