在做背包、商城等界面的时候不管是NGUI还是UGUI,都会遇到特效在格子上滑动后特效不会隐藏这种问题
我的解决方法是利用shader可以实现剔除的效果
- 求出容器的边界
- 把边界传给每一个条目的shader
- 判断顶点坐标是否超出边界坐标,把超出的部分透明度设为0
private Transform content;
private Transform m_canvas;
private RectTransform m_rectTrans; //容器的rect
private float m_halfWidth;
private float m_halfHeight;
ParticleSystem[] particles;
void Start()
{
m_canvas = GameObject.Find("Canvas").transform;
content = gameObject.transform.Find("Viewport/Content");
particles = content.GetComponentsInChildren<ParticleSystem>();
m_rectTrans = gameObject.GetComponent<RectTransform>();
//计算容器宽高的一半,值