Example #1
0
        internal void ConvertUssToTextGenerationSettings(UnityEngine.TextCore.Text.TextGenerationSettings tgs)
        {
            var style = m_TextElement.computedStyle;

            if (tgs.textSettings == null)
            {
                tgs.textSettings = TextUtilities.GetTextSettingsFrom(m_TextElement);
                if (tgs.textSettings == null)
                {
                    return;
                }
            }

            tgs.fontAsset = TextUtilities.GetFontAsset(m_TextElement);
            if (tgs.fontAsset == null)
            {
                return;
            }

            tgs.material = tgs.fontAsset.material;
            // The screenRect in TextCore is not properly implemented with regards to the offset part, so zero it out for now and we will add it ourselves later
            tgs.screenRect = new Rect(0, 0, m_TextElement.contentRect.width, m_TextElement.contentRect.height);
            tgs.text       = m_TextElement.isElided && !TextLibraryCanElide() ? m_TextElement.elidedText : m_TextElement.renderedText;

            tgs.fontSize = style.fontSize.value > 0
                ? style.fontSize.value
                : tgs.fontAsset.faceInfo.pointSize;

            tgs.fontStyle     = TextGeneratorUtilities.LegacyStyleToNewStyle(style.unityFontStyleAndWeight);
            tgs.textAlignment = TextGeneratorUtilities.LegacyAlignmentToNewAlignment(style.unityTextAlign);

            tgs.wordWrap = style.whiteSpace == WhiteSpace.Normal;

            tgs.wordWrappingRatio = 0.4f;
            tgs.richText          = m_TextElement.enableRichText;
            tgs.overflowMode      = GetTextOverflowMode();
            tgs.characterSpacing  = style.letterSpacing.value;
            tgs.wordSpacing       = style.wordSpacing.value;
            tgs.paragraphSpacing  = style.unityParagraphSpacing.value;

            tgs.color = style.color;
            tgs.shouldConvertToLinearSpace = false;

            if (m_TextElement.panel?.contextType == ContextType.Editor)
            {
                tgs.color *= UIElementsUtility.editorPlayModeTintColor;
            }

            tgs.inverseYAxis = true;
        }
 public UITKTextHandle(TextElement te)
 {
     m_CurrentGenerationSettings = new UnityEngine.TextCore.Text.TextGenerationSettings();
     textHandle    = new TextHandle();
     m_TextElement = te;
 }