Ejemplo n.º 1
0
        SpriteGraphic FindGraphic(InlineText text, SpriteAsset matchAsset, out List <SpriteGraphic> list)
        {
            EmojiTools.BeginSample("Emoji_UnitFindGraphic");
            if (textGraphics == null)
            {
                textGraphics = new Dictionary <InlineText, List <SpriteGraphic> >();
            }

            if (!textGraphics.TryGetValue(text, out list))
            {
                list = ListPool <SpriteGraphic> .Get();

                textGraphics[text] = list;
            }

            SpriteGraphic target = null;

            for (int i = 0; i < list.Count; ++i)
            {
                SpriteGraphic graphic = list[i];
                if (graphic && UnityEngine.Object.ReferenceEquals(graphic.mainTexture, matchAsset.texSource))
                {
                    target = graphic;
                    break;
                }
            }
            EmojiTools.EndSample();
            return(target);
        }
        SpriteGraphic CreateSpriteRender()
        {
            if (PoolObj == null)
            {
                PoolObj = new GameObject("GroupRenderPool");
                SpriteGraphic target = null;
                for (int i = 0; i < 4; i++)
                {
                    target = CreateInstance(PoolObj.transform);
                }

                target.transform.SetParent(manager.transform);
                return(target);
            }
            else
            {
                int childcnt = PoolObj.transform.childCount;
                if (childcnt > 0)
                {
                    Transform trans = PoolObj.transform.GetChild(0);
                    trans.SetParent(manager.transform);
                    return(trans.GetComponent <SpriteGraphic>());
                }

                return(CreateInstance(manager.transform));
            }
        }
Ejemplo n.º 3
0
        public void Release(Graphic graphic)
        {
            if (graphic is SpriteGraphic)
            {
                SpriteGraphic spriteGraphic = graphic as SpriteGraphic;
                if (renderData != null)
                {
                    renderData.Remove(spriteGraphic);
                }

                if (textGraphics != null)
                {
                    var en = textGraphics.GetEnumerator();
                    while (en.MoveNext())
                    {
                        var list = en.Current.Value;
                        for (int i = list.Count - 1; i >= 0; --i)
                        {
                            var target = list[i];

                            if (UnityEngine.Object.ReferenceEquals(target, graphic))
                            {
                                list.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        SpriteGraphic FindGraphic(InlineText text, int atlasID, out SpriteAsset matchAsset)
        {
            matchAsset = null;
            for (int i = 0; i < allatlas.Count; ++i)
            {
                SpriteAsset asset = allatlas[i];
                if (asset != null && asset.ID == atlasID)
                {
                    matchAsset = asset;
                    break;
                }
            }

            if (matchAsset && matchAsset.texSource != null)
            {
                List <SpriteGraphic> list   = null;
                SpriteGraphic        target = FindGraphic(text, matchAsset, out list);
                if (!target)
                {
                    target = CreateSpriteRender(text.transform);
                    list.Add(target);
                }
                return(target);
            }
            return(null);
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
0
 public Texture getRenderTexture(SpriteGraphic graphic)
 {
     if (graphic != null && renderData != null)
     {
         UnitMeshInfo info;
         if (renderData.TryGetValue(graphic, out info))
         {
             return(info.getTexture());
         }
     }
     return(null);
 }
        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);
 }
        SpriteGraphic CreateInstance(Transform targetTrans)
        {
            GameObject newobject = new GameObject("pre_Sprite");

            newobject.transform.SetParent(targetTrans);
            newobject.transform.localPosition    = Vector3.zero;
            newobject.transform.localScale       = Vector3.one;
            newobject.transform.localRotation    = Quaternion.identity;
            newobject.transform.gameObject.layer = targetTrans.gameObject.layer;
            newobject.transform.tag = targetTrans.gameObject.tag;
            //newobject.transform.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;

            SpriteGraphic spritegrahic = newobject.AddComponent <SpriteGraphic>();

            spritegrahic.raycastTarget = false;
            return(spritegrahic);
        }
        public void Release(Graphic graphic)
        {
            if (graphic is SpriteGraphic && PoolObj != null)
            {
                SpriteGraphic spriteGraphic = graphic as SpriteGraphic;
                spriteGraphic.Draw(null);

                if (GraphicTasks != null)
                {
                    for (int i = 0; i < GraphicTasks.Count; ++i)
                    {
                        CanvasGraphicGroup group = GraphicTasks[i];

                        if (group != null && UnityEngine.Object.ReferenceEquals(group.graphic, graphic))
                        {
                            GraphicTasks.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        SpriteGraphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV)
        {
            EmojiTools.BeginSample("Emoji_UnitParsePosAndUV");
            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)
            {
                List <SpriteGraphic> list   = null;
                SpriteGraphic        target = FindGraphic(text, matchAsset, out list);
                if (!target)
                {
                    target = CreateSpriteRender(text.transform);
                    list.Add(target);
                }

                RefreshSubUIMesh(text, target, matchAsset, Pos, UV);

                EmojiTools.EndSample();
                return(target);
            }
            else
            {
                Debug.LogErrorFormat("missing {0} atlas", ID);
            }
            EmojiTools.EndSample();
            return(null);
        }
        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.º 13
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.º 14
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();
        }