示例#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);
        }
    }
示例#2
0
    /// <summary>
    /// 在设置顶点时调用
    /// </summary>
    public override void SetVerticesDirty()
    {
        base.SetVerticesDirty();
        m_OutputText = GetOutputText();

        //解析标签属性
        foreach (Match match in m_spriteTagRegex.Matches(text))
        {
            SpriteTagInfo tempSpriteTag = new SpriteTagInfo();
            tempSpriteTag.name  = match.Groups[1].Value;
            tempSpriteTag.index = match.Index;
            //print("match.Index" + match.Index);
            //tempSpriteTag.size = new Vector2(float.Parse(match.Groups[2].Value)*float.Parse(match.Groups[3].Value), float.Parse(match.Groups[2].Value)*float.Parse(match.Groups[4].Value));
            tempSpriteTag.size   = new Vector2(float.Parse(match.Groups[2].Value), float.Parse(match.Groups[2].Value));
            tempSpriteTag.Length = match.Length;
            if (null != match.Groups[3])
            {
                tempSpriteTag.count = int.Parse(match.Groups[3].Value);
            }
            listTagInfo.Add(tempSpriteTag);
            if (tempSpriteTag.count > 1 && !haveDynamicEmoji)
            {
                haveDynamicEmoji = true;//count=1或无 则为静态表情  (优化2)
            }
        }
    }
示例#3
0
    private string GetOutputText()
    {
        _imagesTagInfoList.Clear();
        IList <UIVertex> verts       = cachedTextGenerator.verts;
        StringBuilder    textBuilder = new StringBuilder();
        int textIndex = 0;

        foreach (Match match in _inputRegex.Matches(text))
        {
            int tempId = 0;
            if (!string.IsNullOrEmpty(match.Groups[1].Value) && !match.Groups[1].Value.Equals("-"))
            {
                tempId = int.Parse(match.Groups[1].Value);
            }
            string tempTag = match.Groups[2].Value;
            //更新超链接
            if (tempId < 0)
            {
                textBuilder.Append(text.Substring(textIndex, match.Index - textIndex));
                textBuilder.Append("<color=blue>");
                int _startIndex = textBuilder.Length * 4;
                textBuilder.Append("[" + match.Groups[2].Value + "]");
                int _endIndex = textBuilder.Length * 4 - 2;
                textBuilder.Append("</color>");

                var hrefInfo = new HrefInfo
                {
                    id         = Mathf.Abs(tempId),
                    startIndex = _startIndex, // 超链接里的文本起始顶点索引
                    endIndex   = _endIndex,
                    name       = match.Groups[2].Value
                };
                _listHrefInfos.Add(hrefInfo);
            }
            //更新表情
            else
            {
                textBuilder.Append(text.Substring(textIndex, match.Index - textIndex));

                SpriteAsset      spriteAsset = SpriteFaceCache.GetAsset(tempId);
                SpriteInforGroup tempGroup   = SpriteFaceCache.GetAsset(tempId, tempTag);
                float            imgSize     = spriteAsset == null ? 24.0f : spriteAsset.size;
                float            imgWidth    = spriteAsset == null ? 1.0f : spriteAsset.width;

                int vertexIndex = textBuilder.Length * 4;
                textBuilder.Append(@"<quad size=" + imgSize + " width=" + imgWidth + " />");
                SpriteTagInfo spInfo = new SpriteTagInfo();
                spInfo.vertId = vertexIndex;
                spInfo.faceId = tempId;
                spInfo.action = tempTag;
                spInfo.size   = new Vector2(imgSize * imgWidth, imgSize);
                _imagesTagInfoList.Add(spInfo);
            }

            textIndex = match.Index + match.Length;
        }

        textBuilder.Append(text.Substring(textIndex, text.Length - textIndex));
        return(textBuilder.ToString());
    }
示例#4
0
    private void SpriteTagHandler()
    {
        if (mAnimSpriteInfoList == null || mAnimSpriteInfoList.Count == 0)
        {
            return;
        }

        if (mAnimSpiteTagList == null || mAnimSpiteTagList.Count == 0)
        {
            return;
        }

        if (mSpriteVertPositionList == null)
        {
            mSpriteVertPositionList = new List <UIVertex>();
        }

        UnityEngine.Profiling.Profiler.BeginSample("inlineText SpriteTagHandler Position");

        for (int i = 0; i < mAnimSpiteTagList.Count; i++)
        {
            SpriteTagInfo tempTagInfo = mAnimSpiteTagList[i];
            if (!tempTagInfo.IsValid())
            {
                continue;
            }

            int vertexIndex = ((tempTagInfo.VertextIndex + 1) * 4) - 1;
            if (vertexIndex >= mVertexHelperRef.currentVertCount || vertexIndex < 0)
            {
                // Debug.LogError("CalcQuadTag Vertex Index is out of range:" + j);
                continue;
            }

            if (i + 1 > mSpriteVertPositionList.Count)
            {
                int needCount = i + 1 - mSpriteVertPositionList.Count;
                for (int m = 0; m < needCount; ++m)
                {
                    mSpriteVertPositionList.Add(new UIVertex());
                }
            }
            UIVertex tempVer = new UIVertex();
            mVertexHelperRef.PopulateUIVertex(ref tempVer, vertexIndex);
            mSpriteVertPositionList[i] = tempVer;
        }
        UnityEngine.Profiling.Profiler.EndSample();

        CalcQuadTag(mSpriteVertPositionList);

        if (mSpriteManager != null)
        {
            mSpriteManager.UpdateSpriteAnimInfos(this, mAnimSpriteInfoList);
        }
    }
示例#5
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);
            }
        }
    }
示例#6
0
    protected void UpdateQuadImage()
    {
        if (_prefabObj == null)
        {
            _faceAction = transform.Find("FaceActionCon");
            _prefabObj  = AssetDatabase.LoadMainAssetAtPath(PathManager.GetResPathByName("Prefabs", "FaceActoin.prefab", "UILib"));
        }
        for (int i = 0; i < _imagesTagInfoList.Count; i++)
        {
            SpriteTagInfo spInfo = _imagesTagInfoList[i];

            if (i >= _imagesPool.Count)
            {
                GameObject       go   = Object.Instantiate(_prefabObj) as GameObject;
                SpriteFaceAction face = go.GetComponent <SpriteFaceAction>();
                face.setIndexAction(spInfo.faceId, spInfo.action);
                var rt = go.GetComponent <RectTransform>();
                if (rt)
                {
                    rt.SetParent(_faceAction, false);
                    rt.localPosition = spInfo.pos;
                    rt.localRotation = Quaternion.identity;
                    rt.localScale    = Vector3.one;
                    rt.sizeDelta     = spInfo.size;
                }
                _imagesPool.Add(go);
            }
            else
            {
                GameObject       go   = _imagesPool[i];
                SpriteFaceAction face = go.GetComponent <SpriteFaceAction>();
                face.setIndexAction(spInfo.faceId, spInfo.action);
                go.SetActive(true);
            }
        }
        for (var i = _imagesTagInfoList.Count; i < _imagesPool.Count; i++)
        {
            if (_imagesPool[i])
            {
                _imagesPool[i].SetActive(false);
            }
        }
    }
示例#7
0
        private string ParseText()
        {
            string linkedtext = GetLinkedText(OriginalText);

            //先对文本中的超链接进行解析。
            //然后再解析表情标记。
            int lastpos = 0;

            sb.Length = 0;
            foreach (Match match in m_originTagRegex.Matches(linkedtext))
            {
                SpriteTagInfo tempSpriteTag = new SpriteTagInfo();
                string        str           = match.Groups[0].Value;
                sb.Append(linkedtext.Substring(lastpos, match.Index - lastpos));
                tempSpriteTag.start_index = sb.Length;
                lastpos = match.Index + match.Length;
                tempSpriteTag.sprite_name  = str.Substring(2, 3);
                tempSpriteTag.display_size = new Vector2(fontSize, fontSize);
                sti.add(tempSpriteTag);
                string imgstr = string.Format("<quad name={0} size={1} width=1 />", tempSpriteTag.sprite_name, fontSize);
                sb.Append(imgstr);

                //在这里要注意到因为[/ddd]被替换成更长的形式。所以要去更改链接索引。
                //即lastpos以前从[/ddd]到<quad>。
                int deta = (imgstr.Length - 6) * 4;
                foreach (var hrefInfo in m_HrefInfos)
                {
                    if (hrefInfo.startpos_linkedtext < lastpos)
                    {
                        continue;
                    }

                    hrefInfo.startIndex += deta;
                    hrefInfo.endIndex   += deta;
                }
            }

            sb.Append(linkedtext.Substring(lastpos));
            return(sb.ToString());
        }
示例#8
0
    //UGUIText不支持<quad/>标签,表现为乱码, 将uv全设置为0
    private void ClearQuadUv(IList <UIVertex> verts)
    {
        if (mAnimSpiteTagList == null || mAnimSpiteTagList.Count == 0)
        {
            return;
        }

        UnityEngine.Profiling.Profiler.BeginSample("inlineText Cal ClearQuadUv");

        UIVertex tempVertex;

        for (int i = 0; i < mAnimSpiteTagList.Count; i++)
        {
            SpriteTagInfo temp = mAnimSpiteTagList[i];
            if (!temp.IsValid())
            {
                continue;
            }

            int startIndex = temp.VertextIndex * 4;
            int endIndex   = startIndex + 4;

            for (int m = startIndex; m < endIndex; m++)
            {
                if (m >= verts.Count)
                {
                    continue;
                }

                tempVertex     = verts[m];
                tempVertex.uv0 = Vector2.zero;
                verts[m]       = tempVertex;
            }
        }
        UnityEngine.Profiling.Profiler.EndSample();
    }
示例#9
0
 private void ClearQuadUVs(IList <UIVertex> verts)
 {
     for (int i = 0; i < _imagesTagInfoList.Count; i++)
     {
         SpriteTagInfo spInfo = _imagesTagInfoList[i];
         if ((spInfo.vertId + 4) > verts.Count)
         {
             continue;
         }
         for (int k = spInfo.vertId; k < spInfo.vertId + 4; k++)
         {
             //清除乱码
             UIVertex tempVertex = verts[k];
             tempVertex.uv0 = Vector2.zero;
             verts[k]       = tempVertex;
         }
         if (i < _imagesPool.Count)
         {
             GameObject    go = _imagesPool[i];
             RectTransform rt = go.GetComponent <RectTransform>();
             rt.anchoredPosition = new Vector2(verts[spInfo.vertId + 3].position.x + rt.sizeDelta.x / 2, verts[spInfo.vertId + 3].position.y + rt.sizeDelta.y / 2);
         }
     }
 }
示例#10
0
    private string GetOutputText()
    {
        _SpriteInfo = new Dictionary <int, SpriteTagInfo>();
        StringBuilder _textBuilder = new StringBuilder();
        int           _textIndex   = 0;

        foreach (Match match in _InputTagRegex.Matches(text))
        {
            int _tempID = 0;
            if (!string.IsNullOrEmpty(match.Groups[1].Value))
            {
                _tempID = int.Parse(match.Groups[1].Value);
            }
            string _tempTag = match.Groups[2].Value;
            //更新超链接
            if (_tempID == -1)
            {
                _textBuilder.Append(text.Substring(_textIndex, match.Index - _textIndex));
                _textBuilder.Append("<color=blue>");
                int _startIndex = _textBuilder.Length * 4;
                _textBuilder.Append("[" + match.Groups[2].Value + "]");
                int _endIndex = _textBuilder.Length * 4 - 2;
                _textBuilder.Append("</color>");

                var hrefInfo = new HrefInfo
                {
                    startIndex = _startIndex, // 超链接里的文本起始顶点索引
                    endIndex   = _endIndex,
                    name       = match.Groups[2].Value
                };
                _ListHrefInfos.Add(hrefInfo);
            }
            //更新表情
            else
            {
                if (!_InlineManager._IndexSpriteInfo.ContainsKey(_tempID) ||
                    !_InlineManager._IndexSpriteInfo[_tempID].ContainsKey(_tempTag))
                {
                    continue;
                }
                SpriteInforGroup _tempGroup = _InlineManager._IndexSpriteInfo[_tempID][_tempTag];

                _textBuilder.Append(text.Substring(_textIndex, match.Index - _textIndex));
                int _tempIndex = _textBuilder.Length * 4;
                _textBuilder.Append(@"<quad size=" + _tempGroup.size + " width=" + _tempGroup.width + " />");

                SpriteTagInfo _tempSpriteTag = new SpriteTagInfo
                {
                    _ID   = _tempID,
                    _Tag  = _tempTag,
                    _Size = new Vector2(_tempGroup.size * _tempGroup.width, _tempGroup.size),
                    _Pos  = new Vector3[4],
                    _UV   = _tempGroup.listSpriteInfor[0].uv
                };
                if (!_SpriteInfo.ContainsKey(_tempIndex))
                {
                    _SpriteInfo.Add(_tempIndex, _tempSpriteTag);
                }
            }

            _textIndex = match.Index + match.Length;
        }

        _textBuilder.Append(text.Substring(_textIndex, text.Length - _textIndex));
        return(_textBuilder.ToString());
    }
示例#11
0
    private string GetOutputText()
    {
        if (null == _SpriteInfo)
        {
            _SpriteInfo = new Dictionary <int, SpriteTagInfo>();
        }
        StringBuilder _textBuilder = new StringBuilder();
        int           _textIndex   = 0;

        var matches = _InputTagRegex.Matches(text);

        foreach (Match match in matches)
        {
            int _tempID = 0;
            if (!string.IsNullOrEmpty(match.Groups[1].Value) && !match.Groups[1].Value.Equals("-"))
            {
                _tempID = int.Parse(match.Groups[1].Value);
            }
            string _tempTag = match.Groups[2].Value;
            //更新超链接
            if (_tempID < 0)
            {
                _textBuilder.Append(text.Substring(_textIndex, match.Index - _textIndex));
                _textBuilder.Append("<color=blue>");
                int _startIndex = _textBuilder.Length * 4;

                _textBuilder.Append("[");
                _textBuilder.Append(match.Groups[2].Value);
                _textBuilder.Append("]");

                int _endIndex = _textBuilder.Length * 4 - 2;
                _textBuilder.Append("</color>");

                var hrefInfo = new HrefInfo
                {
                    id         = Mathf.Abs(_tempID),
                    startIndex = _startIndex, // 超链接里的文本起始顶点索引
                    endIndex   = _endIndex,
                    name       = match.Groups[2].Value
                };
                _ListHrefInfos.Add(hrefInfo);
            }
            else  //更新表情
            {
                if (!_IndexSpriteInfo.ContainsKey(_tempID) ||
                    !_IndexSpriteInfo[_tempID].ContainsKey(_tempTag))
                {
                    continue;
                }
                SpriteInfoGroup _tempGroup = _IndexSpriteInfo[_tempID][_tempTag];

                _textBuilder.Append(text.Substring(_textIndex, match.Index - _textIndex));
                int _tempIndex = _textBuilder.Length * 4;// 每个字符四个顶点,用顶点的起始来索引表情

                // 使用 quad 标记来表示表情占位符
                _textBuilder.Append(@"<quad size=");
                _textBuilder.Append(_tempGroup.size);
                _textBuilder.Append(" width=");
                _textBuilder.Append(_tempGroup.width);
                _textBuilder.Append(" />");

                if (!_SpriteInfo.ContainsKey(_tempIndex))
                {
                    SpriteTagInfo _tempSpriteTag = new SpriteTagInfo
                    {
                        _ID   = _tempID,
                        _Tag  = _tempTag,
                        _Size = new Vector2(_tempGroup.size * _tempGroup.width, _tempGroup.size),
                        _Pos  = new Vector3[4],                 // 表情的四个顶点
                        _UV   = _tempGroup.listSpriteInfo[0].uv // 默认显示表情第一帧
                    };
                    _SpriteInfo.Add(_tempIndex, _tempSpriteTag);
                }
            }

            _textIndex = match.Index + match.Length;
        }

        _textBuilder.Append(text.Substring(_textIndex, text.Length - _textIndex));
        return(_textBuilder.ToString());
    }
示例#12
0
        void DrawSprite(VertexHelper toFill)
        {
            //public override void SetVerticesDirty()
            //在这个时间点上还不可以操纵它所在的GameObject。
            //这个方法的执行时机是顶点变化了,但并不一定是内容发生了变化.
            //这个方法[先于]Awake,且执行了[很多]遍,但是OnPopulateMesh UpdateGeometry保证在Awake enable start 之后。
            //m_spriteTagRegex =
            //new Regex(@"<quad name=(.+?) size=(\d*\.?\d+%?) width=(\d*\.?\d+%?) />", RegexOptions.Singleline);
            if (m_ImageFont == null || sti == null)
            {
                return;
            }

            Vector3[] vertex_buffer = new Vector3[sti.Count * 4];
            int[]     index_buffer  = new int[sti.Count * 6];
            Vector2[] uv_buffer     = new Vector2[sti.Count * 4];

            int[] indexorder = { 0, 1, 2, 2, 3, 0 };

            //float[] uvorder = { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };
            //现在填充UI网格数据并间接交给image2的canvasrender!!!

            for (int image_index = 0; image_index < sti.Count; image_index++)
            {
                float         deta_down = fontSize * 0.1f;
                SpriteTagInfo curtag    = sti[image_index];
                UIVertex      curVertex = new UIVertex();
                int           basepos   = curtag.start_index * 4;
                if (basepos + 3 >= toFill.currentVertCount)
                {
                    print("spritetag.endIndex >= toFill.currentVertCount");
                    break;
                }

                int vertex_start = image_index * 4;
                int index_start  = image_index * 6;
                int uv_start     = image_index * 4;
                for (int i = 0; i < 6; i++)
                {
                    index_buffer[index_start + i] = indexorder[i] + vertex_start;
                }

                int number = 1;
                number = int.Parse(curtag.sprite_name);
                if (number < 0 || number > m_ImageFont.data.Length)
                {
                    number = 1;
                }

                //默认0号资源。
                var cur_sprite = m_ImageFont.data[number - 1].Sprite;

                //cur_sprite中的uv没规律。
                if (cur_sprite != null)
                {
                    CalcUV(cur_sprite.uv, uv_buffer, uv_start);
                }

                for (int i = 0; i < 4; i++)
                {
                    int pos = basepos + i;
                    toFill.PopulateUIVertex(ref curVertex, pos);

                    //if (pos >= toFill.currentVertCount)
                    //print(string.Format("序号:{0}  i={1} 总顶点数{2}  当前偏移{3}",image_index,i,toFill.currentVertCount,pos));
                    vertex_buffer[vertex_start + i] = curVertex.position;

                    //这里将默认占位网格整体下移 原因在于预留确实为fontsize大小,但是偏高。
                    vertex_buffer[vertex_start + i].y -= deta_down;

                    //完成构造好网格后要设定原顶点为0,因为这些乱码部分要被覆盖。
                    //一段Quad标记占据等数量的四边形,但是除了首个四边形,之后的都是已经失能的,正如下面的这条语句。
                    curVertex.position = Vector3.zero;
                    toFill.SetUIVertex(curVertex, pos);
                }
            }

            if (im == null)
            {
                return;
            }

            //注意一定要准备好数据再传给mesh.
            Mesh all_image_mesh = new Mesh();

            all_image_mesh.vertices  = vertex_buffer;
            all_image_mesh.triangles = index_buffer;
            all_image_mesh.uv        = uv_buffer;

            //这里要将顶点数据传递过去。
            im.SetContent(all_image_mesh);
        }
示例#13
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="spriteVerters">图片位置信息</param>
    /// <param name="onlyUpdatePositon">是否只更新位置</param>
    void CalcQuadTag(List <UIVertex> spriteVerters, bool onlyUpdatePositon = false)
    {
        UnityEngine.Profiling.Profiler.BeginSample("inlineText SpriteTagHandler CalcQuadTag");

        if (mAnimSpriteInfoList == null || mAnimSpriteInfoList.Count == 0)
        {
            return;
        }

        if (mAnimSpiteTagList == null || mAnimSpiteTagList.Count == 0)
        {
            return;
        }

        if (spriteVerters == null || spriteVerters.Count == 0)
        {
            return;
        }

        //canvas scale
        Vector3 relativePostion = Vector3.zero;

        if (mInlineSprite != null)
        {
            //todo
            relativePostion = transform.position - mInlineSprite.transform.position;
            if (canvas != null)
            {
                Vector3 scale = canvas.transform.localScale;
                relativePostion = new Vector3(relativePostion.x / scale.x, relativePostion.y / scale.y, relativePostion.z / scale.z);
            }
        }

        UnityEngine.Profiling.Profiler.BeginSample("inlineText CalcQuadTag Cal");

        for (int i = 0; i < mAnimSpiteTagList.Count; i++)
        {
            SpriteTagInfo tempTagInfo = mAnimSpiteTagList[i];
            if (!tempTagInfo.IsValid())
            {
                continue;
            }

            SpriteAnimInfo tempSpriteAnimInfos = mAnimSpriteInfoList[i];

            tempSpriteAnimInfos.Key   = tempTagInfo.Key;
            tempSpriteAnimInfos.Names = tempTagInfo.Names;

            if (i >= spriteVerters.Count)
            {
                //Debug.LogWarning("SpriteAnim Position is less");
                continue;
            }
            Debug.Log("_____________________relativePostion:" + relativePostion);
            Vector3 textpos = relativePostion + spriteVerters[i].position;
            Debug.Log("_____________________textpos:" + textpos);

            float xOffset = tempTagInfo.Offset * tempTagInfo.Size.x;

            tempSpriteAnimInfos.Vertices[0] = new Vector3(xOffset, 0, 0) + textpos;
            tempSpriteAnimInfos.Vertices[1] = new Vector3(xOffset + tempTagInfo.Size.x, tempTagInfo.Size.y, 0) + textpos;
            tempSpriteAnimInfos.Vertices[2] = new Vector3(xOffset + tempTagInfo.Size.x, 0, 0) + textpos;
            tempSpriteAnimInfos.Vertices[3] = new Vector3(xOffset, tempTagInfo.Size.x, 0) + textpos;

            if (onlyUpdatePositon == true)
            {
                continue;
            }

            for (int j = 0; j < tempTagInfo.Names.Count; j++)
            {
                Rect newSpriteRect;

                //todo
                SpriteAssetInfo tempSpriteAsset = mInlineSprite.GetSpriteInfo(tempTagInfo.Names[j]);
                if (tempSpriteAsset != null)
                {
                    newSpriteRect = tempSpriteAsset.rect;
                }
                else
                {
                    newSpriteRect = mInlineSprite.GetSpriteInfo(0).rect;
                    Debug.LogError("CalcQuadTag Can Find Sprite(name=" + tempTagInfo.Key + ")");
                }
                tempSpriteAnimInfos.Uvs[j] = newSpriteRect;
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();

        UnityEngine.Profiling.Profiler.EndSample();
    }
示例#14
0
    private void ParseSpriteTags(string strText)
    {
        if (mInlineSprite == null)
        {
            return;
        }

        if (mAnimSpiteTagList == null)
        {
            mAnimSpiteTagList = new List <SpriteTagInfo>();
        }

        if (string.IsNullOrEmpty(strText) || -1 == strText.IndexOf("quad"))
        {
            for (int i = 0; i < mAnimSpiteTagList.Count; ++i)
            {
                mAnimSpiteTagList[i].Reset();
            }
            return;
        }

        int index = 0;

        foreach (Match match in mConstSpriteTagRegex.Matches(strText))
        {
            List <string> names = mInlineSprite.GetSpriteNamesFromPrefix(match.Groups[1].Value);

            Debug.Log("____________________________prefix:" + match.Groups[1].Value);
            Debug.Log("____________________________prefix names:" + names.Count);

            if (names != null && names.Count > 0)
            {
                if (index + 1 > mAnimSpiteTagList.Count)
                {
                    SpriteTagInfo tempNew = new SpriteTagInfo();
                    mAnimSpiteTagList.Add(tempNew);
                }

                SpriteTagInfo tempArrayTag = mAnimSpiteTagList[index];
                tempArrayTag.Key          = GenerateKey(match.Groups[1].Value, index);
                tempArrayTag.Names        = names;
                tempArrayTag.VertextIndex = match.Index;

                float size = float.Parse(match.Groups[2].Value);

                float width  = float.Parse(match.Groups[3].Value);
                float offset = 0.0f;
                if (width > 1.0f)
                {
                    offset = (width - 1.0f) / 2.0f;
                }

                tempArrayTag.Size   = new Vector2(size, size);
                tempArrayTag.Offset = offset;

                Debug.Log("_________________________name:" + match.Groups[1].Value + ", index :" + match.Index);
                index++;
            }
        }

        if (index < mAnimSpiteTagList.Count)
        {
            int count = mAnimSpiteTagList.Count;
            for (int i = index; i < count; ++i)
            {
                mAnimSpiteTagList[i].Reset();
            }
        }
    }
示例#15
0
    private string GetOutputText()
    {
        _spriteInfo = new Dictionary <int, SpriteTagInfo>();
        StringBuilder textBuilder = new StringBuilder();
        int           textIndex   = 0;

        foreach (Match match in _inputTagRegex.Matches(text))
        {
            int tempId = 0;
            if (!string.IsNullOrEmpty(match.Groups[1].Value) && !match.Groups[1].Value.Equals("-"))
            {
                tempId = int.Parse(match.Groups[1].Value);
            }
            string tempTag = match.Groups[2].Value;
            //更新超链接
            if (tempId < 0)
            {
                textBuilder.Append(text.Substring(textIndex, match.Index - textIndex));
                textBuilder.Append("<color=blue>");
                int startIndex = textBuilder.Length * 4;
                textBuilder.Append("[" + match.Groups[2].Value + "]");
                int endIndex = textBuilder.Length * 4 - 2;
                textBuilder.Append("</color>");

                var hrefInfo = new HrefInfo
                {
                    Id         = Mathf.Abs(tempId),
                    StartIndex = startIndex, // 超链接里的文本起始顶点索引
                    EndIndex   = endIndex,
                    Name       = match.Groups[2].Value
                };
                _listHrefInfos.Add(hrefInfo);
            }
            //更新表情
            else
            {
                if (!_inlineManager.IndexSpriteInfo.ContainsKey(tempId) ||
                    !_inlineManager.IndexSpriteInfo[tempId].ContainsKey(tempTag))
                {
                    continue;
                }
                SpriteInforGroup tempGroup = _inlineManager.IndexSpriteInfo[tempId][tempTag];

                textBuilder.Append(text.Substring(textIndex, match.Index - textIndex));
                int tempIndex = textBuilder.Length * 4;
                textBuilder.Append(@"<quad size=" + tempGroup.Size + " width=" + tempGroup.Width + " />");

                SpriteTagInfo tempSpriteTag = new SpriteTagInfo
                {
                    Id   = tempId,
                    Tag  = tempTag,
                    Size = new Vector2(tempGroup.Size * tempGroup.Width, tempGroup.Size),
                    Pos  = new Vector3[4],
                    Uv   = tempGroup.ListSpriteInfor[0].Uv
                };
                if (!_spriteInfo.ContainsKey(tempIndex))
                {
                    _spriteInfo.Add(tempIndex, tempSpriteTag);
                }
            }

            textIndex = match.Index + match.Length;
        }

        textBuilder.Append(text.Substring(textIndex, text.Length - textIndex));
        return(textBuilder.ToString());
    }