private void DrawTextCore(MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint) { TextInfo textInfo = handle.Update(textParams, pixelsPerPoint); for (int i = 0; i < textInfo.materialCount; i++) { bool flag = textInfo.meshInfo[i].vertexCount == 0; if (flag) { break; } this.m_CurrentEntry.isTextEntry = true; this.m_CurrentEntry.clipRectID = this.m_ClipRectID; this.m_CurrentEntry.isStencilClipped = this.m_StencilClip; MeshBuilder.MakeText(textInfo.meshInfo[i], textParams.rect.min, new MeshBuilder.AllocMeshData { alloc = this.m_AllocRawVertsIndicesDelegate }); this.m_CurrentEntry.font = textInfo.meshInfo[i].material.mainTexture; this.m_Entries.Add(this.m_CurrentEntry); this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_CurrentEntry = default(UIRStylePainter.Entry); } }
private void DrawTextNative(MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint) { float scaling = TextHandle.ComputeTextScaling(this.currentElement.worldTransform, pixelsPerPoint); TextNativeSettings textNativeSettings = MeshGenerationContextUtils.TextParams.GetTextNativeSettings(textParams, scaling); using (NativeArray <UnityEngine.UIElements.TextVertex> vertices = TextNative.GetVertices(textNativeSettings)) { bool flag = vertices.Length == 0; if (!flag) { Vector2 offset = TextNative.GetOffset(textNativeSettings, textParams.rect); this.m_CurrentEntry.isTextEntry = true; this.m_CurrentEntry.clipRectID = this.m_ClipRectID; this.m_CurrentEntry.isStencilClipped = this.m_StencilClip; MeshBuilder.MakeText(vertices, offset, new MeshBuilder.AllocMeshData { alloc = this.m_AllocRawVertsIndicesDelegate }); this.m_CurrentEntry.font = textParams.font.material.mainTexture; this.m_Entries.Add(this.m_CurrentEntry); this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_CurrentEntry = default(UIRStylePainter.Entry); this.currentElement.renderChainData.usesLegacyText = true; this.currentElement.renderChainData.disableNudging = true; } } }
public void DrawText(MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint) { bool flag = textParams.font == null; if (!flag) { bool flag2 = this.m_CurrentElement.panel.contextType == ContextType.Editor; if (flag2) { textParams.fontColor *= textParams.playmodeTintColor; } float scaling = TextNative.ComputeTextScaling(this.m_CurrentElement.worldTransform, pixelsPerPoint); TextNativeSettings textNativeSettings = MeshGenerationContextUtils.TextParams.GetTextNativeSettings(textParams, scaling); using (NativeArray <TextVertex> vertices = TextNative.GetVertices(textNativeSettings)) { List <RenderChainTextEntry> arg_91_0 = this.m_CurrentElement.renderChainData.textEntries; int textEntryIndex = this.m_TextEntryIndex; this.m_TextEntryIndex = textEntryIndex + 1; RenderChainTextEntry renderChainTextEntry = arg_91_0[textEntryIndex]; Vector2 offset = TextNative.GetOffset(textNativeSettings, textParams.rect); MeshBuilder.UpdateText(vertices, offset, this.m_CurrentElement.renderChainData.verticesSpace, this.m_XFormClipPages, this.m_IDsFlags, this.m_OpacityPagesSettingsIndex, this.m_MeshDataVerts.Slice(renderChainTextEntry.firstVertex, renderChainTextEntry.vertexCount)); renderChainTextEntry.command.state.font = textParams.font.material.mainTexture; } } }
public float GetLineHeight(int characterIndex, MeshGenerationContextUtils.TextParams textParams, float textScaling, float pixelPerPoint) { Update(textParams, pixelPerPoint); var character = m_TextInfo.textElementInfo[m_TextInfo.characterCount - 1]; var line = m_TextInfo.lineInfo[character.lineNumber]; return(line.lineHeight); }
public int VerticesCount(MeshGenerationContextUtils.TextParams parms, float pixelPerPoint) { Update(parms, pixelPerPoint); var verticesCount = 0; foreach (var meshInfo in textInfo.meshInfo) { verticesCount += meshInfo.vertexCount; } return(verticesCount); }
internal static PanelTextSettings GetTextSettingsFrom(MeshGenerationContextUtils.TextParams textParam) { if (textParam.panel is RuntimePanel runtimePanel) { var textsettings = runtimePanel.panelSettings.textSettings as PanelTextSettings; if (textsettings == null) { Debug.LogFormat(runtimePanel.panelSettings, "PanelSettings is invalid. Please assign a valid PanelTextSettings."); } return(textsettings); } return(PanelTextSettings.EditorTextSettings); }
internal static FontAsset GetFontAsset(MeshGenerationContextUtils.TextParams textParam) { var textSettings = GetTextSettingsFrom(textParam); if (textParam.fontDefinition.fontAsset != null) { return(textParam.fontDefinition.fontAsset as FontAsset); } if (textParam.fontDefinition.font != null) { return(textSettings.GetCachedFontAsset(textParam.fontDefinition.font)); } return(textSettings.GetCachedFontAsset(textParam.font)); }
void UpdatePreferredValues(MeshGenerationContextUtils.TextParams parms) { // 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 parms.rect = new Rect(Vector2.zero, parms.rect.size); int paramsHash = parms.GetHashCode(); if (m_PreviousLayoutSettingsHash == paramsHash) { return; } UpdateGenerationSettingsCommon(parms, m_CurrentLayoutSettings); m_PreferredSize = UnityEngine.TextCore.Text.TextGenerator.GetPreferredValues(m_CurrentLayoutSettings, textInfo); m_PreviousLayoutSettingsHash = paramsHash; }
private static TextOverflowMode GetTextOverflowMode(MeshGenerationContextUtils.TextParams textParams) { if (textParams.textOverflow == TextOverflow.Clip) { return(TextOverflowMode.Masking); } if (textParams.textOverflow != TextOverflow.Ellipsis) { return(TextOverflowMode.Overflow); } if (!textParams.wordWrap && textParams.overflow == OverflowInternal.Hidden) { return(TextOverflowMode.Ellipsis); } return(TextOverflowMode.Overflow); }
public UnityEngine.UIElements.TextInfo Update(MeshGenerationContextUtils.TextParams parms, float pixelsPerPoint) { // 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 parms.rect = new Rect(Vector2.zero, parms.rect.size); int paramsHash = parms.GetHashCode(); if (m_PreviousGenerationSettingsHash == paramsHash) { return(uITKTextInfo); } UpdateGenerationSettingsCommon(parms, m_CurrentGenerationSettings); m_CurrentGenerationSettings.color = parms.fontColor; m_CurrentGenerationSettings.inverseYAxis = true; m_CurrentGenerationSettings.scale = pixelsPerPoint; textInfo.isDirty = true; UnityEngine.TextCore.Text.TextGenerator.GenerateText(m_CurrentGenerationSettings, textInfo); m_PreviousGenerationSettingsHash = paramsHash; return(ConvertTo(textInfo)); }
public void DrawText(MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint) { bool flag = textParams.font == null; if (!flag) { bool flag2 = this.currentElement.panel.contextType == ContextType.Editor; if (flag2) { textParams.fontColor *= textParams.playmodeTintColor; } bool useLegacy = handle.useLegacy; if (useLegacy) { this.DrawTextNative(textParams, handle, pixelsPerPoint); } else { this.DrawTextCore(textParams, handle, pixelsPerPoint); } } }
static void UpdateGenerationSettingsCommon(MeshGenerationContextUtils.TextParams painterParams, UnityEngine.TextCore.Text.TextGenerationSettings settings) { if (settings.textSettings == null) { settings.textSettings = TextUtilities.GetTextSettingsFrom(painterParams); if (settings.textSettings == null) { return; } } settings.fontAsset = TextUtilities.GetFontAsset(painterParams); settings.material = settings.fontAsset.material; // in case rect is not properly set (ex: style has not been resolved), make sure its width at least matches wordWrapWidth var screenRect = painterParams.rect; if (float.IsNaN(screenRect.width)) { screenRect.width = painterParams.wordWrapWidth; } settings.screenRect = screenRect; settings.text = string.IsNullOrEmpty(painterParams.text) ? " " : painterParams.text; settings.fontSize = painterParams.fontSize > 0 ? painterParams.fontSize : settings.fontAsset.faceInfo.pointSize; settings.fontStyle = TextGeneratorUtilities.LegacyStyleToNewStyle(painterParams.fontStyle); settings.textAlignment = TextGeneratorUtilities.LegacyAlignmentToNewAlignment(painterParams.anchor); settings.wordWrap = painterParams.wordWrap; settings.wordWrappingRatio = 0.4f; settings.richText = painterParams.richText; settings.overflowMode = GetTextOverflowMode(painterParams); settings.characterSpacing = painterParams.letterSpacing.value; settings.wordSpacing = painterParams.wordSpacing.value; settings.paragraphSpacing = painterParams.paragraphSpacing.value; }
public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling) { UpdatePreferredValues(parms); return(m_PreferredSize.y); }
public void DrawText(UIRStylePainter painter, MeshGenerationContextUtils.TextParams textParams, float pixelsPerPoint) { painter.DrawTextCore(textParams, this, pixelsPerPoint); }