Beispiel #1
0
 public bool isSameStyle(LRenderElement elem)
 {
     return(this.color == elem.color &&
            this.isOutLine == elem.isOutLine &&
            this.isUnderLine == elem.isUnderLine &&
            this.font == elem.font &&
            this.fontSize == elem.fontSize &&
            this.data == elem.data);
 }
Beispiel #2
0
        void makeImage(GameObject img, LRenderElement elem)
        {
            Image comImage = img.GetComponent <Image>();

            if (comImage != null)
            {
                Sprite sp = LLoadBundle.GetInstance().LoadAsset(LGameConfig.WINDOW_BUNDLE, elem.path, typeof(Sprite)) as Sprite;
                comImage.sprite = sp;
            }
        }
        void makeImage(GameObject img, LRenderElement elem)
        {
            Image comImage = img.GetComponent <Image>();

            if (comImage != null)
            {
                Sprite sp = GAMEAPI.ABUI_LoadSprite(elem.path);
                comImage.sprite = sp;
            }
        }
Beispiel #4
0
        void makeImage(GameObject img, LRenderElement elem)
        {
            Image comImage = img.GetComponent <Image>();

            if (comImage != null)
            {
                Sprite sp = Resources.Load(elem.path, typeof(Sprite)) as Sprite;
                comImage.sprite = sp;
            }
        }
        void makeLabel(GameObject lab, LRenderElement elem)
        {
            Text comText = lab.GetComponent <Text>();

            if (comText != null)
            {
                comText.text      = elem.strChar;
                comText.font      = elem.font;
                comText.fontSize  = elem.fontSize;
                comText.fontStyle = FontStyle.Normal;
                comText.color     = elem.color;
            }

            Outline outline = lab.GetComponent <Outline>();

            // Outline outline1 = lab.GetComponent<Outline>();
            if (elem.isOutLine)
            {
                if (outline == null)
                {
                    outline = lab.AddComponent <Outline>();
                    //  outline1 = lab.AddComponent<Outline>();
                }
            }
            else
            {
                if (outline)
                {
                    Destroy(outline);
                }
                //if (outline1)
                //{
                //    Destroy(outline1);
                //}
            }

            if (elem.isUnderLine)
            {
                GameObject underLine = getCacheImage(false);
                Image      underImg  = underLine.GetComponent <Image>();
                underImg.color = elem.color;
                underImg.GetComponent <RectTransform>().sizeDelta = new Vector2(comText.preferredWidth, 1);
                underLine.transform.SetParent(transform);
                underLine.transform.localPosition = new Vector2(elem.pos.x, elem.pos.y);
            }
            if (elem.isNewLine)
            {
                comText.text      = elem.strChar;
                comText.font      = this.font;
                comText.fontSize  = elem.fontSize;
                comText.fontStyle = FontStyle.Normal;
                comText.color     = elem.color;
            }
        }
Beispiel #6
0
        private void makeLabel(GameObject lab, LRenderElement elem)
        {
            Text component = lab.GetComponent <Text>();
            bool flag      = component != null;

            if (flag)
            {
                component.text      = elem.strChar;
                component.font      = elem.font;
                component.fontSize  = elem.fontSize;
                component.fontStyle = FontStyle.Normal;
                component.color     = elem.color;
            }
            Outline outline   = lab.GetComponent <Outline>();
            bool    isOutLine = elem.isOutLine;

            if (isOutLine)
            {
                bool flag2 = outline == null;
                if (flag2)
                {
                    outline = lab.AddComponent <Outline>();
                }
            }
            else
            {
                bool flag3 = outline;
                if (flag3)
                {
                    UnityEngine.Object.Destroy(outline);
                }
            }
            bool isUnderLine = elem.isUnderLine;

            if (isUnderLine)
            {
                GameObject cacheImage = this.getCacheImage(false);
                Image      component2 = cacheImage.GetComponent <Image>();
                component2.color = elem.color;
                component2.GetComponent <RectTransform>().sizeDelta = new Vector2(component.preferredWidth, 1f);
                cacheImage.transform.SetParent(base.transform);
                cacheImage.transform.localPosition = new Vector2(elem.pos.x, elem.pos.y);
            }
            bool isNewLine = elem.isNewLine;

            if (isNewLine)
            {
                component.text      = elem.strChar;
                component.font      = this.font;
                component.fontSize  = elem.fontSize;
                component.fontStyle = FontStyle.Normal;
                component.color     = elem.color;
            }
        }
Beispiel #7
0
        private void makeImage(GameObject img, LRenderElement elem)
        {
            Image component = img.GetComponent <Image>();
            bool  flag      = component != null;

            if (flag)
            {
                Sprite sprite = Resources.Load(elem.path, typeof(Sprite)) as Sprite;
                component.sprite = sprite;
            }
        }
Beispiel #8
0
        void makeFramAnim(GameObject anim, LRenderElement elem)
        {
            LMovieClip comFram = anim.GetComponent <LMovieClip>();

            if (comFram != null)
            {
                comFram.path = elem.path;
                comFram.fps  = elem.fs;
                comFram.loadTexture();
                comFram.play();
            }
        }
Beispiel #9
0
        void makeImage(GameObject img, LRenderElement elem)
        {
            Image comImage = img.GetComponent <Image>();

            if (comImage != null)
            {
                string atlas  = System.IO.Path.GetDirectoryName(elem.path);
                string spname = System.IO.Path.GetFileName(elem.path);
                Sprite sp     = LLoadBundle.GetInstance().GetSpriteByName(atlas, spname);
                comImage.sprite = sp;
            }
        }
Beispiel #10
0
        void makeImage(GameObject img, LRenderElement elem)
        {
            Image comImage = img.GetComponent <Image>();

            if (comImage != null)
            {
                string atlas  = elem.path.Split('/')[0];
                string spname = elem.path.Split('/')[1];
                LTextureAtlas.GetInstance().LoadData(atlas);
                Sprite sp = LTextureAtlas.GetInstance().getSprite(atlas, spname);
                comImage.sprite = sp;
            }
        }
Beispiel #11
0
        private void makeFramAnim(GameObject anim, LRenderElement elem)
        {
            LMovieClip component = anim.GetComponent <LMovieClip>();
            bool       flag      = component != null;

            if (flag)
            {
                component.path = elem.path;
                component.fps  = elem.fs;
                component.loadTexture();
                component.play();
            }
        }
Beispiel #12
0
        void makeImage(GameObject img, LRenderElement elem)
        {
            Image comImage = img.GetComponent <Image>();

            if (comImage != null)
            {
                string atlas  = elem.path.Split('/')[0];
                string spname = elem.path.Split('/')[1];
                LTextureAtlas.GetInstance().LoadData(atlas);
                Sprite sp = LTextureAtlas.GetInstance().getSprite(atlas, spname);
                //Sprite sp = LLoadBundle.GetInstance().LoadAsset(LGameConfig.PREFAB_BUNDLE, elem.path, typeof(Sprite)) as Sprite;
                comImage.sprite = sp;
            }
        }
Beispiel #13
0
        void makeLabel(GameObject lab, LRenderElement elem)
        {
            Text comText = lab.GetComponent <Text>();

            if (comText != null)
            {
                comText.text          = elem.strChar;
                comText.font          = elem.font;
                comText.fontSize      = elem.fontSize;
                comText.fontStyle     = FontStyle.Normal;
                comText.color         = elem.color;
                comText.lineSpacing   = 0;
                comText.raycastTarget = this.raycastTarget;
            }

            Outline outline = lab.GetComponent <Outline>();

            if (elem.isOutLine)
            {
                if (outline == null)
                {
                    outline             = lab.AddComponent <Outline>();
                    outline.effectColor = elem.outLineColor;
                }
            }
            else
            {
                if (outline)
                {
                    Destroy(outline);
                }
            }

            if (elem.isUnderLine)
            {
                GameObject underLine = getCacheImage(false);
                Image      underImg  = underLine.GetComponent <Image>();
                underImg.color = elem.color;
                underImg.GetComponent <RectTransform>().sizeDelta = new Vector2(comText.preferredWidth, 1);
                underLine.SetActive(true);
                underLine.transform.SetParent(transform);
                underLine.transform.localScale    = new Vector3(1, 1, 1);
                underLine.transform.localPosition = new Vector2(elem.pos.x, elem.pos.y);
                comText.raycastTarget             = true;
            }
        }
        public LRenderElement Clone()
        {
            LRenderElement cloneOjb = new LRenderElement();

            cloneOjb.type        = this.type;
            cloneOjb.strChar     = this.strChar;
            cloneOjb.width       = this.width;
            cloneOjb.height      = this.height;
            cloneOjb.isOutLine   = this.isOutLine;
            cloneOjb.isUnderLine = this.isUnderLine;
            cloneOjb.font        = this.font;
            cloneOjb.fontSize    = this.fontSize;
            cloneOjb.color       = this.color;
            cloneOjb.data        = this.data;
            cloneOjb.path        = this.path;
            cloneOjb.fs          = this.fs;
            cloneOjb.isNewLine   = this.isNewLine;
            cloneOjb.pos         = this.pos;
            cloneOjb.rect        = this.rect;
            return(cloneOjb);
        }
Beispiel #15
0
        protected void formatRenderers()
        {
            int  oneLine          = 0;
            int  lines            = 1;
            bool isReplaceInSpace = false;
            int  len = _elemRenderArr.Count;

            for (int i = 0; i < len; i++)
            {
                isReplaceInSpace = false;
                LRenderElement elem = _elemRenderArr[i];
                if (elem.isNewLine) // new line
                {
                    oneLine = 0;
                    lines++;
                    elem.width  = 10;
                    elem.height = 27;
                    elem.pos    = new Vector2(oneLine, -lines * 27);
                }
                else //other elements
                {
                    if (oneLine + elem.width > maxLineWidth)
                    {
                        if (elem.type == RichType.TEXT)
                        {
                            if (isChinese(elem.strChar) || elem.strChar == " ")
                            {
                                oneLine = 0;
                                lines++;

                                elem.pos = new Vector2(oneLine, -lines * 27);
                                oneLine  = elem.width;
                            }
                            else // en
                            {
                                int spaceIdx = 0;
                                int idx      = i;
                                while (idx > 0)
                                {
                                    idx--;
                                    if (_elemRenderArr[idx].strChar == " " &&
                                        _elemRenderArr[idx].pos.y == _elemRenderArr[i - 1].pos.y) // just for the same line
                                    {
                                        spaceIdx = idx;
                                        break;
                                    }
                                }
                                // can't find space , force new line
                                if (spaceIdx == 0)
                                {
                                    oneLine = 0;
                                    lines++;
                                    elem.pos = new Vector2(oneLine, -lines * 27);
                                    oneLine  = elem.width;
                                }
                                else
                                {
                                    oneLine = 0;
                                    lines++;
                                    isReplaceInSpace = true; //reset cuting words position

                                    for (int _i = spaceIdx + 1; _i <= i; ++_i)
                                    {
                                        LRenderElement _elem = _elemRenderArr[_i];
                                        _elem.pos = new Vector2(oneLine, -lines * 27);
                                        oneLine  += _elem.width;

                                        _elemRenderArr[_i] = _elem;
                                    }
                                }
                            }
                        }
                        else if (elem.type == RichType.ANIM || elem.type == RichType.IMAGE)
                        {
                            lines++;
                            elem.pos = new Vector2(0, -lines * 27);
                            oneLine  = elem.width;
                        }
                    }
                    else
                    {
                        elem.pos = new Vector2(oneLine, -lines * 27);
                        oneLine += elem.width;
                    }
                }
                if (isReplaceInSpace == false)
                {
                    _elemRenderArr[i] = elem;
                }
            }
            //sort all lines
            Dictionary <int, List <LRenderElement> > rendElemLineMap = new Dictionary <int, List <LRenderElement> >();
            List <int> lineKeyList = new List <int>();

            len = _elemRenderArr.Count;
            for (int i = 0; i < len; i++)
            {
                LRenderElement        elem = _elemRenderArr[i];
                List <LRenderElement> lineList;

                if (!rendElemLineMap.ContainsKey((int)elem.pos.y))
                {
                    lineList = new List <LRenderElement>();
                    rendElemLineMap[(int)elem.pos.y] = lineList;
                }
                rendElemLineMap[(int)elem.pos.y].Add(elem);
            }
            // all lines in arr
            List <List <LRenderElement> > rendLineArrs = new List <List <LRenderElement> >();

            foreach (var item in rendElemLineMap)
            {
                lineKeyList.Add(-1 * item.Key);
            }
            lineKeyList.Sort();
            len = lineKeyList.Count;

            for (int i = 0; i < len; i++)
            {
                int            posY                = -1 * lineKeyList[i];
                string         lineString          = "";
                LRenderElement _lastEleme          = rendElemLineMap[posY][0];
                LRenderElement _lastDiffStartEleme = rendElemLineMap[posY][0];
                if (rendElemLineMap[posY].Count > 0)
                {
                    List <LRenderElement> lineElemArr = new List <LRenderElement>();

                    foreach (LRenderElement elem in rendElemLineMap[posY])
                    {
                        if (_lastEleme.type == RichType.TEXT && elem.type == RichType.TEXT)
                        {
                            if (_lastEleme.isSameStyle(elem))
                            {
                                // the same style can mergin one element
                                lineString += elem.strChar;
                            }
                            else // diff style
                            {
                                if (_lastDiffStartEleme.type == RichType.TEXT)
                                {
                                    LRenderElement _newElem = _lastDiffStartEleme.Clone();
                                    _newElem.strChar = lineString;
                                    lineElemArr.Add(_newElem);

                                    _lastDiffStartEleme = elem;
                                    lineString          = elem.strChar;
                                }
                            }
                        }
                        else if (elem.type == RichType.IMAGE || elem.type == RichType.ANIM || elem.type == RichType.NEWLINE)
                        {
                            //interrupt
                            if (_lastDiffStartEleme.type == RichType.TEXT)
                            {
                                LRenderElement _newEleme = _lastDiffStartEleme.Clone();
                                _newEleme.strChar = lineString;
                                lineString        = "";
                                lineElemArr.Add(_newEleme);
                            }
                            lineElemArr.Add(elem);
                        }
                        else if (_lastEleme.type != RichType.TEXT)
                        {
                            //interrupt
                            _lastDiffStartEleme = elem;
                            if (elem.type == RichType.TEXT)
                            {
                                lineString = elem.strChar;
                            }
                        }
                        _lastEleme = elem;
                    }
                    // the last elementText
                    if (_lastDiffStartEleme.type == RichType.TEXT)
                    {
                        LRenderElement _newElem = _lastDiffStartEleme.Clone();
                        _newElem.strChar = lineString;
                        lineElemArr.Add(_newElem);
                    }
                    rendLineArrs.Add(lineElemArr);
                }
            }

            // offset position
            int _offsetLineY = 0;

            realLineHeight = 0;
            len            = rendLineArrs.Count;
            for (int i = 0; i < len; i++)
            {
                List <LRenderElement> _lines = rendLineArrs[i];
                int _lineHeight = 0;
                foreach (LRenderElement elem in _lines)
                {
                    _lineHeight = Mathf.Max(_lineHeight, elem.height);
                }

                realLineHeight += _lineHeight;
                _offsetLineY   += (_lineHeight - 27);

                int _len = _lines.Count;
                for (int j = 0; j < _len; j++)
                {
                    LRenderElement elem = _lines[j];
                    elem.pos       = new Vector2(elem.pos.x, elem.pos.y - _offsetLineY);
                    realLineHeight = Mathf.Max(realLineHeight, (int)Mathf.Abs(elem.pos.y));
                    _lines[j]      = elem;
                }
                rendLineArrs[i] = _lines;
            }

            // place all position
            realLineWidth = 0;
            GameObject obj = null;

            foreach (List <LRenderElement> _lines in rendLineArrs)
            {
                int _lineWidth = 0;
                foreach (LRenderElement elem in _lines)
                {
                    if (elem.type != RichType.NEWLINE)
                    {
                        if (elem.type == RichType.TEXT)
                        {
                            obj = getCacheLabel();
                            makeLabel(obj, elem);
                            _lineWidth += (int)obj.GetComponent <Text>().preferredWidth;
                        }
                        else if (elem.type == RichType.IMAGE)
                        {
                            obj = getCacheImage(true);
                            makeImage(obj, elem);
                            _lineWidth += (int)obj.GetComponent <Image>().preferredWidth;
                        }
                        else if (elem.type == RichType.ANIM)
                        {
                            obj = getCacheFramAnim();
                            makeFramAnim(obj, elem);
                            _lineWidth += elem.width;
                        }
                        obj.SetActive(true);
                        obj.transform.SetParent(transform);
                        obj.transform.localPosition = new Vector2(elem.pos.x, elem.pos.y /*+ realLineHeight*/);
                        obj.transform.localScale    = new Vector2(1, 1);
                        _objectDataMap[obj]         = elem.data;
                    }
                }
                realLineWidth = Mathf.Max(_lineWidth, realLineWidth);
            }

            RectTransform rtran = this.GetComponent <RectTransform>();

            //align
            if (alignType == RichAlignType.DESIGN_CENTER)
            {
                rtran.sizeDelta = new Vector2(maxLineWidth, realLineHeight);
            }
            else if (alignType == RichAlignType.LEFT_TOP)
            {
                rtran.sizeDelta = new Vector2(realLineWidth, realLineHeight);
            }
        }
Beispiel #16
0
        public void reloadData()
        {
            this.removeAllElements();

            RectTransform rtran = this.GetComponent <RectTransform>();

            //align
            if (alignType == RichAlignType.DESIGN_CENTER)
            {
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f);
            }
            else if (alignType == RichAlignType.LEFT_TOP)
            {
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0f, 1f);
            }

            foreach (LRichElement elem in _richElements)
            {
                if (elem.type == RichType.TEXT)
                {
                    LRichElementText elemText = elem as LRichElementText;
                    char[]           _charArr = elemText.txt.ToCharArray();
                    TextGenerator    gen      = new TextGenerator();

                    foreach (char strChar in _charArr)
                    {
                        LRenderElement rendElem = new LRenderElement();
                        rendElem.type         = RichType.TEXT;
                        rendElem.strChar      = strChar.ToString();
                        rendElem.isOutLine    = elemText.isOutLine;
                        rendElem.isUnderLine  = elemText.isUnderLine;
                        rendElem.outLineColor = elemText.outLineColor;
                        rendElem.font         = this.font;
                        rendElem.fontSize     = elemText.fontSize;
                        rendElem.data         = elemText.data;
                        rendElem.color        = elemText.color;

                        TextGenerationSettings setting = new TextGenerationSettings();
                        setting.font               = this.font;
                        setting.fontSize           = elemText.fontSize;
                        setting.lineSpacing        = 1;
                        setting.scaleFactor        = 1;
                        setting.verticalOverflow   = VerticalWrapMode.Overflow;
                        setting.horizontalOverflow = HorizontalWrapMode.Overflow;

                        rendElem.width  = (int)gen.GetPreferredWidth(rendElem.strChar, setting);
                        rendElem.height = (int)gen.GetPreferredHeight(rendElem.strChar, setting);
                        _elemRenderArr.Add(rendElem);
                    }
                }
                else if (elem.type == RichType.IMAGE)
                {
                    LRichElementImage elemImg  = elem as LRichElementImage;
                    LRenderElement    rendElem = new LRenderElement();
                    rendElem.type = RichType.IMAGE;
                    rendElem.path = elemImg.path;
                    rendElem.data = elemImg.data;

                    string atlas  = System.IO.Path.GetDirectoryName(rendElem.path);
                    string spname = System.IO.Path.GetFileName(rendElem.path);

                    Sprite sp = LLoadBundle.GetInstance().GetSpriteByName(atlas, spname);
                    rendElem.width  = (int)sp.rect.size.x;
                    rendElem.height = (int)sp.rect.size.y;
                    _elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.ANIM)
                {
                    LRichElementAnim elemAnim = elem as LRichElementAnim;
                    LRenderElement   rendElem = new LRenderElement();
                    rendElem.type = RichType.ANIM;
                    rendElem.path = elemAnim.path;
                    rendElem.data = elemAnim.data;
                    rendElem.fs   = elemAnim.fs;

                    string atlas  = System.IO.Path.GetDirectoryName(rendElem.path);
                    string spname = System.IO.Path.GetFileName(rendElem.path);

                    Sprite sp = LLoadBundle.GetInstance().GetSpriteByName(atlas, spname);
                    rendElem.width  = (int)sp.rect.size.x;
                    rendElem.height = (int)sp.rect.size.y;
                    _elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.NEWLINE)
                {
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.isNewLine = true;
                    _elemRenderArr.Add(rendElem);
                }
            }

            _richElements.Clear();

            formatRenderers();
        }
        protected void formarRenderers(float newElemOffset)
        {
            int  oneLine          = 0;
            int  lines            = 1;
            int  height           = 27;
            bool isReplaceInSpace = false;
            int  len = _elemRenderArr.Count;

            for (int i = 0; i < len; i++)
            {
                isReplaceInSpace = false;
                LRenderElement elem = _elemRenderArr[i];
                if (elem.isNewLine) // new line
                {
                    oneLine = 0;
                    lines++;
                    elem.width  = 10;
                    elem.height = height;
                    elem.pos    = new Vector2(oneLine, -lines * height);
                }
                else //other elements
                {
                    if (oneLine + elem.width > maxLineWidth)
                    {
                        if (elem.type == RichType.TEXT)
                        {
                            if (isChinese(elem.strChar) || elem.strChar == " ")
                            {
                                oneLine = 0;
                                lines++;

                                elem.pos = new Vector2(oneLine, -lines * height);
                                oneLine  = elem.width;
                            }
                            else // en
                            {
                                int spaceIdx = 0;
                                int idx      = i;
                                while (idx > 0)
                                {
                                    idx--;
                                    if (_elemRenderArr[idx].strChar == " " &&
                                        _elemRenderArr[idx].pos.y == _elemRenderArr[i - 1].pos.y) // just for the same line//
                                    {
                                        spaceIdx = idx;
                                        break;
                                    }
                                }
                                // can't find space , force new line
                                if (spaceIdx == 0)
                                {
                                    oneLine = 0;
                                    lines++;
                                    elem.pos = new Vector2(oneLine, -lines * height);
                                    oneLine  = elem.width;
                                }
                                else
                                {
                                    oneLine = 0;
                                    lines++;
                                    isReplaceInSpace = true; //reset cuting words position

                                    for (int _i = spaceIdx + 1; _i <= i; ++_i)
                                    {
                                        LRenderElement _elem = _elemRenderArr[_i];
                                        _elem.pos = new Vector2(oneLine, -lines * height);
                                        oneLine  += _elem.width;

                                        _elemRenderArr[_i] = _elem;
                                    }
                                }
                            }
                        }
                        else if (elem.type == RichType.ANIM || elem.type == RichType.IMAGE)
                        {
                            lines++;
                            elem.pos = new Vector2(0, -lines * height);
                            oneLine  = elem.width;
                        }
                    }
                    else
                    {
                        elem.pos = new Vector2(oneLine, -lines * height);
                        oneLine += (elem.width + 1 + countNumber(elem.strChar));//元素间距
                    }
                }
                if (isReplaceInSpace == false)
                {
                    _elemRenderArr[i] = elem;
                }
            }
            //sort all lines
            Dictionary <int, List <LRenderElement> > rendElemLineMap = new Dictionary <int, List <LRenderElement> >();
            List <int> lineKeyList = new List <int>();

            len = _elemRenderArr.Count;
            for (int i = 0; i < len; i++)
            {
                LRenderElement        elem = _elemRenderArr[i];
                List <LRenderElement> lineList;

                if (!rendElemLineMap.ContainsKey((int)elem.pos.y))
                {
                    lineList = new List <LRenderElement>();
                    rendElemLineMap[(int)elem.pos.y] = lineList;
                }
                rendElemLineMap[(int)elem.pos.y].Add(elem);
            }
            // all lines in arr
            List <List <LRenderElement> > rendLineArrs = new List <List <LRenderElement> >();

            foreach (var item in rendElemLineMap)
            {
                lineKeyList.Add(-1 * item.Key);
            }
            lineKeyList.Sort();
            len = lineKeyList.Count;

            for (int i = 0; i < len; i++)
            {
                int            posY                = -1 * lineKeyList[i];
                string         lineString          = "";
                LRenderElement _lastEleme          = rendElemLineMap[posY][0];
                LRenderElement _lastDiffStartEleme = rendElemLineMap[posY][0];
                Vector2        counter             = Vector2.zero;
                if (rendElemLineMap[posY].Count > 0)
                {
                    List <LRenderElement> lineElemArr = new List <LRenderElement>();
                    foreach (LRenderElement elem in rendElemLineMap[posY])
                    {
                        if (_lastEleme.type == RichType.TEXT && elem.type == RichType.TEXT)
                        {
                            if (_lastEleme.color == elem.color && (_lastEleme.data == elem.data || elem.data == ""))//fixed:相同颜色,不同data触发结果相同的BUG
                            {
                                // the same color and same data can mergin one string
                                lineString += elem.strChar;
                            }
                            else // diff color
                            {
                                if (_lastDiffStartEleme.type == RichType.TEXT)
                                {
                                    LRenderElement _newElem = _lastDiffStartEleme.Clone();
                                    _newElem.strChar = lineString;
                                    //_newElem.pos += new Vector2(-5, 0);
                                    lineElemArr.Add(_newElem);

                                    _lastDiffStartEleme = elem;

                                    counter = counter + new Vector2(newElemOffset, 0);
                                    _lastDiffStartEleme.pos = _lastDiffStartEleme.pos + counter;
                                    lineString = elem.strChar;
                                }
                            }
                        }
                        else if (elem.type == RichType.IMAGE || elem.type == RichType.ANIM || elem.type == RichType.NEWLINE)
                        {
                            //interrupt
                            if (_lastDiffStartEleme.type == RichType.TEXT)
                            {
                                LRenderElement _newEleme = _lastDiffStartEleme.Clone();
                                _newEleme.strChar = lineString;
                                lineString        = "";
                                lineElemArr.Add(_newEleme);
                            }
                            lineElemArr.Add(elem);
                        }
                        else if (_lastEleme.type != RichType.TEXT)
                        {
                            //interrupt
                            _lastDiffStartEleme = elem;
                            if (elem.type == RichType.TEXT)
                            {
                                lineString = elem.strChar;
                            }
                        }
                        _lastEleme = elem;
                    }
                    // the last elementText
                    if (_lastDiffStartEleme.type == RichType.TEXT)
                    {
                        LRenderElement _newElem = _lastDiffStartEleme.Clone();
                        _newElem.strChar = lineString;
                        lineElemArr.Add(_newElem);
                    }
                    rendLineArrs.Add(lineElemArr);
                }
            }

            // offset position
            int _offsetLineY  = 0;
            int oneLineHeight = font.fontSize;

            realLineHeight = 0;
            len            = rendLineArrs.Count;
            for (int i = 0; i < len; i++)
            {
                List <LRenderElement> _lines = rendLineArrs[i];
                int _lineHeight = 0;
                foreach (LRenderElement elem in _lines)
                {
                    _lineHeight = Mathf.Max(_lineHeight, elem.height);
                }
                oneLineHeight   = _lineHeight;
                realLineHeight += _lineHeight;
                _offsetLineY   += (_lineHeight - height);

                int _len = _lines.Count;
                for (int j = 0; j < _len; j++)
                {
                    LRenderElement elem = _lines[j];
                    elem.pos       = new Vector2(elem.pos.x, elem.pos.y - _offsetLineY);
                    realLineHeight = Mathf.Max(realLineHeight, (int)Mathf.Abs(elem.pos.y));
                    _lines[j]      = elem;
                }
                rendLineArrs[i] = _lines;
            }

            // place all position
            realLineWidth = 0;
            GameObject obj          = null;
            GameObject _lastGo      = null;
            float      _lastGoWidth = 0;

            foreach (List <LRenderElement> _lines in rendLineArrs)
            {
                int _lineWidth = 0;
                _lastGo = null;
                foreach (LRenderElement elem in _lines)
                {
                    if (elem.type != RichType.NEWLINE)
                    {
                        if (elem.type == RichType.TEXT)
                        {
                            obj = getCacheLabel();
                            makeLabel(obj, elem);
                            _lineWidth += ( int )obj.GetComponent <Text>().preferredWidth;
                        }
                        else if (elem.type == RichType.IMAGE)
                        {
                            obj = getCacheImage(true);
                            makeImage(obj, elem);
                            _lineWidth += ( int )obj.GetComponent <Image>().preferredWidth;
                        }
                        else if (elem.type == RichType.ANIM)
                        {
                            obj = getCacheFramAnim();
                            makeFramAnim(obj, elem);
                            _lineWidth += elem.width;
                        }
                        obj.transform.SetParent(transform);
                        float newPosY = elem.pos.y;
                        if (Mathf.Abs(elem.pos.y) != oneLineHeight)
                        {
                            uVerticalOffset = verticalOffset + uVerticalOffset;
                            newPosY         = newPosY + uVerticalOffset;
                        }
                        obj.transform.localPosition = new Vector2(
                            x: _lastGo == null ? elem.pos.x : _lastGo.transform.localPosition.x + _lastGoWidth,
                            //y: newPosY
                            y: _lastGo == null ? newPosY : _lastGo.transform.localPosition.y
                            );

                        _objectDataMap[obj] = elem.data;
                        _lastGo             = obj;

                        if (elem.type == RichType.ANIM)
                        {
                            _lastGoWidth = elem.width; continue;
                        }

                        _lastGoWidth = elem.type == RichType.TEXT ? obj.GetComponent <Text>().preferredWidth : obj.GetComponent <Image>().preferredWidth;
                    }
                }

                realLineWidth = Mathf.Max(_lineWidth, realLineWidth);
            }
            RectTransform rtran = this.GetComponent <RectTransform>();

            //align
            if (alignType == RichAlignType.DESIGN_CENTER)
            {
                rtran.sizeDelta = new Vector2(maxLineWidth, realLineHeight);
            }
            else if (alignType == RichAlignType.LEFT_TOP)
            {
                rtran.sizeDelta = new Vector2(realLineWidth, realLineHeight);
            }
        }
Beispiel #18
0
        public void reloadData()
        {
            this.removeAllElements();

            RectTransform rtran = this.GetComponent <RectTransform>();

            //align
            if (alignType == RichAlignType.DESIGN_CENTER)
            {
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f);
            }
            else if (alignType == RichAlignType.LEFT_TOP)
            {
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0f, 1f);
            }

            foreach (LRichElement elem in richElements)
            {
                if (elem.type == RichType.TEXT)
                {
                    LRichElementText elemText = elem as LRichElementText;
                    char[]           _charArr = elemText.txt.ToCharArray();
                    TextGenerator    gen      = new TextGenerator();

                    foreach (char strChar in _charArr)
                    {
                        LRenderElement rendElem = new LRenderElement();
                        rendElem.type        = RichType.TEXT;
                        rendElem.strChar     = strChar.ToString();
                        rendElem.isOutLine   = elemText.isOutLine;
                        rendElem.isUnderLine = elemText.isUnderLine;
                        rendElem.font        = this.font;
                        rendElem.fontSize    = elemText.fontSize;
                        rendElem.data        = elemText.data;
                        rendElem.color       = elemText.color;

                        TextGenerationSettings setting = new TextGenerationSettings();
                        setting.font               = this.font;
                        setting.fontSize           = elemText.fontSize;
                        setting.lineSpacing        = 1;
                        setting.scaleFactor        = 1;
                        setting.verticalOverflow   = VerticalWrapMode.Overflow;
                        setting.horizontalOverflow = HorizontalWrapMode.Overflow;

                        rendElem.width  = (int)gen.GetPreferredWidth(rendElem.strChar, setting);
                        rendElem.height = (int)gen.GetPreferredHeight(rendElem.strChar, setting);
                        elemRenderArr.Add(rendElem);
                    }
                }
                else if (elem.type == RichType.IMAGE)
                {
                    LRichElementImage elemImg  = elem as LRichElementImage;
                    LRenderElement    rendElem = new LRenderElement();
                    rendElem.type = RichType.IMAGE;
                    rendElem.path = elemImg.path;
                    rendElem.data = elemImg.data;

                    Sprite sp = Resources.Load(rendElem.path, typeof(Sprite)) as Sprite;
                    rendElem.width  = sp.texture.width;
                    rendElem.height = sp.texture.height;
                    elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.ANIM)
                {
                    LRichElementAnim elemAnim = elem as LRichElementAnim;
                    LRenderElement   rendElem = new LRenderElement();
                    rendElem.type = RichType.ANIM;
                    rendElem.path = elemAnim.path;
                    rendElem.data = elemAnim.data;
                    rendElem.fs   = elemAnim.fs;

                    Sprite sp = Resources.Load(rendElem.path + "/1", typeof(Sprite)) as Sprite;
                    rendElem.width  = sp.texture.width;
                    rendElem.height = sp.texture.height;
                    elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.NEWLINE)
                {
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.isNewLine = true;
                    elemRenderArr.Add(rendElem);
                }
            }

            richElements.Clear();

            formarRenderers();
        }
Beispiel #19
0
        void makeLabel(GameObject lab, LRenderElement elem)
        {
            Text comText = lab.GetComponent<Text>();
            if (comText != null)
            {
                comText.text = elem.strChar;
                comText.font = elem.font;
                comText.fontSize = elem.fontSize;
                comText.fontStyle = FontStyle.Normal;
                comText.color = elem.color;
            }

            Outline outline = lab.GetComponent<Outline>();
            if (elem.isOutLine)
            {
                if (outline == null)
                {
                    outline = lab.AddComponent<Outline>();
                }
            }
            else {
                if (outline)
                {
                    Destroy(outline);
                }
            }

            if (elem.isUnderLine)
            {
                GameObject underLine = getCacheImage(false);
                Image underImg = underLine.GetComponent<Image>();
                underImg.color = elem.color;
                underImg.GetComponent<RectTransform>().sizeDelta = new Vector2(comText.preferredWidth, 1);
                underLine.transform.SetParent(transform);
                underLine.transform.localScale = new Vector2(1, 1);
                underLine.transform.localPosition = new Vector2(elem.pos.x, elem.pos.y);
            }
        }
Beispiel #20
0
 void makeImage(GameObject img, LRenderElement elem)
 {
     Image comImage = img.GetComponent<Image>();
     if (comImage != null)
     {
         Sprite sp = LLoadBundle.GetInstance().LoadAsset(LGameConfig.WINDOW_BUNDLE, elem.path, typeof(Sprite)) as Sprite;
         comImage.sprite = sp;
     }
 }
Beispiel #21
0
        public void reloadData()
        {
            this.removeAllElements();

            RectTransform rtran = this.GetComponent<RectTransform>();
            //align
            if (alignType == RichAlignType.DESIGN_CENTER)
            {
                rtran.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);

            }
            else if (alignType == RichAlignType.LEFT_TOP)
            {
                rtran.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
            }

            foreach (LRichElement elem in _richElements)
            {
                if (elem.type == RichType.TEXT)
                {
                    LRichElementText elemText = elem as LRichElementText;
                    char[] _charArr = elemText.txt.ToCharArray();
                    TextGenerator gen = new TextGenerator();

                    foreach (char strChar in _charArr)
                    {
                        LRenderElement rendElem = new LRenderElement();
                        rendElem.type = RichType.TEXT;
                        rendElem.strChar = strChar.ToString();
                        rendElem.isOutLine = elemText.isOutLine;
                        rendElem.isUnderLine = elemText.isUnderLine;
                        rendElem.font = this.font;
                        rendElem.fontSize = elemText.fontSize;
                        rendElem.data = elemText.data;
                        rendElem.color = elemText.color;

                        TextGenerationSettings setting = new TextGenerationSettings();
                        setting.font = this.font;
                        setting.fontSize = elemText.fontSize;
                        setting.lineSpacing = 1;
                        setting.scaleFactor = 1;
                        setting.verticalOverflow = VerticalWrapMode.Overflow;
                        setting.horizontalOverflow = HorizontalWrapMode.Overflow;

                        rendElem.width = (int)gen.GetPreferredWidth(rendElem.strChar, setting);
                        rendElem.height = (int)gen.GetPreferredHeight(rendElem.strChar, setting);
                        _elemRenderArr.Add(rendElem);
                    }
                }
                else if (elem.type == RichType.IMAGE)
                {
                    LRichElementImage elemImg = elem as LRichElementImage;
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.type = RichType.IMAGE;
                    rendElem.path = elemImg.path;
                    rendElem.data = elemImg.data;
                    Sprite sp = LLoadBundle.GetInstance().LoadAsset(LGameConfig.WINDOW_BUNDLE, rendElem.path, typeof(Sprite)) as Sprite;
                    // Sprite sp = Resources.Load(rendElem.path,typeof(Sprite)) as Sprite;
                    rendElem.width = sp.texture.width;
                    rendElem.height = sp.texture.height;
                    _elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.ANIM)
                {
                    LRichElementAnim elemAnim = elem as LRichElementAnim;
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.type = RichType.ANIM;
                    rendElem.path = elemAnim.path;
                    rendElem.data = elemAnim.data;
                    rendElem.fs = elemAnim.fs;

                    Sprite sp = LLoadBundle.GetInstance().LoadAsset(LGameConfig.WINDOW_BUNDLE, rendElem.path + "/1", typeof(Sprite)) as Sprite;
                    // Sprite sp = Resources.Load(rendElem.path+"/1",typeof(Sprite)) as Sprite;
                    rendElem.width = sp.texture.width;
                    rendElem.height = sp.texture.height;
                    _elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.NEWLINE)
                {
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.isNewLine = true;
                    _elemRenderArr.Add(rendElem);
                }
            }

            _richElements.Clear();

            formarRenderers();
        }
        public void reloadData(float newElemOffset = 3.5f)
        {
            this.removeAllElements();
            RectTransform rtran = this.GetComponent <RectTransform>();

            //align
            switch (alignType)
            {
            default:
            case RichAlignType.LEFT_TOP:
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0f, 1f);
                break;

            case RichAlignType.DESIGN_CENTER:
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f);
                break;

            case RichAlignType.RIGHT_BOTTOM:
                rtran.GetComponent <RectTransform>().pivot = new Vector2(1f, 0f);
                break;

            case RichAlignType.LEFT_BOTTOM:
                rtran.GetComponent <RectTransform>().pivot = new Vector2(0f, 0f);
                break;
            }
            for (int i = 0; i < _richElements.Count; i++)
            {
                LRichElement elem = _richElements[i];
                if (elem.type == RichType.TEXT)
                {
                    LRichElementText elemText = elem as LRichElementText;
                    char[]           _charArr = elemText.txt.ToCharArray();
                    TextGenerator    gen      = new TextGenerator();
                    for (int j = 0; j < _charArr.Length; j++)
                    {
                        char           strChar  = _charArr[j];
                        LRenderElement rendElem = new LRenderElement();
                        rendElem.type        = RichType.TEXT;
                        rendElem.strChar     = strChar.ToString();
                        rendElem.isOutLine   = elemText.isOutLine;
                        rendElem.isUnderLine = elemText.isUnderLine;
                        rendElem.font        = this.font;
                        rendElem.fontSize    = elemText.fontSize;
                        rendElem.data        = elemText.data;
                        float r = elemText.color.r,
                              g = elemText.color.g,
                              b = elemText.color.b;
                        if (r > 1)
                        {
                            r = r / 255f;
                        }
                        if (g > 1)
                        {
                            g = g / 255f;
                        }
                        if (b > 1)
                        {
                            b = b / 255f;
                        }
                        rendElem.color = new Color(r, g, b);

                        TextGenerationSettings setting = new TextGenerationSettings();
                        setting.font        = this.font;
                        setting.fontSize    = elemText.fontSize;
                        setting.lineSpacing = 1;
                        //setting.scaleFactor = 1;
                        setting.verticalOverflow   = VerticalWrapMode.Overflow;
                        setting.horizontalOverflow = HorizontalWrapMode.Overflow;

                        rendElem.width  = (int)gen.GetPreferredWidth(rendElem.strChar, setting);
                        rendElem.height = (int)gen.GetPreferredHeight(rendElem.strChar, setting);
                        _elemRenderArr.Add(rendElem);
                    }
                }
                else if (elem.type == RichType.IMAGE)
                {
                    LRichElementImage elemImg  = elem as LRichElementImage;
                    LRenderElement    rendElem = new LRenderElement();
                    rendElem.type = RichType.IMAGE;
                    rendElem.path = elemImg.path;
                    rendElem.data = elemImg.data;

                    Sprite sp = GAMEAPI.ABUI_LoadSprite(rendElem.path);
                    rendElem.width  = (int)sp.rect.size.x;
                    rendElem.height = (int)sp.rect.size.y;
                    _elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.ANIM)
                {
                    LRichElementAnim elemAnim = elem as LRichElementAnim;
                    LRenderElement   rendElem = new LRenderElement();
                    rendElem.type = RichType.ANIM;
                    rendElem.path = elemAnim.path;
                    rendElem.data = elemAnim.data;
                    rendElem.fs   = elemAnim.fs;

                    Sprite sp = GAMEAPI.ABUI_LoadSprite(rendElem.path + "/1");
                    rendElem.width  = (int)sp.rect.size.x;
                    rendElem.height = (int)sp.rect.size.y;
                    _elemRenderArr.Add(rendElem);
                }
                else if (elem.type == RichType.NEWLINE)
                {
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.isNewLine = true;
                    _elemRenderArr.Add(rendElem);
                }
            }

            _richElements.Clear();

            formarRenderers(newElemOffset);
        }
Beispiel #23
0
        protected void formarRenderers()
        {
            int num   = 0;
            int num2  = 1;
            int num3  = 27;
            int count = this._elemRenderArr.Count;

            for (int i = 0; i < count; i++)
            {
                bool           flag           = false;
                LRenderElement lRenderElement = this._elemRenderArr[i];
                bool           isNewLine      = lRenderElement.isNewLine;
                if (isNewLine)
                {
                    num = 0;
                    num2++;
                    lRenderElement.width  = 10;
                    lRenderElement.height = num3;
                    lRenderElement.pos    = new Vector2((float)num, (float)(-(float)num2 * num3));
                }
                else
                {
                    bool flag2 = num + lRenderElement.width > this.maxLineWidth;
                    if (flag2)
                    {
                        bool flag3 = lRenderElement.type == RichType.TEXT;
                        if (flag3)
                        {
                            bool flag4 = this.isChinese(lRenderElement.strChar) || lRenderElement.strChar == " ";
                            if (flag4)
                            {
                                num = 0;
                                num2++;
                                lRenderElement.pos = new Vector2((float)num, (float)(-(float)num2 * num3));
                                num = lRenderElement.width;
                            }
                            else
                            {
                                int num4 = 0;
                                int j    = i;
                                while (j > 0)
                                {
                                    j--;
                                    bool flag5 = this._elemRenderArr[j].strChar == " " && this._elemRenderArr[j].pos.y == this._elemRenderArr[i - 1].pos.y;
                                    if (flag5)
                                    {
                                        num4 = j;
                                        break;
                                    }
                                }
                                bool flag6 = num4 == 0;
                                if (flag6)
                                {
                                    num = 0;
                                    num2++;
                                    lRenderElement.pos = new Vector2((float)num, (float)(-(float)num2 * num3));
                                    num = lRenderElement.width;
                                }
                                else
                                {
                                    num = 0;
                                    num2++;
                                    flag = true;
                                    for (int k = num4 + 1; k <= i; k++)
                                    {
                                        LRenderElement lRenderElement2 = this._elemRenderArr[k];
                                        lRenderElement2.pos = new Vector2((float)num, (float)(-(float)num2 * num3));
                                        num += lRenderElement2.width;
                                        this._elemRenderArr[k] = lRenderElement2;
                                    }
                                }
                            }
                        }
                        else
                        {
                            bool flag7 = lRenderElement.type == RichType.ANIM || lRenderElement.type == RichType.IMAGE;
                            if (flag7)
                            {
                                num2++;
                                lRenderElement.pos = new Vector2(0f, (float)(-(float)num2 * num3));
                                num = lRenderElement.width;
                            }
                        }
                    }
                    else
                    {
                        lRenderElement.pos = new Vector2((float)num, (float)(-(float)num2 * num3));
                        num += lRenderElement.width + 1 + this.countNumber(lRenderElement.strChar);
                    }
                }
                bool flag8 = !flag;
                if (flag8)
                {
                    this._elemRenderArr[i] = lRenderElement;
                }
            }
            Dictionary <int, List <LRenderElement> > dictionary = new Dictionary <int, List <LRenderElement> >();
            List <int> list = new List <int>();

            count = this._elemRenderArr.Count;
            for (int l = 0; l < count; l++)
            {
                LRenderElement lRenderElement3 = this._elemRenderArr[l];
                bool           flag9           = !dictionary.ContainsKey((int)lRenderElement3.pos.y);
                if (flag9)
                {
                    List <LRenderElement> value = new List <LRenderElement>();
                    dictionary[(int)lRenderElement3.pos.y] = value;
                }
                dictionary[(int)lRenderElement3.pos.y].Add(lRenderElement3);
            }
            List <List <LRenderElement> > list2 = new List <List <LRenderElement> >();

            foreach (KeyValuePair <int, List <LRenderElement> > current in dictionary)
            {
                list.Add(-1 * current.Key);
            }
            list.Sort();
            count = list.Count;
            for (int m = 0; m < count; m++)
            {
                int            key             = -1 * list[m];
                string         text            = "";
                LRenderElement lRenderElement4 = dictionary[key][0];
                LRenderElement lRenderElement5 = dictionary[key][0];
                bool           flag10          = dictionary[key].Count > 0;
                if (flag10)
                {
                    List <LRenderElement> list3 = new List <LRenderElement>();
                    foreach (LRenderElement current2 in dictionary[key])
                    {
                        bool flag11 = lRenderElement4.type == RichType.TEXT && current2.type == RichType.TEXT;
                        if (flag11)
                        {
                            bool flag12 = lRenderElement4.color == current2.color && (lRenderElement4.data == current2.data || current2.data == "");
                            if (flag12)
                            {
                                text += current2.strChar;
                            }
                            else
                            {
                                bool flag13 = lRenderElement5.type == RichType.TEXT;
                                if (flag13)
                                {
                                    LRenderElement item = lRenderElement5.Clone();
                                    item.strChar = text;
                                    list3.Add(item);
                                    lRenderElement5 = current2;
                                    text            = current2.strChar;
                                }
                            }
                        }
                        else
                        {
                            bool flag14 = current2.type == RichType.IMAGE || current2.type == RichType.ANIM || current2.type == RichType.NEWLINE;
                            if (flag14)
                            {
                                bool flag15 = lRenderElement5.type == RichType.TEXT;
                                if (flag15)
                                {
                                    LRenderElement item2 = lRenderElement5.Clone();
                                    item2.strChar = text;
                                    text          = "";
                                    list3.Add(item2);
                                }
                                list3.Add(current2);
                            }
                            else
                            {
                                bool flag16 = lRenderElement4.type > RichType.TEXT;
                                if (flag16)
                                {
                                    lRenderElement5 = current2;
                                    bool flag17 = current2.type == RichType.TEXT;
                                    if (flag17)
                                    {
                                        text = current2.strChar;
                                    }
                                }
                            }
                        }
                        lRenderElement4 = current2;
                    }
                    bool flag18 = lRenderElement5.type == RichType.TEXT;
                    if (flag18)
                    {
                        LRenderElement item3 = lRenderElement5.Clone();
                        item3.strChar = text;
                        list3.Add(item3);
                    }
                    list2.Add(list3);
                }
            }
            int num5 = 0;
            int num6 = this.font.fontSize;

            this.realLineHeight = 0;
            count = list2.Count;
            for (int n = 0; n < count; n++)
            {
                List <LRenderElement> list4 = list2[n];
                int num7 = 0;
                foreach (LRenderElement current3 in list4)
                {
                    num7 = Mathf.Max(num7, current3.height);
                }
                num6 = num7;
                this.realLineHeight += num7;
                num5 += num7 - num3;
                int count2 = list4.Count;
                for (int num8 = 0; num8 < count2; num8++)
                {
                    LRenderElement lRenderElement6 = list4[num8];
                    lRenderElement6.pos = new Vector2(lRenderElement6.pos.x, lRenderElement6.pos.y - (float)num5);
                    this.realLineHeight = Mathf.Max(this.realLineHeight, (int)Mathf.Abs(lRenderElement6.pos.y));
                    list4[num8]         = lRenderElement6;
                }
                list2[n] = list4;
            }
            this.realLineWidth = 0;
            GameObject gameObject = null;

            foreach (List <LRenderElement> current4 in list2)
            {
                int num9 = 0;
                foreach (LRenderElement current5 in current4)
                {
                    bool flag19 = current5.type != RichType.NEWLINE;
                    if (flag19)
                    {
                        bool flag20 = current5.type == RichType.TEXT;
                        if (flag20)
                        {
                            gameObject = this.getCacheLabel();
                            this.makeLabel(gameObject, current5);
                            num9 += (int)gameObject.GetComponent <Text>().preferredWidth;
                        }
                        else
                        {
                            bool flag21 = current5.type == RichType.IMAGE;
                            if (flag21)
                            {
                                gameObject = this.getCacheImage(true);
                                this.makeImage(gameObject, current5);
                                num9 += (int)gameObject.GetComponent <Image>().preferredWidth;
                            }
                            else
                            {
                                bool flag22 = current5.type == RichType.ANIM;
                                if (flag22)
                                {
                                    gameObject = this.getCacheFramAnim();
                                    this.makeFramAnim(gameObject, current5);
                                    num9 += current5.width;
                                }
                            }
                        }
                        gameObject.transform.SetParent(base.transform);
                        gameObject.transform.localPosition = new Vector2(current5.pos.x, (Mathf.Abs(current5.pos.y) != (float)num6) ? (current5.pos.y + (float)this.verticalOffset) : current5.pos.y);
                        this._objectDataMap[gameObject]    = current5.data;
                    }
                }
                this.realLineWidth = Mathf.Max(num9, this.realLineWidth);
            }
            RectTransform component = base.GetComponent <RectTransform>();
            bool          flag23    = this.alignType == RichAlignType.DESIGN_CENTER;

            if (flag23)
            {
                component.sizeDelta = new Vector2((float)this.maxLineWidth, (float)this.realLineHeight);
            }
            else
            {
                bool flag24 = this.alignType == RichAlignType.LEFT_TOP;
                if (flag24)
                {
                    component.sizeDelta = new Vector2((float)this.realLineWidth, (float)this.realLineHeight);
                }
            }
        }
Beispiel #24
0
        public void reloadData()
        {
            this.removeAllElements();
            RectTransform component = base.GetComponent <RectTransform>();

            switch (this.alignType)
            {
            case RichAlignType.DESIGN_CENTER:
                component.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f);
                goto IL_A2;

            case RichAlignType.LEFT_TOP:
IL_2E:
                component.GetComponent <RectTransform>().pivot = new Vector2(0f, 1f);
                goto IL_A2;

            case RichAlignType.LEFT_BOTTOM:
                component.GetComponent <RectTransform>().pivot = new Vector2(0f, 0f);
                goto IL_A2;

            case RichAlignType.RIGHT_BOTTOM:
                component.GetComponent <RectTransform>().pivot = new Vector2(1f, 0f);
                goto IL_A2;
            }
            goto IL_2E;
IL_A2:
            foreach (LRichElement current in this._richElements)
            {
                bool flag = current.type == RichType.TEXT;
                if (flag)
                {
                    LRichElementText lRichElementText = current as LRichElementText;
                    char[]           array            = lRichElementText.txt.ToCharArray();
                    TextGenerator    textGenerator    = new TextGenerator();
                    char[]           array2           = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        char           c = array2[i];
                        LRenderElement lRenderElement = default(LRenderElement);
                        lRenderElement.type        = RichType.TEXT;
                        lRenderElement.strChar     = c.ToString();
                        lRenderElement.isOutLine   = lRichElementText.isOutLine;
                        lRenderElement.isUnderLine = lRichElementText.isUnderLine;
                        lRenderElement.font        = this.font;
                        lRenderElement.fontSize    = lRichElementText.fontSize;
                        lRenderElement.data        = lRichElementText.data;
                        lRenderElement.color       = lRichElementText.color;
                        TextGenerationSettings settings = default(TextGenerationSettings);
                        settings.font               = this.font;
                        settings.fontSize           = lRichElementText.fontSize;
                        settings.lineSpacing        = 1f;
                        settings.verticalOverflow   = VerticalWrapMode.Overflow;
                        settings.horizontalOverflow = HorizontalWrapMode.Overflow;
                        lRenderElement.width        = (int)textGenerator.GetPreferredWidth(lRenderElement.strChar, settings);
                        lRenderElement.height       = (int)textGenerator.GetPreferredHeight(lRenderElement.strChar, settings);
                        this._elemRenderArr.Add(lRenderElement);
                    }
                }
                else
                {
                    bool flag2 = current.type == RichType.IMAGE;
                    if (flag2)
                    {
                        LRichElementImage lRichElementImage = current as LRichElementImage;
                        LRenderElement    lRenderElement2   = default(LRenderElement);
                        lRenderElement2.type = RichType.IMAGE;
                        lRenderElement2.path = lRichElementImage.path;
                        lRenderElement2.data = lRichElementImage.data;
                        Sprite sprite = Resources.Load(lRenderElement2.path, typeof(Sprite)) as Sprite;
                        lRenderElement2.width  = (int)sprite.rect.size.x;
                        lRenderElement2.height = (int)sprite.rect.size.y;
                        this._elemRenderArr.Add(lRenderElement2);
                    }
                    else
                    {
                        bool flag3 = current.type == RichType.ANIM;
                        if (flag3)
                        {
                            LRichElementAnim lRichElementAnim = current as LRichElementAnim;
                            LRenderElement   lRenderElement3  = default(LRenderElement);
                            lRenderElement3.type = RichType.ANIM;
                            lRenderElement3.path = lRichElementAnim.path;
                            lRenderElement3.data = lRichElementAnim.data;
                            lRenderElement3.fs   = lRichElementAnim.fs;
                            Sprite sprite2 = Resources.Load(lRenderElement3.path + "/1", typeof(Sprite)) as Sprite;
                            lRenderElement3.width  = (int)sprite2.rect.size.x;
                            lRenderElement3.height = (int)sprite2.rect.size.y;
                            this._elemRenderArr.Add(lRenderElement3);
                        }
                        else
                        {
                            bool flag4 = current.type == RichType.NEWLINE;
                            if (flag4)
                            {
                                LRenderElement item = default(LRenderElement);
                                item.isNewLine = true;
                                this._elemRenderArr.Add(item);
                            }
                        }
                    }
                }
            }
            this._richElements.Clear();
            this.formarRenderers();
        }
Beispiel #25
0
 void makeFramAnim(GameObject anim, LRenderElement elem)
 {
     LMovieClip comFram = anim.GetComponent<LMovieClip>();
     if (comFram != null)
     {
         comFram.path = elem.path;
         comFram.fps = elem.fs;
         comFram.loadTexture();
         comFram.play();
     }
 }
Beispiel #26
0
 void makeImage(GameObject img, LRenderElement elem)
 {
     Image comImage = img.GetComponent<Image>();
     if (comImage != null)
     {
     Sprite sp = Resources.Load(elem.path,typeof(Sprite)) as Sprite;
     comImage.sprite = sp;
     }
 }