public void DrawGizmos(Graphic graphic)
        {
            CanvasGraphicGroup group = FindGraphicGroup(graphic);

            if (group != null)
            {
                UnitMeshInfo rendermesh = group.mesh;
                if (rendermesh != null && rendermesh.getTexture() != null)
                {
                    Gizmos.color = Color.red;
                    int vertcnt = rendermesh.VertCnt();
                    int uvcnt   = rendermesh.UVCnt();
                    if (vertcnt != uvcnt)
                    {
                        Debug.LogError("data error");
                    }
                    else
                    {
                        for (int i = 0; i < vertcnt; i += 4)
                        {
                            Vector3 p1 = getPoint(graphic, rendermesh.GetVert(i));
                            Vector3 p2 = getPoint(graphic, rendermesh.GetVert(i + 1));
                            Vector3 p3 = getPoint(graphic, rendermesh.GetVert(i + 2));
                            Vector3 p4 = getPoint(graphic, rendermesh.GetVert(i + 3));

                            Gizmos.DrawLine(p1, p2);
                            Gizmos.DrawLine(p2, p3);
                            Gizmos.DrawLine(p3, p4);
                            Gizmos.DrawLine(p4, p1);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void RefreshSubUIMesh(InlineText text, SpriteGraphic target, SpriteAsset matchAsset, Vector3[] Pos, Vector2[] UV)
        {
            // set mesh
            tempMesh.SetAtlas(matchAsset);
            tempMesh.SetUVLen(UV.Length);
            tempMesh.SetVertLen(Pos.Length);

            for (int i = 0; i < Pos.Length; ++i)
            {
                //text object pos
                Vector3 value    = Pos[i];
                Vector3 worldpos = text.transform.TransformPoint(value);
                Vector3 localpos = target.transform.InverseTransformPoint(worldpos);
                tempMesh.SetVert(i, localpos);
            }

            for (int i = 0; i < UV.Length; ++i)
            {
                Vector2 value = UV[i];
                tempMesh.SetUV(i, value);
            }

            //rendermesh
            UnitMeshInfo currentMesh = null;

            if (!this.renderData.TryGetValue(target, out currentMesh))
            {
                currentMesh        = new UnitMeshInfo();
                renderData[target] = currentMesh;
            }

            if (!currentMesh.Equals(tempMesh))
            {
                if (target.isDirty)
                {
                    currentMesh.AddCopy(tempMesh);
                    tempMesh.Clear();
                }
                else
                {
                    currentMesh.Copy(tempMesh);
                }
            }

            if (currentMesh.VertCnt() > 3 && currentMesh.UVCnt() > 3)
            {
                target.Draw(this);
                target.SetDirtyMask();
                target.SetVerticesDirty();
            }
            else
            {
                target.Draw(null);
                target.SetDirtyMask();
                target.SetVerticesDirty();
            }
        }
        void RefreshSubUIMesh(InlineText text, CanvasGraphicGroup group, SpriteAsset matchAsset, Vector3[] Pos, Vector2[] UV, List <string> joblist)
        {
            // set mesh
            tempMesh.SetAtlas(matchAsset);
            tempMesh.SetUVLen(UV.Length);
            tempMesh.SetVertLen(Pos.Length);

            SpriteGraphic graphic = group.graphic;

            //think about culling and screen coordinate.......
            for (int i = 0; i < Pos.Length; ++i)
            {
                //text object pos
                Vector3 value    = Pos[i];
                Vector3 worldpos = text.transform.TransformPoint(value);
                Vector3 localpos = group.graphic.transform.InverseTransformPoint(worldpos);
                tempMesh.SetVert(i, localpos);
            }

            for (int i = 0; i < UV.Length; ++i)
            {
                Vector2 value = UV[i];
                tempMesh.SetUV(i, value);
            }

            //rendermesh
            UnitMeshInfo currentMesh = group.mesh;

            if (!currentMesh.Equals(tempMesh))
            {
                if (joblist != null && joblist.Count > 0)
                {
                    currentMesh.AddCopy(tempMesh);
                    tempMesh.Clear();
                }
                else
                {
                    currentMesh.Copy(tempMesh);
                }
            }

            if (currentMesh.VertCnt() > 3 && currentMesh.UVCnt() > 3)
            {
                graphic.Draw(this);
            }
            else
            {
                graphic.Draw(null);
            }

            group.isDirty = true;
        }
 public Texture getRenderTexture(SpriteGraphic graphic)
 {
     if (graphic != null && GraphicTasks != null)
     {
         CanvasGraphicGroup group = FindGraphicGroup(graphic);
         if (group != null)
         {
             UnitMeshInfo info = group.mesh;
             if (info != null)
             {
                 return(info.getTexture());
             }
         }
     }
     return(null);
 }
        public void FillMesh(Graphic graphic, VertexHelper vh)
        {
            CanvasGraphicGroup group = FindGraphicGroup(graphic);

            if (group != null)
            {
                UnitMeshInfo rendermesh = group.mesh;
                if (rendermesh != null && rendermesh.getTexture() != null)
                {
                    int vertcnt = rendermesh.VertCnt();
                    int uvcnt   = rendermesh.UVCnt();
                    if (vertcnt != uvcnt)
                    {
                        Debug.LogError("data error");
                    }
                    else
                    {
                        for (int i = 0; i < vertcnt; ++i)
                        {
                            vh.AddVert(rendermesh.GetVert(i), graphic.color, rendermesh.GetUV(i));
                        }

                        int cnt = vertcnt / 4;
                        for (int i = 0; i < cnt; ++i)
                        {
                            int m = i * 4;

                            vh.AddTriangle(m, m + 1, m + 2);
                            vh.AddTriangle(m + 2, m + 3, m);
                        }

                        //vh.AddTriangle(0, 1, 2);
                        //vh.AddTriangle(2, 3, 0);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public static void Release(UnitMeshInfo toRelease)
 {
     s_ListPool.Release(toRelease);
 }
        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;
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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;
        }