static int UpdateVertexData(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(TMPro.TextMeshProUGUI))) { TMPro.TextMeshProUGUI obj = (TMPro.TextMeshProUGUI)ToLua.ToObject(L, 1); obj.UpdateVertexData(); return(0); } else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(TMPro.TextMeshProUGUI), typeof(TMPro.TMP_VertexDataUpdateFlags))) { TMPro.TextMeshProUGUI obj = (TMPro.TextMeshProUGUI)ToLua.ToObject(L, 1); TMPro.TMP_VertexDataUpdateFlags arg0 = (TMPro.TMP_VertexDataUpdateFlags)ToLua.ToObject(L, 2); obj.UpdateVertexData(arg0); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshProUGUI.UpdateVertexData")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
List <Color32[]> SetLinkToColor(int linkIndex, Color32 color) { TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; var oldVertColors = new List <Color32[]>(); // store the old character colors for (int i = 0; i < linkInfo.linkTextLength; i++) { // for each character in the link string int characterIndex = linkInfo.linkTextfirstCharacterIndex + i; // the character index into the entire text var charInfo = pTextMeshPro.textInfo.characterInfo[characterIndex]; int meshIndex = charInfo.materialReferenceIndex; // Get the index of the material / sub text object used by this character. int vertexIndex = charInfo.vertexIndex; // Get the index of the first vertex of this character. Color32[] vertexColors = pTextMeshPro.textInfo.meshInfo[meshIndex].colors32; // the colors for this character oldVertColors.Add(vertexColors.ToArray()); if (charInfo.isVisible) { vertexColors[vertexIndex + 0] = color; vertexColors[vertexIndex + 1] = color; vertexColors[vertexIndex + 2] = color; vertexColors[vertexIndex + 3] = color; } } // Update Geometry pTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All); return(oldVertColors); }
void RecalculateText() { if (TextComponent == null) { TextComponent = this.transform.Find("Text").GetComponent <TMPro.TextMeshProUGUI>(); } if (RectTransform == null) { RectTransform = GetComponent <RectTransform>(); } TextComponent.text = Text; Vector3[] vertices; TextComponent.ForceMeshUpdate(); float textWidth = TextComponent.preferredWidth + Padding * 2; this.RectTransform.sizeDelta = new Vector3(textWidth, this.RectTransform.sizeDelta.y, 0f); TextComponent.ForceMeshUpdate(); TMP_TextInfo textInfo = TextComponent.textInfo; int characterCount = textInfo.characterCount; if (characterCount == 0) { return; } float boundsMinX = TextComponent.bounds.min.x - Padding; float boundsMaxX = TextComponent.bounds.max.x + Padding; float fullWidth = textWidth + Padding * 2; float angle = Angle * 100 / textWidth; for (int i = 0; i < characterCount; i++) { if (!textInfo.characterInfo[i].isVisible) { continue; } int vertexIndex = textInfo.characterInfo[i].vertexIndex; int materialIndex = textInfo.characterInfo[i].materialReferenceIndex; vertices = textInfo.meshInfo[materialIndex].vertices; Vector3 charMidBaselinePos = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine); float zeroToOnePos = (charMidBaselinePos.x - boundsMinX) / (boundsMaxX - boundsMinX); var quat = Quaternion.AngleAxis((zeroToOnePos - 0.5f) * angle, new Vector3(0f, 0f, -1f)); vertices[vertexIndex + 0] = quat * vertices[vertexIndex + 0]; vertices[vertexIndex + 1] = quat * vertices[vertexIndex + 1]; vertices[vertexIndex + 2] = quat * vertices[vertexIndex + 2]; vertices[vertexIndex + 3] = quat * vertices[vertexIndex + 3]; } TextComponent.UpdateVertexData(); SetVerticesDirty(); SetMaterialDirty(); }