Graphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV, List <string> joblist)
        {
            EmojiTools.BeginSample("Emoji_GroupParsePosAndUV");
            SpriteAsset matchAsset = null;

            for (int i = 0; i < allatlas.Count; ++i)
            {
                SpriteAsset asset = allatlas[i];
                if (asset != null && asset.ID == ID)
                {
                    matchAsset = asset;
                    break;
                }
            }

            if (matchAsset && matchAsset.texSource != null)
            {
                CanvasGraphicGroup group = FindGraphicGroup(text.canvas, matchAsset.ID);
                if (group == null)
                {
                    group         = new CanvasGraphicGroup();
                    group.AtlasID = matchAsset.ID;
                    group.canvas  = text.canvas;
                    group.mesh    = UnitMeshInfoPool.Get();
                    group.isDirty = false;
                    group.graphic = CreateSpriteRender();

                    if (GraphicTasks == null)
                    {
                        GraphicTasks = new List <CanvasGraphicGroup>();
                    }

                    GraphicTasks.Add(group);
                }

                RefreshSubUIMesh(text, group, matchAsset, Pos, UV, joblist);

                EmojiTools.EndSample();
                return(group.graphic);
            }
            else
            {
                Debug.LogErrorFormat("missing {0} atlas", ID);
            }
            EmojiTools.EndSample();
            return(null);
        }
        void PlayAnimation()
        {
            EmojiTools.BeginSample("Emoji_GroupAnimation");
            if (alltexts != null)
            {
                if (_time == null)
                {
                    _time = Time.timeSinceLevelLoad;
                }
                else
                {
                    float deltatime = Time.timeSinceLevelLoad - _time.Value;

                    int framecnt = Mathf.RoundToInt(deltatime * Speed);
                    if (framecnt > 0)
                    {
                        List <string> joblist = ListPool <string> .Get();

                        for (int i = 0; i < alltexts.Count; ++i)
                        {
                            InlineText       text      = alltexts[i];
                            List <IFillData> emojidata = text.PopEmojiData();
                            if (emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0)
                            {
                                for (int j = 0; j < emojidata.Count; ++j)
                                {
                                    IFillData taginfo = emojidata[j];
                                    if (taginfo == null || taginfo.ignore)
                                    {
                                        continue;
                                    }
                                    SpriteAsset     asset     = null;
                                    SpriteInfoGroup groupinfo = manager.FindSpriteGroup(taginfo.Tag, out asset);
                                    if (groupinfo != null && groupinfo.spritegroups.Count > 1)
                                    {
                                        int        index   = framecnt % groupinfo.spritegroups.Count;
                                        SpriteInfo sprInfo = groupinfo.spritegroups[index];
                                        taginfo.uv = sprInfo.uv;

                                        //render next
                                        CanvasGraphicGroup group = FindGraphicGroup(text.canvas, asset.ID);

                                        if (group != null)
                                        {
                                            if (tempMesh == null)
                                            {
                                                tempMesh = UnitMeshInfoPool.Get();
                                            }

                                            RefreshSubUIMesh(text, group, asset, taginfo.pos, taginfo.uv, joblist);

                                            if (group.isDirty)
                                            {
                                                group.graphic.SetVerticesDirty();
                                            }
                                            joblist.Add(taginfo.Tag);
                                        }
                                    }
                                }
                            }
                        }
                        ListPool <string> .Release(joblist);
                    }
                }
            }

            EmojiTools.EndSample();
        }
        void RenderRebuild()
        {
            EmojiTools.BeginSample("Emoji_GroupRebuild");
            if (rebuildqueue != null && rebuildqueue.Count > 0)
            {
                List <string> joblist = ListPool <string> .Get();

                this.SetAllGroupDirty(false);

                for (int i = 0; i < alltexts.Count; ++i)
                {
                    InlineText text = alltexts[i];

                    List <IFillData> emojidata = text.PopEmojiData();
                    if (text != null && emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0)
                    {
                        if (tempMesh == null)
                        {
                            tempMesh = UnitMeshInfoPool.Get();
                        }

                        for (int j = 0; j < emojidata.Count; ++j)
                        {
                            IFillData taginfo = emojidata[j];
                            if (taginfo == null || taginfo.ignore)
                            {
                                continue;
                            }
                            Graphic job = Parse(text, taginfo, joblist);
                            if (job)
                            {
                                joblist.Add(taginfo.Tag);
                            }
                        }
                    }
                }

                if (GraphicTasks != null)
                {
                    for (int i = 0; i < GraphicTasks.Count; ++i)
                    {
                        CanvasGraphicGroup group = GraphicTasks[i];
                        if (group != null && group.graphic != null)
                        {
                            if (group.isDirty)
                            {
                                group.graphic.SetVerticesDirty();
                            }
                            else
                            {
                                group.graphic.Draw(null);
                                group.graphic.SetDirtyMask();
                                group.graphic.SetVerticesDirty();
                            }
                        }
                    }
                }

                ListPool <string> .Release(joblist);

                rebuildqueue.Clear();
            }
            EmojiTools.EndSample();
        }
        public void Dispose()
        {
            if (allatlas != null)
            {
                ListPool <SpriteAsset> .Release(allatlas);

                allatlas = null;
            }

            if (alltexts != null)
            {
                ListPool <InlineText> .Release(alltexts);

                alltexts = null;
            }

            if (tempMesh != null)
            {
                UnitMeshInfoPool.Release(tempMesh);
                tempMesh = null;
            }

            if (GraphicTasks != null)
            {
                for (int i = 0; i < GraphicTasks.Count; ++i)
                {
                    CanvasGraphicGroup group  = GraphicTasks[i];
                    SpriteGraphic      target = group.graphic;
                    if (target != null)
                    {
                        target.Draw(null);
                        target.SetDirtyMask();
                        target.SetVerticesDirty();
                    }

                    if (group.mesh != null)
                    {
                        UnitMeshInfoPool.Release(group.mesh);
                    }
                }

                GraphicTasks.Clear();
                GraphicTasks = null;
            }

            if (rebuildqueue != null)
            {
                ListPool <InlineText> .Release(rebuildqueue);

                rebuildqueue = null;
            }


            if (listeners != null)
            {
                listeners.Clear();
                listeners = null;
            }

            if (tempMesh != null)
            {
                UnitMeshInfoPool.Release(tempMesh);
                tempMesh = null;
            }

            _time = null;
        }
        void PlayAnimation()
        {
            EmojiTools.BeginSample("Emoji_UnitAnimation");
            if (alltexts != null)
            {
                if (_time == null)
                {
                    _time = Time.timeSinceLevelLoad;
                }
                else
                {
                    float deltatime = Time.timeSinceLevelLoad - _time.Value;
                    //at least one frame
                    int framecnt = Mathf.RoundToInt(deltatime * Speed);
                    if (framecnt > 0)
                    {
                        for (int i = 0; i < alltexts.Count; ++i)
                        {
                            InlineText       text      = alltexts[i];
                            List <IFillData> emojidata = text.PopEmojiData();
                            if (emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0)
                            {
                                for (int j = 0; j < emojidata.Count; ++j)
                                {
                                    IFillData taginfo = emojidata[j];
                                    if (taginfo == null || taginfo.ignore)
                                    {
                                        continue;
                                    }

                                    SpriteAsset     asset     = null;
                                    SpriteInfoGroup groupinfo = manager.FindSpriteGroup(taginfo.Tag, out asset);
                                    if (groupinfo != null && groupinfo.spritegroups.Count > 1)
                                    {
                                        int        index   = framecnt % groupinfo.spritegroups.Count;
                                        SpriteInfo sprInfo = groupinfo.spritegroups[index];
                                        taginfo.uv = sprInfo.uv;

                                        List <SpriteGraphic> list   = null;
                                        SpriteGraphic        target = FindGraphic(text, asset, out list);
                                        if (target)
                                        {
                                            if (tempMesh == null)
                                            {
                                                tempMesh = UnitMeshInfoPool.Get();
                                            }

                                            if (renderData == null)
                                            {
                                                renderData = new Dictionary <Graphic, UnitMeshInfo>(emojidata.Count);
                                            }

                                            RefreshSubUIMesh(text, target, asset, taginfo.pos, taginfo.uv);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            EmojiTools.EndSample();
        }
        void RenderRebuild()
        {
            EmojiTools.BeginSample("Emoji_UnitRebuild");
            if (rebuildqueue != null && rebuildqueue.Count > 0)
            {
                for (int i = 0; i < rebuildqueue.Count; ++i)
                {
                    InlineText       text      = rebuildqueue[i];
                    List <IFillData> emojidata = text.PopEmojiData();
                    if (emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0)
                    {
                        if (tempMesh == null)
                        {
                            tempMesh = UnitMeshInfoPool.Get();
                        }

                        if (renderData == null)
                        {
                            renderData = new Dictionary <Graphic, UnitMeshInfo>(emojidata.Count);
                        }

                        for (int j = 0; j < emojidata.Count; ++j)
                        {
                            IFillData taginfo = emojidata[j];
                            if (taginfo == null || taginfo.ignore)
                            {
                                continue;
                            }
                            Parse(text, taginfo);
                        }

                        List <SpriteGraphic> list;
                        if (textGraphics != null && textGraphics.TryGetValue(text, out list))
                        {
                            for (int j = 0; j < list.Count; ++j)
                            {
                                SpriteGraphic graphic = list[j];
                                //not render
                                if (graphic != null && !graphic.isDirty)
                                {
                                    graphic.Draw(null);
                                    graphic.SetDirtyMask();
                                    graphic.SetVerticesDirty();
                                }
                            }
                        }
                    }
                    else
                    {
                        List <SpriteGraphic> list;
                        if (textGraphics != null && textGraphics.TryGetValue(text, out list))
                        {
                            for (int j = 0; j < list.Count; ++j)
                            {
                                SpriteGraphic graphic = list[j];
                                //not render
                                if (graphic != null)
                                {
                                    graphic.Draw(null);
                                    graphic.SetDirtyMask();
                                    graphic.SetVerticesDirty();
                                }
                            }
                        }
                    }
                }

                rebuildqueue.Clear();
            }
            EmojiTools.EndSample();
        }
        public void Dispose()
        {
            if (allatlas != null)
            {
                ListPool <SpriteAsset> .Release(allatlas);

                allatlas = null;
            }

            if (alltexts != null)
            {
                ListPool <InlineText> .Release(alltexts);

                alltexts = null;
            }

            if (tempMesh != null)
            {
                UnitMeshInfoPool.Release(tempMesh);
                tempMesh = null;
            }

            if (textGraphics != null)
            {
                var en = textGraphics.GetEnumerator();
                while (en.MoveNext())
                {
                    var list = en.Current.Value;
                    for (int i = 0; i < list.Count; ++i)
                    {
                        var target = list[i];
                        if (target != null)
                        {
                            target.Draw(null);
                            target.SetDirtyMask();
                            target.SetVerticesDirty();
                        }
                    }

                    ListPool <SpriteGraphic> .Release(en.Current.Value);
                }
                textGraphics = null;
            }

            if (rebuildqueue != null)
            {
                ListPool <InlineText> .Release(rebuildqueue);

                rebuildqueue = null;
            }

            if (renderData != null)
            {
                renderData.Clear();
                renderData = null;
            }

            if (tempMesh != null)
            {
                UnitMeshInfoPool.Release(tempMesh);
                tempMesh = null;
            }

            _time = null;
        }