使用 UGUI 制作背包的时候。同事发现假设背包中加入了大量的物品。比方两百个。Unity就会出错,提示
Canvas element contains more than 65535 vertices. This is not supported 。意思就是 Canvas以下的顶点数过多。

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

例如以下图:

可是一个物品 的GameObject 难道有300个顶点不成?

不看不知道一看吓一跳,一个物品 竟然有 500个Verts。

在对 物品的 GameObject 以下的子 物体 一个一个 禁用然后查看顶点后发现,当把Text 禁用之后,Verts 会锐减几百个。

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

没有禁用 Text 时的顶点数

禁用 Text 的顶点数

于是。继续,在Text 上发现挂了 Outline 组件,把Outline 禁用之后,发现Verts 锐减。才确定是 Outline的原因。

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

禁用Outline 之前

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHV1dHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

禁用Outline 之后

Ok,就是 Outline的原因。

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

那为什么Outline 会添加这么多顶点数呢?

查看UGUI的 Outline的源码,例如以下:

using System.Collections.Generic;

namespace UnityEngine.UI
{
[AddComponentMenu("UI/Effects/Outline", 15)]
public class Outline : Shadow
{
protected Outline()
{} public override void ModifyVertices(List<UIVertex> verts)
{
if (!IsActive())
return; var start = 0;
var end = verts.Count;
ApplyShadow(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y); start = end;
end = verts.Count;
ApplyShadow(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y); start = end;
end = verts.Count;
ApplyShadow(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y); start = end;
end = verts.Count;
ApplyShadow(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y);
}
}
}

代码中的意思是 运行 ApplyShadow 4次。并且传过去的參数各自是 (x,y) (x,-y) (-x,y) (-x,-y) 。

看到这四个值,好像感觉到了什么。

来看看 这个函数做了什么。

protected void ApplyShadow(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
{
UIVertex vt; var neededCpacity = verts.Count * 2;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity; for (int i = start; i < end; ++i)
{
vt = verts[i];
verts.Add(vt); Vector3 v = vt.position;
v.x += x;
v.y += y;
vt.position = v;
var newColor = color;
if (m_UseGraphicAlpha)
newColor.a = (byte)((newColor.a * verts[i].color.a) / 255);
vt.color = newColor;
verts[i] = vt;
}
}

简单的就是说:

1、把原来的顶点 Copy出来一份。而且依据编辑器中设置的偏移量 来设置 Copy 出来的顶点的位置

2、依据编辑器中设置的 Shadow 颜色设置定点色

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

运行了4次,每一次都Copy了一份顶点。

。这难道是 复制了4份 Text ?这和我们自己再另外加入 4个Text性质差点儿相同吧。。

想到一个非常好验证的方法。把偏移量设置的非常大,我们来看看。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHV1dHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

我们知道 1个字 = 1张图片 = 2个三角形 =4 个顶点。

本来用 Text 。定点数量就会比較多,而 Outline 却在这个 值上 乘以 5 。

所以

慎用 Outline

转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn

project下载:

http://pan.baidu.com/s/1c02KTfq
http://download.csdn.net/detail/cp790621656/8779193

最新文章

  1. 设计数据库字段或者java中使用boolean型时需谨慎
  2. python实现curl功能
  3. Coursera台大机器学习技法课程笔记01-linear hard SVM
  4. GL_GL系列 - 会计期间管理分析(案例)
  5. LA 4727
  6. 浮点数精确表示,java陷阱
  7. [转]Laravel 4之控制器
  8. ORACLE SEQUENCE用法 (自增长)
  9. less学习笔记(一)
  10. C++ - 复制容器(container)的元素至还有一个容器
  11. 使用R的注意事项
  12. 2、Kafka架构
  13. accept:Invalid Argument
  14. sklearn数据预处理
  15. redhat修改网卡名称
  16. JoyOI1940 创世纪
  17. 【译】第七篇 SQL Server代理作业活动监视器
  18. skynet1.0阅读笔记2_skynet的消息投递skynet.call
  19. Configuring Oracle E-Business Suite Integrated SOA Gateway Release 12.1.2 and Release 12.1.3 in a Multinode Environment (Doc ID 1081100.1)
  20. Dalvik与JVM区别

热门文章

  1. Kotlin:数组、字符串模板
  2. mysql 修改表的字段
  3. CAD交互绘制文字(com接口)
  4. cuda输出
  5. html嵌入pdf &amp;&amp; html嵌入多媒体文件,word,flash,pdf,音视频
  6. Android反编译初步
  7. 【C语言】控制台窗口图形界面编程(五):文本移动
  8. win10 专业版 安装tornado 的步骤
  9. c++基础_特殊回文数
  10. tomcat idea 报权限错误