Пример #1
0
        public static IEnumerator ApplyModelChanges(ParcelScene scene, TMP_Text text, Model model)
        {
            if (!string.IsNullOrEmpty(model.font))
            {
                yield return(DCLFont.SetFontFromComponent(scene, model.font, text));
            }

            text.text = model.value;

            text.color            = new Color(model.color.r, model.color.g, model.color.b, model.visible ? model.opacity : 0);
            text.fontSize         = (int)model.fontSize;
            text.richText         = true;
            text.overflowMode     = TextOverflowModes.Overflow;
            text.enableAutoSizing = model.fontAutoSize;

            text.margin =
                new Vector4
                (
                    (int)model.paddingLeft,
                    (int)model.paddingTop,
                    (int)model.paddingRight,
                    (int)model.paddingBottom
                );

            text.alignment   = GetAlignment(model.vTextAlign, model.hTextAlign);
            text.lineSpacing = model.lineSpacing;

            if (model.lineCount != 0)
            {
                text.maxVisibleLines = Mathf.Max(model.lineCount, 1);
            }
            else
            {
                text.maxVisibleLines = int.MaxValue;
            }

            text.enableWordWrapping = model.textWrapping && !text.enableAutoSizing;

            if (model.shadowOffsetX != 0 || model.shadowOffsetY != 0)
            {
                text.fontMaterial.EnableKeyword("UNDERLAY_ON");
                text.fontMaterial.SetColor("_UnderlayColor", model.shadowColor);
                text.fontMaterial.SetFloat("_UnderlaySoftness", model.shadowBlur);
            }
            else if (text.fontMaterial.IsKeywordEnabled("UNDERLAY_ON"))
            {
                text.fontMaterial.DisableKeyword("UNDERLAY_ON");
            }

            if (model.outlineWidth > 0f)
            {
                text.fontMaterial.EnableKeyword("OUTLINE_ON");
                text.outlineWidth = model.outlineWidth;
                text.outlineColor = model.outlineColor;
            }
            else if (text.fontMaterial.IsKeywordEnabled("OUTLINE_ON"))
            {
                text.fontMaterial.DisableKeyword("OUTLINE_ON");
            }
        }
Пример #2
0
        public static IEnumerator SetFontFromComponent(ParcelScene scene, string componentId, TMP_Text text)
        {
            if (!scene.disposableComponents.ContainsKey(componentId))
            {
                Debug.Log($"couldn't fetch font, the DCLFont component with id {componentId} doesn't exist");
                yield break;
            }

            DCLFont fontComponent = scene.disposableComponents[componentId] as DCLFont;

            if (fontComponent == null)
            {
                Debug.Log($"couldn't fetch font, the shared component with id {componentId} is NOT a DCLFont");
                yield break;
            }

            while (!fontComponent.loaded && !fontComponent.error)
            {
                yield return(null);
            }

            if (!fontComponent.error)
            {
                text.font = fontComponent.fontAsset;
            }
        }