Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        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);
        }