/// <summary> /// Fill Vertex Buffers for Sprites /// </summary> /// <param name="i"></param> /// <param name="generationSettings"></param> /// <param name="textInfo"></param> public static void FillSpriteVertexBuffers(int i, TextGenerationSettings generationSettings, TextInfo textInfo) { int materialIndex = textInfo.textElementInfo[i].materialReferenceIndex; int indexX4 = textInfo.meshInfo[materialIndex].vertexCount; TextElementInfo[] textElementInfoArray = textInfo.textElementInfo; textInfo.textElementInfo[i].vertexIndex = indexX4; // Handle potential axis inversion if (generationSettings.inverseYAxis) { Vector3 axisOffset; axisOffset.x = 0; axisOffset.y = generationSettings.screenRect.y + generationSettings.screenRect.height; axisOffset.z = 0; Vector3 position = textElementInfoArray[i].vertexBottomLeft.position; position.y *= -1; textInfo.meshInfo[materialIndex].vertices[0 + indexX4] = position + axisOffset; position = textElementInfoArray[i].vertexTopLeft.position; position.y *= -1; textInfo.meshInfo[materialIndex].vertices[1 + indexX4] = position + axisOffset; position = textElementInfoArray[i].vertexTopRight.position; position.y *= -1; textInfo.meshInfo[materialIndex].vertices[2 + indexX4] = position + axisOffset; position = textElementInfoArray[i].vertexBottomRight.position; position.y *= -1; textInfo.meshInfo[materialIndex].vertices[3 + indexX4] = position + axisOffset; } else { textInfo.meshInfo[materialIndex].vertices[0 + indexX4] = textElementInfoArray[i].vertexBottomLeft.position; textInfo.meshInfo[materialIndex].vertices[1 + indexX4] = textElementInfoArray[i].vertexTopLeft.position; textInfo.meshInfo[materialIndex].vertices[2 + indexX4] = textElementInfoArray[i].vertexTopRight.position; textInfo.meshInfo[materialIndex].vertices[3 + indexX4] = textElementInfoArray[i].vertexBottomRight.position; } // Setup UVS0 textInfo.meshInfo[materialIndex].uvs0[0 + indexX4] = textElementInfoArray[i].vertexBottomLeft.uv; textInfo.meshInfo[materialIndex].uvs0[1 + indexX4] = textElementInfoArray[i].vertexTopLeft.uv; textInfo.meshInfo[materialIndex].uvs0[2 + indexX4] = textElementInfoArray[i].vertexTopRight.uv; textInfo.meshInfo[materialIndex].uvs0[3 + indexX4] = textElementInfoArray[i].vertexBottomRight.uv; // Setup UVS2 textInfo.meshInfo[materialIndex].uvs2[0 + indexX4] = textElementInfoArray[i].vertexBottomLeft.uv2; textInfo.meshInfo[materialIndex].uvs2[1 + indexX4] = textElementInfoArray[i].vertexTopLeft.uv2; textInfo.meshInfo[materialIndex].uvs2[2 + indexX4] = textElementInfoArray[i].vertexTopRight.uv2; textInfo.meshInfo[materialIndex].uvs2[3 + indexX4] = textElementInfoArray[i].vertexBottomRight.uv2; // setup Vertex Colors textInfo.meshInfo[materialIndex].colors32[0 + indexX4] = textElementInfoArray[i].vertexBottomLeft.color; textInfo.meshInfo[materialIndex].colors32[1 + indexX4] = textElementInfoArray[i].vertexTopLeft.color; textInfo.meshInfo[materialIndex].colors32[2 + indexX4] = textElementInfoArray[i].vertexTopRight.color; textInfo.meshInfo[materialIndex].colors32[3 + indexX4] = textElementInfoArray[i].vertexBottomRight.color; textInfo.meshInfo[materialIndex].vertexCount = indexX4 + 4; }
public void Copy(TextGenerationSettings other) { bool flag = other == null; if (!flag) { this.text = other.text; this.screenRect = other.screenRect; this.margins = other.margins; this.scale = other.scale; this.fontAsset = other.fontAsset; this.material = other.material; this.spriteAsset = other.spriteAsset; this.fontStyle = other.fontStyle; this.textAlignment = other.textAlignment; this.overflowMode = other.overflowMode; this.wordWrap = other.wordWrap; this.wordWrappingRatio = other.wordWrappingRatio; this.color = other.color; this.fontColorGradient = other.fontColorGradient; this.tintSprites = other.tintSprites; this.overrideRichTextColors = other.overrideRichTextColors; this.fontSize = other.fontSize; this.autoSize = other.autoSize; this.fontSizeMin = other.fontSizeMin; this.fontSizeMax = other.fontSizeMax; this.enableKerning = other.enableKerning; this.richText = other.richText; this.isRightToLeft = other.isRightToLeft; this.extraPadding = other.extraPadding; this.parseControlCharacters = other.parseControlCharacters; this.characterSpacing = other.characterSpacing; this.wordSpacing = other.wordSpacing; this.lineSpacing = other.lineSpacing; this.paragraphSpacing = other.paragraphSpacing; this.lineSpacingMax = other.lineSpacingMax; this.maxVisibleCharacters = other.maxVisibleCharacters; this.maxVisibleWords = other.maxVisibleWords; this.maxVisibleLines = other.maxVisibleLines; this.firstVisibleCharacter = other.firstVisibleCharacter; this.useMaxVisibleDescender = other.useMaxVisibleDescender; this.fontWeight = other.fontWeight; this.pageToDisplay = other.pageToDisplay; this.horizontalMapping = other.horizontalMapping; this.verticalMapping = other.verticalMapping; this.uvLineOffset = other.uvLineOffset; this.geometrySortingOrder = other.geometrySortingOrder; this.inverseYAxis = other.inverseYAxis; this.charWidthMaxAdj = other.charWidthMaxAdj; } }
private static void UpdateGenerationSettingsCommon(MeshGenerationContextUtils.TextParams painterParams, UnityEngine.TextCore.TextGenerationSettings settings) { settings.fontAsset = TextHandle.GetFontAsset(painterParams.font); settings.material = settings.fontAsset.material; Rect rect = painterParams.rect; bool flag = float.IsNaN(rect.width); if (flag) { rect.width = painterParams.wordWrapWidth; } settings.screenRect = rect; settings.text = (string.IsNullOrEmpty(painterParams.text) ? " " : painterParams.text); settings.fontSize = (float)((painterParams.fontSize > 0) ? painterParams.fontSize : painterParams.font.fontSize); settings.fontStyle = TextGeneratorUtilities.LegacyStyleToNewStyle(painterParams.fontStyle); settings.textAlignment = TextGeneratorUtilities.LegacyAlignmentToNewAlignment(painterParams.anchor); settings.wordWrap = painterParams.wordWrap; settings.richText = false; settings.overflowMode = TextOverflowMode.Overflow; }
/// <summary> /// Method to store the content of a string into an integer array. /// </summary> /// <param name="sourceText"></param> /// <param name="charBuffer"></param> /// <param name="styleStack"></param> /// <param name="generationSettings"></param> public static void StringToCharArray(string sourceText, ref int[] charBuffer, ref RichTextTagStack <int> styleStack, TextGenerationSettings generationSettings) { if (sourceText == null) { charBuffer[0] = 0; return; } if (charBuffer == null) { charBuffer = new int[8]; } // Clear the Style stack. styleStack.SetDefault(0); int writeIndex = 0; for (int i = 0; i < sourceText.Length; i++) { if (sourceText[i] == 92 && sourceText.Length > i + 1) { switch ((int)sourceText[i + 1]) { case 85: // \U00000000 for UTF-32 Unicode if (sourceText.Length > i + 9) { if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = GetUtf32(sourceText, i + 2); i += 9; writeIndex += 1; continue; } break; case 92: // \ escape if (!generationSettings.parseControlCharacters) { break; } if (sourceText.Length <= i + 2) { break; } if (writeIndex + 2 > charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = sourceText[i + 1]; charBuffer[writeIndex + 1] = sourceText[i + 2]; i += 2; writeIndex += 2; continue; case 110: // \n LineFeed if (!generationSettings.parseControlCharacters) { break; } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = (char)10; i += 1; writeIndex += 1; continue; case 114: // \r if (!generationSettings.parseControlCharacters) { break; } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = (char)13; i += 1; writeIndex += 1; continue; case 116: // \t Tab if (!generationSettings.parseControlCharacters) { break; } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = (char)9; i += 1; writeIndex += 1; continue; case 117: // \u0000 for UTF-16 Unicode if (sourceText.Length > i + 5) { if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = (char)GetUtf16(sourceText, i + 2); i += 5; writeIndex += 1; continue; } break; } } // Handle UTF-32 in the input text (string). // Not sure this is needed // if (Char.IsHighSurrogate(sourceText[i]) && Char.IsLowSurrogate(sourceText[i + 1])) { if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = Char.ConvertToUtf32(sourceText[i], sourceText[i + 1]); i += 1; writeIndex += 1; continue; } //// Handle inline replacement of <stlye> and <br> tags. if (sourceText[i] == 60 && generationSettings.richText) { if (IsTagName(ref sourceText, "<BR>", i)) { if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = 10; writeIndex += 1; i += 3; continue; } if (IsTagName(ref sourceText, "<STYLE=", i)) { int srcOffset; if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref charBuffer, ref writeIndex, ref styleStack)) { i = srcOffset; continue; } } else if (IsTagName(ref sourceText, "</STYLE>", i)) { ReplaceClosingStyleTag(ref charBuffer, ref writeIndex, ref styleStack); // Strip </style> even if style is invalid. i += 7; continue; } } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = sourceText[i]; writeIndex += 1; } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = (char)0; }
protected bool Equals(TextGenerationSettings other) { return(string.Equals(this.text, other.text) && this.screenRect.Equals(other.screenRect) && this.margins.Equals(other.margins) && this.scale.Equals(other.scale) && object.Equals(this.fontAsset, other.fontAsset) && object.Equals(this.material, other.material) && object.Equals(this.spriteAsset, other.spriteAsset) && this.fontStyle == other.fontStyle && this.textAlignment == other.textAlignment && this.overflowMode == other.overflowMode && this.wordWrap == other.wordWrap && this.wordWrappingRatio.Equals(other.wordWrappingRatio) && this.color.Equals(other.color) && object.Equals(this.fontColorGradient, other.fontColorGradient) && this.tintSprites == other.tintSprites && this.overrideRichTextColors == other.overrideRichTextColors && this.fontSize.Equals(other.fontSize) && this.autoSize == other.autoSize && this.fontSizeMin.Equals(other.fontSizeMin) && this.fontSizeMax.Equals(other.fontSizeMax) && this.enableKerning == other.enableKerning && this.richText == other.richText && this.isRightToLeft == other.isRightToLeft && this.extraPadding == other.extraPadding && this.parseControlCharacters == other.parseControlCharacters && this.characterSpacing.Equals(other.characterSpacing) && this.wordSpacing.Equals(other.wordSpacing) && this.lineSpacing.Equals(other.lineSpacing) && this.paragraphSpacing.Equals(other.paragraphSpacing) && this.lineSpacingMax.Equals(other.lineSpacingMax) && this.maxVisibleCharacters == other.maxVisibleCharacters && this.maxVisibleWords == other.maxVisibleWords && this.maxVisibleLines == other.maxVisibleLines && this.firstVisibleCharacter == other.firstVisibleCharacter && this.useMaxVisibleDescender == other.useMaxVisibleDescender && this.fontWeight == other.fontWeight && this.pageToDisplay == other.pageToDisplay && this.horizontalMapping == other.horizontalMapping && this.verticalMapping == other.verticalMapping && this.uvLineOffset.Equals(other.uvLineOffset) && this.geometrySortingOrder == other.geometrySortingOrder && this.inverseYAxis == other.inverseYAxis && this.charWidthMaxAdj.Equals(other.charWidthMaxAdj)); }