public static LegoTextMeta Create(YuLegoText text)
        {
            var meta = new LegoTextMeta
            {
                StyleId       = text.StyleId,
                Content       = text.text,
                RaycastTarget = text.raycastTarget,

                FontId    = text.font.name,
                FontStyle = text.fontStyle.ToString().AsEnum <LegoTextFontStyle>(),
                FontSize  = text.fontSize,
                ////Color = YuColor.Create(text.color),
                RichText    = text.supportRichText,
                LineSpacing = text.lineSpacing,

                VerticalOverflow   = text.verticalOverflow.ToString().AsEnum <LegoTextVerticalOverflow>(),
                HorizontalOverflow = text.horizontalOverflow
                                     .ToString().AsEnum <LegoTextHorizontalOverflow>(),

                BestFit         = text.resizeTextForBestFit,
                Alignment       = text.alignment.ToString().AsEnum <LegoTextAlignment>(),
                AlignByGeometry = text.alignByGeometry
            };

            return(meta);
        }
예제 #2
0
        public static LegoTextStyleMeta Create(YuLegoText text)
        {
            var meta = new LegoTextStyleMeta
            {
                FontName  = text.font == null ? null : text.font.name,
                FontStyle = text.font == null
                    ? LegoTextFontStyle.Normal
                    : text.fontStyle.ToString().AsEnum <LegoTextFontStyle>(),
                FontSize           = text.font == null ? 20 : text.fontSize,
                LineSpacing        = text.lineSpacing,
                SupportRichText    = text.supportRichText,
                Alignment          = text.alignment.ToString().AsEnum <LegoTextAlignment>(),
                AlignByGeometry    = text.alignByGeometry,
                HorizontalOverflow = text.horizontalOverflow.ToString()
                                     .AsEnum <LegoTextHorizontalOverflow>(),
                VerticalOverflow = text.verticalOverflow.ToString()
                                   .AsEnum <LegoTextVerticalOverflow>(),
                BestFit       = text.resizeTextForBestFit,
                TextLegoColor = LegoColorMeta.Create(text.color),
                Material      = text.material == null ? null : text.material.name,
                RaycastTarget = text.raycastTarget
            };

            return(meta);
        }
        public static void UntrackText(YuLegoText t)
        {
            if (t.font == null)
            {
                return;
            }

            HashSet <YuLegoText> texts;

            m_Tracked.TryGetValue(t.font, out texts);

            if (texts == null)
            {
                return;
            }

            texts.Remove(t);

            if (texts.Count == 0)
            {
                m_Tracked.Remove(t.font);

                // There is a global textureRebuilt event for all fonts, so once the last Text reference goes away, remove our delegate
                if (m_Tracked.Count == 0)
                {
                    Font.textureRebuilt -= RebuildForFont;
                }
            }
        }
        public static void TrackText(YuLegoText t)
        {
            if (t.font == null)
            {
                return;
            }

            HashSet <YuLegoText> exists;

            m_Tracked.TryGetValue(t.font, out exists);
            if (exists == null)
            {
                // The textureRebuilt event is global for all fonts, so we add our delegate the first time we register *any* Text
                if (m_Tracked.Count == 0)
                {
                    Font.textureRebuilt += RebuildForFont;
                }

                exists = new HashSet <YuLegoText>();
                m_Tracked.Add(t.font, exists);
            }

            if (!exists.Contains(t))
            {
                exists.Add(t);
            }
        }
예제 #5
0
        private static void SetDefaultTextValues(YuLegoText lbl)
        {
            // Set text values we want across UI elements in default controls.
            // Don't set values which are the same as the default values for the Text component,
            // since there's no point in that, and it's good to keep them as consistent as possible.
            lbl.color = s_TextColor;

            // Reset() is not called when playing. We still want the default font to be assigned
            lbl.AssignDefaultFont();
        }
 private void ApplyFontStyleToPreviewText(YuLegoText previewText)
 {
     previewText.fontSize  = textSize;
     previewText.font      = font;
     previewText.Color     = color;
     previewText.fontStyle = fontStyle;
     previewText.fontStyle = fontStyle;
     previewText.alignment = TextAnchor;
     SetFontEffect(previewText, isOutLine, isShadow);
     if (preViewTextString != "")
     {
         previewText.text = preViewTextString;
     }
 }
        public void PreviewFontStyle()
        {
            Transform TextContent = PreviewObject.transform.Find
                                        ("Canvas/PreViewUI/Text_Content");
            YuLegoText preViewContent = TextContent.GetComponent <YuLegoText>();
            Transform  TextTitle      = PreviewObject.transform.Find
                                            ("Canvas/PreViewUI/Text_Title");
            YuLegoText preViewTitle = TextTitle.GetComponent <YuLegoText>();

            ApplyFontStyleToPreviewText(preViewContent);
            ApplyFontStyleToPreviewText(preViewTitle);
            preViewTextTexture = GetTextPreviewScreenshot();
            //GameObject.DestroyImmediate(previewObject);
        }
        private static void InitPreviewObject()
        {
            Transform TextContent = previewObject.transform.Find
                                        ("Canvas/PreViewUI/Text_Content");
            YuLegoText preViewContent = TextContent.GetComponent <YuLegoText>();

            if (preViewContent == null)
            {
                preViewContent      = TextContent.gameObject.AddComponent <YuLegoText>();
                preViewContent.text = "文本内容";
            }

            Transform TextTitle = previewObject.transform.Find
                                      ("Canvas/PreViewUI/Text_Title");
            YuLegoText preViewTitle = TextTitle.GetComponent <YuLegoText>();

            if (preViewTitle == null)
            {
                preViewTitle      = TextTitle.gameObject.AddComponent <YuLegoText>();
                preViewTitle.text = "标题";
            }

            Transform TitleBgImage = previewObject.transform.Find
                                         ("Canvas/PreViewUI/Image_Title");
            YuLegoImage preViewTitleBg = TitleBgImage.GetComponent <YuLegoImage>();

            if (preViewTitleBg == null)
            {
                preViewTitleBg       = TitleBgImage.gameObject.AddComponent <YuLegoImage>();
                preViewTitleBg.Color = new Color(0.9f, 0.9f, 0.7f);
            }

            Transform ContentBgImage = previewObject.transform.Find
                                           ("Canvas/PreViewUI/Image_Content");
            YuLegoImage preViewContentBg = ContentBgImage.GetComponent <YuLegoImage>();

            if (preViewContentBg == null)
            {
                preViewContentBg     = ContentBgImage.gameObject.AddComponent <YuLegoImage>();
                preViewTitleBg.Color = new Color(0.4f, 0.4f, 0.4f);
            }
        }
 private void SetFontEffect(YuLegoText previewText, bool isOutLine, bool isShadow)
 {
     if (isOutLine)
     {
         Outline outlineComponent = previewText.gameObject.GetComponent <Outline>();
         if (outlineComponent == null)
         {
             outlineComponent = previewText.gameObject.AddComponent <Outline>();
         }
         outlineComponent.effectColor    = outlineEffectColor;
         outlineComponent.effectDistance = outLineDistance;
     }
     if (isShadow)
     {
         Shadow shdowComponent = previewText.gameObject.GetComponent <Shadow>();
         if (shdowComponent == null)
         {
             shdowComponent = previewText.gameObject.AddComponent <Shadow>();
         }
         shdowComponent.effectColor    = shadowEffectColor;
         shdowComponent.effectDistance = shadowDistance;
     }
 }