Exemple #1
0
        protected void DoAddText(string text, string hrefb, string hrefColor, string hrefEnable, bool isTitle, bool limitReplace)
        {
            if (!limitReplace && 行数限制 > 0 && mNowLineCount >= 行数限制)
            {
                return;
            }
            UILabel       lbl      = null;
            UIFont        font     = UIResourceManager.LoadFont(FontType);
            int           fontSize = mFontSizeTagStack.Peek();
            Color         color    = mFontColorTagStack.Peek();
            UILabelEffect effect   = mFontEffectTagStack.Peek();

            if (isTitle)
            {
                if (string.IsNullOrEmpty(hrefb))
                {
                    lbl = UIViewHelper.AddUILabel(底板.gameObject, FontType, fontSize, color);
                }
                else
                {
                    UIHyperLinkLabel linkLbl = UIViewHelper.AddHyperLinkLabel(底板.gameObject, FontType, fontSize, color);
                    linkLbl.OnHyperLinkClicked += OnLinkClicked;
                    linkLbl.LinkDataSource      = hrefb;
                    linkLbl.UnderLineColor      = hrefColor;
                    linkLbl.LinkDataEnable      = hrefEnable;
                    lbl = linkLbl;
                }
                Vector2 showSize = new Vector2(lbl.width, lbl.height);
                lbl.overflowMethod = CalcTextSize(ref showSize);
                if (effect.type != UILabel.Effect.None)
                {
                    lbl.effectStyle    = effect.type;
                    lbl.effectDistance = effect.dist;
                    lbl.effectColor    = effect.color;
                }
                lbl.depth = 层级 + 11;
                lbl.text  = text;
                if (mNowWritePos.x > 0)
                {
                    DoChangeLine();
                }
                float x = 0;
                lbl.transform.localPosition = new Vector3(x, mNowWritePos.y - lbl.height * 0.5f);
                //OnUnitAdded(lbl);
                DoChangeLine();
            }
            else
            {
                UILabel.Overflow overflow = UILabel.Overflow.ResizeFreely;
                Vector2          showSize = Vector2.zero;
                if (自动换行)
                {
                    if (视图尺寸.x < fontSize)
                    {
                        Debug.LogError("富文本设置为自动换行后,视图尺寸至少大于等于一个字的宽度");
                        return;
                    }
                    string nextLineText = "";
                    string splitText    = text;
                    showSize = CalcTextPrintSize(splitText, font.dynamicFont, fontSize, FontStyle.Normal, true, 1000000, 1000000);
                    overflow = CalcTextSize(ref showSize);
                    float canUseSpace = CalcNowLineCanUsedSpace();
                    if (showSize.x > canUseSpace)
                    {
                        while (showSize.x > canUseSpace)
                        {
                            for (int i = text.Length - 1; i >= 0; --i)
                            {
                                splitText = splitText.Substring(0, i);
                                showSize  = CalcTextPrintSize(splitText, font.dynamicFont, fontSize, FontStyle.Normal, true, 1000000, 1000000);
                                overflow  = CalcTextSize(ref showSize);
                                if (showSize.x <= canUseSpace)
                                {
                                    break;
                                }
                            }
                            if (string.IsNullOrEmpty(splitText))
                            {
                                if (DoChangeLine())
                                {
                                    DoAddText(text, hrefb, hrefColor, hrefEnable, false);
                                }
                                return;
                            }
                        }
                        nextLineText = text.Substring(splitText.Length);
                        DoAddText(splitText, hrefb, hrefColor, hrefEnable, false);
                        if (DoChangeLine())
                        {
                            DoAddText(nextLineText, hrefb, hrefColor, hrefEnable, false);
                        }
                        return;
                    }
                }
                if (string.IsNullOrEmpty(hrefb))
                {
                    lbl = UIViewHelper.AddUILabel(底板.gameObject, FontType, fontSize, color);
                }
                else
                {
                    UIHyperLinkLabel linkLbl = UIViewHelper.AddHyperLinkLabel(底板.gameObject, FontType, fontSize, color);
                    linkLbl.OnHyperLinkClicked += OnLinkClicked;
                    linkLbl.LinkDataSource      = hrefb;
                    linkLbl.UnderLineColor      = hrefColor;
                    linkLbl.LinkDataEnable      = hrefEnable;
                    lbl = linkLbl;
                }
                lbl.width          = (int)showSize.x;
                lbl.height         = (int)showSize.y;
                lbl.overflowMethod = overflow;
                if (effect.type != UILabel.Effect.None)
                {
                    lbl.effectStyle    = effect.type;
                    lbl.effectDistance = effect.dist;
                    lbl.effectColor    = effect.color;
                }
                lbl.depth = 层级 + 11;
                lbl.text  = text;
                Vector3 pos = new Vector3(mNowWritePos.x - (视图尺寸.x - (float)lbl.width) * 0.5f, mNowWritePos.y - lbl.height * 0.5f);
                lbl.transform.localPosition = pos;
                OnUnitAdded(lbl);
            }
        }
Exemple #2
0
 protected virtual void OnLinkClicked(UIHyperLinkLabel sender, object data)
 {
 }