Example #1
0
    /// <summary>
    /// 更新动图 :将需要动图更新的地方,单独提出来更新(不变的就不更新)(优化4)
    /// </summary>
    void ChangeSprites()
    {
        listSprite.Clear();                        //容器要清空,性能巨提升(优化5)
        int listTagInfo_Count = listTagInfo.Count; //List.Count  循环的话 消耗也比较大,所以做个函数内局部缓存(优化6)
        int spriteAsset_ListSpriteInfo_Count = m_spriteAsset.listSpriteInfo.Count;

        for (int i = 0; i < listTagInfo_Count; i++)
        {
            listTagInfo_i = listTagInfo[i];
            for (int j = 0; j < spriteAsset_ListSpriteInfo_Count; j++)
            {
                //通过标签的名称去索引spriteAsset里所对应的sprite的名称
                if (listTagInfo[i].ID == m_spriteAsset.listSpriteInfo[j].ID)//这儿用字符串比较,消耗比较大 所以换做ID来判断
                {
                    if (listTagInfo_i.count >= emojiId)
                    {
                        spriteRect = m_spriteAsset.listSpriteInfo[emojiId + m_spriteAsset.listSpriteInfo[j].ID].rect;
                    }
                    else
                    {
                        spriteRect = m_spriteAsset.listSpriteInfo[listTagInfo_i.count + m_spriteAsset.listSpriteInfo[j].ID].rect;
                    }
                }
            }
            Vector2      texSize    = new Vector2(m_spriteAsset.texSource.width, m_spriteAsset.texSource.height);
            ExSpriteInfo tempSprite = tempSprites[i];
            tempSprite.uv    = new Vector2[4];
            tempSprite.uv[0] = new Vector2(spriteRect.x / texSize.x, spriteRect.y / texSize.y);
            tempSprite.uv[1] = new Vector2((spriteRect.x + spriteRect.width) / texSize.x, (spriteRect.y + spriteRect.height) / texSize.y);
            tempSprite.uv[2] = new Vector2((spriteRect.x + spriteRect.width) / texSize.x, spriteRect.y / texSize.y);
            tempSprite.uv[3] = new Vector2(spriteRect.x / texSize.x, (spriteRect.y + spriteRect.height) / texSize.y);

            listSprite.Add(tempSprite);
        }
    }
Example #2
0
    /// <summary>
    /// 解析quad标签  主要清除quad乱码 获取表情的位置
    /// </summary>
    /// <param name="verts"></param>
    void CalcQuadTag(IList <UIVertex> verts)
    {
        //通过标签信息来设置需要绘制的图片的信息
        if (null == listSprite)
        {
            listSprite = new List <ExSpriteInfo>();
        }
        else
        {
            listSprite.Clear();
        }
        for (int i = 0; i < listTagInfo.Count; i++)
        {
            ExSpriteInfo tempSprite = new ExSpriteInfo();
            // tempSprite = new ExSpriteInfo();

            //获取表情的第一个位置,则计算他的位置为quad占位的第四个点   顶点绘制顺序:
            //                                                                       0    1
            //                                                                       3    2
            SpriteTagInfo listTagInfo_i = listTagInfo[i];
            tempSprite.textpos = verts[((listTagInfo_i.index + 1) * 4) - 1].position;
            //Debug.Log("listTagInfo_i.index "+ listTagInfo_i.index + "listTagInfo.Count " + listTagInfo.Count);
            //设置图片的位置
            tempSprite.vertices    = new Vector3[4];
            tempSprite.vertices[0] = new Vector3(0, 0, 0) + tempSprite.textpos;
            tempSprite.vertices[1] = new Vector3(listTagInfo_i.size.x, listTagInfo_i.size.y, 0) + tempSprite.textpos;
            tempSprite.vertices[2] = new Vector3(listTagInfo_i.size.x, 0, 0) + tempSprite.textpos;
            tempSprite.vertices[3] = new Vector3(0, listTagInfo_i.size.y, 0) + tempSprite.textpos;
            tempSprites.Add(tempSprite);
            //计算其uv  //spriteRect只是需要一个uv模板,具体是谁的并不关心
            //spriteRect = m_spriteAsset.listSpriteInfo[0].rect;
            for (int j = 0; j < m_spriteAsset.listSpriteInfo.Count; j++)
            {
                //通过标签的名称去索引spriteAsset里所对应的sprite的名称
                if (listTagInfo_i.name == m_spriteAsset.listSpriteInfo[j].name)//这里用emoji的名称判断,然后记录ID,供后面用ID对比更新.(之所以不直接用ID判断是为了,可以通过发送#+名称 来发送表情) (优化3)
                {
                    listTagInfo_i.ID = m_spriteAsset.listSpriteInfo[j].ID;
                    spriteRect       = m_spriteAsset.listSpriteInfo[j].rect;
                }
                Vector2 texSize = new Vector2(m_spriteAsset.texSource.width, m_spriteAsset.texSource.height);
                tempSprite.uv    = new Vector2[4];
                tempSprite.uv[0] = new Vector2(spriteRect.x / texSize.x, spriteRect.y / texSize.y);
                tempSprite.uv[1] = new Vector2((spriteRect.x + spriteRect.width) / texSize.x, (spriteRect.y + spriteRect.height) / texSize.y);
                tempSprite.uv[2] = new Vector2((spriteRect.x + spriteRect.width) / texSize.x, spriteRect.y / texSize.y);
                tempSprite.uv[3] = new Vector2(spriteRect.x / texSize.x, (spriteRect.y + spriteRect.height) / texSize.y);

                //声明三角顶点所需要的数组
                tempSprite.triangles = new int[6];
                listSprite.Add(tempSprite);
            }
        }
    }