public AddUIVertexQuad ( |
||
verts | 4 Vertices representing the quad. | |
Résultat | void |
protected override void OnPopulateMesh(VertexHelper vh) { var outer = -rectTransform.pivot.x * rectTransform.rect.width; var inner = -rectTransform.pivot.x * rectTransform.rect.width + thickness; vh.Clear(); var vert = UIVertex.simpleVert; var prevX = Vector2.zero; var prevY = Vector2.zero; var uv0 = new Vector2(0, 0); var uv1 = new Vector2(0, 1); var uv2 = new Vector2(1, 1); var uv3 = new Vector2(1, 0); Vector2 pos0; Vector2 pos1; Vector2 pos2; Vector2 pos3; var degrees = 360f / segments; var fillAngle = (int)((segments + 1) * fillPercent); for (int i = 0; i < fillAngle; i++) { var rad = Mathf.Deg2Rad * (i * degrees); var c = Mathf.Cos(rad); var s = Mathf.Sin(rad); var x = outer * c; var y = inner * c; uv0 = new Vector2(0, 1); uv1 = new Vector2(1, 1); uv2 = new Vector2(1, 0); uv3 = new Vector2(0, 0); pos0 = prevX; pos1 = new Vector2(outer * c, outer * s); if (fill) { pos2 = Vector2.zero; pos3 = Vector2.zero; } else { pos2 = new Vector2(inner * c, inner * s); pos3 = prevY; } prevX = pos1; prevY = pos2; vh.AddUIVertexQuad(SetVBO(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 })); } }
protected override void OnPopulateMesh(UnityEngine.UI.VertexHelper vh) { vh.Clear(); UIVertex[] vertexs = new UIVertex[4]; vertexs[0].position = new Vector3(-1, -1, 0); vertexs[1].position = new Vector3(-1, 1, 0); vertexs[2].position = new Vector3(1, 1, 0); vertexs[3].position = new Vector3(1, -1, 0); vertexs[0].color = color; vertexs[1].color = color; vertexs[2].color = color; vertexs[3].color = color; vertexs[0].uv0 = new Vector2(0, 0); vertexs[1].uv0 = new Vector2(0, 1); vertexs[2].uv0 = new Vector2(1, 1); vertexs[3].uv0 = new Vector2(1, 0); vh.AddUIVertexQuad(vertexs); }
/*void RefreshEmojis() { * foreach( var go in deleteTheese ) { * if( go == null ) continue; * if( UnityEngine.Application.isPlaying == false && Application.isEditor ) { * //Debug.Log("Destroy 1"); * GameObject.DestroyImmediate( go ); * } else { * //Debug.Log("Destroy 2"); * GameObject.Destroy(go); * } * } * deleteTheese.Clear(); * foreach( var go in activateTheese ) { * if( go == null ) { * continue; * } * try { * if( go.GetComponent<Tastybits.EmojiAssist.Emoji>() != null ) { * go.GetComponent<Tastybits.EmojiAssist.Emoji>().UpdateContent(); * } * go.SetActive(true); * }catch{ * * } * } * activateTheese.Clear(); * }*/ // The void OrgPopulate(VertexHelper toFill) { if (this.font == null) { return; } //System.Reflection.BindingFlags bindFl = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance; this.m_DisableFontTextureRebuiltCallback = true; Vector2 size = this.rectTransform.rect.size; TextGenerationSettings generationSettings = this.GetGenerationSettings(size); this.cachedTextGenerator.Populate(_text, generationSettings); Rect rect = this.rectTransform.rect; Vector2 textAnchorPivot = Text.GetTextAnchorPivot(this.alignment); Vector2 zero = Vector2.zero; zero.x = ((textAnchorPivot.x != 1f) ? rect.xMin : rect.xMax); zero.y = ((textAnchorPivot.y != 0f) ? rect.yMax : rect.yMin); Vector2 vector = base.PixelAdjustPoint(zero) - zero; IList <UIVertex> verts = this.cachedTextGenerator.verts; float num = 1f / this.pixelsPerUnit; int num2 = verts.Count - 4; toFill.Clear(); if (vector != Vector2.zero) { for (int i = 0; i < num2; i++) { int num3 = i & 3; this.m_TempVerts [num3] = verts[(i)]; UIVertex[] expr_147_cp_0 = this.m_TempVerts; int expr_147_cp_1 = num3; expr_147_cp_0 [expr_147_cp_1].position = expr_147_cp_0 [expr_147_cp_1].position * num; UIVertex[] expr_16B_cp_0_cp_0 = this.m_TempVerts; int expr_16B_cp_0_cp_1 = num3; expr_16B_cp_0_cp_0 [expr_16B_cp_0_cp_1].position.x = expr_16B_cp_0_cp_0 [expr_16B_cp_0_cp_1].position.x + vector.x; UIVertex[] expr_190_cp_0_cp_0 = this.m_TempVerts; int expr_190_cp_0_cp_1 = num3; expr_190_cp_0_cp_0 [expr_190_cp_0_cp_1].position.y = expr_190_cp_0_cp_0 [expr_190_cp_0_cp_1].position.y + vector.y; if (num3 == 3) { toFill.AddUIVertexQuad(this.m_TempVerts); } } } else { for (int j = 0; j < num2; j++) { int num4 = j & 3; this.m_TempVerts [num4] = verts[(j)]; UIVertex[] expr_201_cp_0 = this.m_TempVerts; int expr_201_cp_1 = num4; expr_201_cp_0 [expr_201_cp_1].position = expr_201_cp_0 [expr_201_cp_1].position * num; if (num4 == 3) { toFill.AddUIVertexQuad(this.m_TempVerts); } } } this.m_DisableFontTextureRebuiltCallback = false; }
void NewPopulate(VertexHelper toFill) { if (this.font == null) { return; } if (InputIsAppending) { Debug.Log("Input is changing text ignore it."); } if (_verbose) { Debug.Log("New populate"); } //System.Reflection.BindingFlags bindFl = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance; this.m_DisableFontTextureRebuiltCallback = true; Vector2 size = this.rectTransform.rect.size; TextGenerationSettings generationSettings = this.GetGenerationSettings(size); this.cachedTextGenerator.Populate(_text, generationSettings); //this.cachedTextGenerator.Populate( _textAsStringWithEmojisReplaced, generationSettings ); Rect rect = this.rectTransform.rect; Vector2 textAnchorPivot = Text.GetTextAnchorPivot(this.alignment); Vector2 pivotPoint = Vector2.zero; pivotPoint.x = ((textAnchorPivot.x != 1f) ? rect.xMin : rect.xMax); pivotPoint.y = ((textAnchorPivot.y != 0f) ? rect.yMax : rect.yMin); Vector2 offset = base.PixelAdjustPoint(pivotPoint) - pivotPoint; IList <UIVertex> verts = this.cachedTextGenerator.verts; ProcessVerts(); //DoFillVBO( this.cachedTextGenerator, ref verts ); float units = 1f / this.pixelsPerUnit; int numCharVerts = verts.Count - 4; toFill.Clear(); if (offset != Vector2.zero) { for (int i = 0; i < numCharVerts; i++) { int num3 = i & 3; this.m_TempVerts [num3] = verts[(i)]; UIVertex[] expr_147_cp_0 = this.m_TempVerts; int expr_147_cp_1 = num3; expr_147_cp_0 [expr_147_cp_1].position = expr_147_cp_0 [expr_147_cp_1].position * units; UIVertex[] expr_16B_cp_0_cp_0 = this.m_TempVerts; int expr_16B_cp_0_cp_1 = num3; expr_16B_cp_0_cp_0 [expr_16B_cp_0_cp_1].position.x = expr_16B_cp_0_cp_0 [expr_16B_cp_0_cp_1].position.x + offset.x; UIVertex[] expr_190_cp_0_cp_0 = this.m_TempVerts; int expr_190_cp_0_cp_1 = num3; expr_190_cp_0_cp_0 [expr_190_cp_0_cp_1].position.y = expr_190_cp_0_cp_0 [expr_190_cp_0_cp_1].position.y + offset.y; if (num3 == 3) { toFill.AddUIVertexQuad(this.m_TempVerts); } //string tmpCh = System.Text.RegularExpressions.Regex.Unescape( "\ud83d\ude02" ); } } else { for (int j = 0; j < numCharVerts; j++) { int num4 = j & 3; this.m_TempVerts [num4] = verts[(j)]; UIVertex[] expr_201_cp_0 = this.m_TempVerts; int expr_201_cp_1 = num4; expr_201_cp_0 [expr_201_cp_1].position = expr_201_cp_0 [expr_201_cp_1].position * units; if (num4 == 3) { toFill.AddUIVertexQuad(this.m_TempVerts); } } } //this.GetType().GetField( "m_TempVerts", bindFl ).SetValue(this, this.m_TempVerts ); this.m_DisableFontTextureRebuiltCallback = false; }
public override void ModifyMesh(UnityEngine.UI.VertexHelper vh) { initImage(); vh.Clear(); Vector2 StartPoint = new Vector2(OriginXStart * width, OriginYStart * height); Vector2 EndPointX = new Vector2(CoordinateXEnd * width, OriginYStart * height); Vector2 EndPointY = new Vector2(OriginXStart * width, CoordinateYEnd * height); #region 数据曲线: int count = listPoint.Count; float minValue = float.MaxValue; float maxValue = float.MinValue; for (int i = 0; i < listPoint.Count; i++) { if (listPoint[i] > maxValue) { maxValue = listPoint[i]; } if (listPoint[i] < minValue) { minValue = listPoint[i]; } } xMin = 0; xMax = listPoint.Count; yMin = minValue; yMax = maxValue; float xoffset = (EndPointX.x - StartPoint.x) / count; float yoofset = ((YEndDraw - YStartDraw) * height) / (maxValue - minValue); List <Vector2> listTemp = new List <Vector2>(); for (int i = 0; i < listPoint.Count; i++) { float x = i * xoffset + StartPoint.x; float y = yoofset * (listPoint[i] - minValue) + YStartDraw * height; listTemp.Add(new Vector2(x, y)); } List <UIVertex> lis = EMeshTools.getTriangleStrame(listTemp, 2, Color.green , true); vh.AddUIVertexTriangleStream(lis); #endregion #region 画坐标轴 UIVertex[] lineX = GetQuaLine(StartPoint, EndPointX, 2, Color.gray); if (lineX != null && lineX.Length == 4) { vh.AddUIVertexQuad(lineX); } UIVertex[] lineY = GetQuaLine(StartPoint, EndPointY, 2, Color.gray); if (lineY != null && lineY.Length == 4) { vh.AddUIVertexQuad(lineY); } #endregion #region 绘制参考线 /* * Vector2 StartPoint_R1 = new Vector2 (XReferencePos_1 * width,OriginYStart*height); * Vector2 EndPoint_R1 = new Vector2 (XReferencePos_1 * width, CoordinateYEnd*height); * UIVertex[] line_X1 = GetQuaLine (StartPoint_R1, EndPoint_R1, 1,Color.red); * if (lineX != null && lineX.Length == 4) { * vh.AddUIVertexQuad (line_X1); * } */ #endregion }
/// <summary> /// v0 v2 /// ┌─────┐ ↑ /// p0 quad p1 width /// └─────┘ ↓ /// v1 v3 /// /// /// </summary> /// <param name="prvVert"> v0, v1 </param> /// <returns> {v0,v1,v2,v3}:UIVertex </returns> UIVertex[] MakeQuad(VertexHelper vh, Vector3 p0, Vector3 p1, Color c0, Color c1, UIVertex[] prvVert=null) { Vector3 lineVector = p1 - p0; Vector3 widthVector = Vector3.Cross(lineVector, new Vector3(0, 0, 1)); widthVector.Normalize(); UIVertex[] verts = new UIVertex[4]; if (prvVert != null) { verts[0] = prvVert[0]; verts[1] = prvVert[1]; } else { verts[0].position = p0 + widthVector * width * 0.5f; verts[1].position = p0 - widthVector * width * 0.5f; } verts[0].uv0 = new Vector2(0, 0); verts[1].uv0 = new Vector2(1, 0); verts[2].position = p1 - widthVector * width * 0.5f; verts[2].uv0 = new Vector2(1, 1); verts[3].position = p1 + widthVector * width * 0.5f; verts[3].uv0 = new Vector2(0, 1); verts[0].color = c0; verts[1].color = c0; verts[2].color = c1; verts[3].color = c1; vh.AddUIVertexQuad(verts); return verts; }
protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) return; // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); cachedTextGenerator.Populate(text, settings); Rect inputRect = rectTransform.rect; // get the text alignment anchor point for the text in local space Vector2 textAnchorPivot = GetTextAnchorPivot(m_FontData.alignment); Vector2 refPoint = Vector2.zero; refPoint.x = Mathf.Lerp(inputRect.xMin, inputRect.xMax, textAnchorPivot.x); refPoint.y = Mathf.Lerp(inputRect.yMin, inputRect.yMax, textAnchorPivot.y); // Determine fraction of pixel to offset text mesh. Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint; // Apply the offset to the vertices IList<UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; //Last 4 verts are always a new line... int vertCount = verts.Count - 4; toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; m_TempVerts[tempVertsIndex].position.x += roundingOffset.x; m_TempVerts[tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) toFill.AddUIVertexQuad(m_TempVerts); } } else { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) toFill.AddUIVertexQuad(m_TempVerts); } } m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(VertexHelper toFill) { if (null == font) { return; } // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); cachedTextGenerator.Populate(m_parseText, settings); Rect inputRect = rectTransform.rect; // get the text alignment anchor point for the text in local space Vector2 textAnchorPivot = GetTextAnchorPivot(alignment); Vector2 refPoint = Vector2.zero; refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin); refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax); // Determine fraction of pixel to offset text mesh. Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint; // Apply the offset to the vertices IList <UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; //Last 4 verts are always a new line... int vertCount = verts.Count - 4; toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_tempVerts[tempVertsIndex] = verts[i]; m_tempVerts[tempVertsIndex].position *= unitsPerPixel; m_tempVerts[tempVertsIndex].position.x += roundingOffset.x; m_tempVerts[tempVertsIndex].position.y += roundingOffset.y; m_tempVerts[tempVertsIndex].uv1 = new Vector2(1.0f, 0); if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_tempVerts); } } } else { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_tempVerts[tempVertsIndex] = verts[i]; m_tempVerts[tempVertsIndex].position *= unitsPerPixel; m_tempVerts[tempVertsIndex].uv1 = new Vector2(1.0f, 0); if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_tempVerts); } } } handleSprite(toFill); m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(Mesh toFill) { if (this.font != null) { this.m_DisableFontTextureRebuiltCallback = true; Vector2 size = base.rectTransform.rect.size; TextGenerationSettings generationSettings = this.GetGenerationSettings(size); this.cachedTextGenerator.Populate(this.text, generationSettings); Rect rect = base.rectTransform.rect; Vector2 textAnchorPivot = GetTextAnchorPivot(this.m_FontData.alignment); Vector2 zero = Vector2.zero; zero.x = (textAnchorPivot.x != 1f) ? rect.xMin : rect.xMax; zero.y = (textAnchorPivot.y != 0f) ? rect.yMax : rect.yMin; Vector2 vector4 = base.PixelAdjustPoint(zero) - zero; IList<UIVertex> verts = this.cachedTextGenerator.verts; float num = 1f / this.pixelsPerUnit; int num2 = verts.Count - 4; using (VertexHelper helper = new VertexHelper()) { if (vector4 != Vector2.zero) { for (int i = 0; i < num2; i++) { int index = i & 3; this.m_TempVerts[index] = verts[i]; this.m_TempVerts[index].position = (Vector3) (this.m_TempVerts[index].position * num); this.m_TempVerts[index].position.x += vector4.x; this.m_TempVerts[index].position.y += vector4.y; if (index == 3) { helper.AddUIVertexQuad(this.m_TempVerts); } } } else { for (int j = 0; j < num2; j++) { int num6 = j & 3; this.m_TempVerts[num6] = verts[j]; this.m_TempVerts[num6].position = (Vector3) (this.m_TempVerts[num6].position * num); if (num6 == 3) { helper.AddUIVertexQuad(this.m_TempVerts); } } } helper.FillMesh(toFill); } this.m_DisableFontTextureRebuiltCallback = false; } }
protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) { return; } // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); cachedTextGenerator.Populate(text, settings); Rect inputRect = rectTransform.rect; // get the text alignment anchor point for the text in local space Vector2 textAnchorPivot = GetTextAnchorPivot(alignment); Vector2 refPoint = Vector2.zero; refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin); refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax); // Determine fraction of pixel to offset text mesh. Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint; // Apply the offset to the vertices IList <UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; //Last 4 verts are always a new line... int vertCount = Mathf.Min(numberOfLettersToShow * 4, verts.Count - 4); toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts [tempVertsIndex] = verts [i]; m_TempVerts [tempVertsIndex].position *= unitsPerPixel; m_TempVerts [tempVertsIndex].position.x += roundingOffset.x; m_TempVerts [tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } else { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts [tempVertsIndex] = verts [i]; //m_TempVerts [tempVertsIndex].color = Color.cyan; m_TempVerts [tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } lastLetterUpperLeft = new Vector2(m_TempVerts [0].position.x, m_TempVerts [0].position.y); Debug.LogError("This element position"); Debug.LogError(Camera.main.WorldToViewportPoint(this.gameObject.transform.position)); for (int i = 0; i < 4; i++) { Debug.LogError(m_TempVerts [i].position); } m_DisableFontTextureRebuiltCallback = false; }
protected virtual void OnPopulateVertsPosition(VertexHelper toFill) { // Apply the offset to the vertices IList <UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; //Last 4 verts are always a new line... (\n) int vertCount = verts.Count - 4; Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel; roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset; toFill.Clear(); bool needOffest = roundingOffset != Vector2.zero; //处理图文混排的图片 int count = this.inlineCharIndex.Count; for (int i = 0; i < count; i++) { int index = inlineCharIndex[i]; if (index * 4 + 3 < vertCount) { if (i < inlineImages.Count && inlineImages[i].image != null) { Vector2 topLeft = verts[index * 4 + 1].position; Vector2 bottomRight = verts[index * 4 + 3].position; Vector2 center = new Vector2((topLeft.x + bottomRight.x) * 0.5f, topLeft.y + (bottomRight.y - topLeft.y) * 0.6f); topLeft.y += (bottomRight.y - topLeft.y) * 0.5f; var image = inlineImages[i].image; image.transform.localPosition = center * unitsPerPixel; SetInLineImageCull(i, false); UIVertex newVertex = UIVertex.simpleVert; newVertex.position = center; verts[index * 4] = newVertex; verts[index * 4 + 1] = newVertex; verts[index * 4 + 2] = newVertex; verts[index * 4 + 3] = newVertex; } } else { if (i < inlineImages.Count) { SetInLineImageCull(i, true); } } } int charIndex = 0; bool hasCharOffests = charOffests != null && charOffests.Count > 0; float bottomY = float.MaxValue; float topY = float.MinValue; if (m_EnabledGradient) { for (int i = 0; i < vertCount; i += 2) { float y = verts[i].position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } } } for (int i = 0; i < vertCount; i += 4) { if (verts[i].position == verts[i + 1].position) { continue; } for (int j = 0; j < 4; ++j) { m_TempVerts[j] = verts[i + j]; m_TempVerts[j].position *= unitsPerPixel; if (needOffest) { m_TempVerts[j].position.x += roundingOffset.x; m_TempVerts[j].position.y += roundingOffset.y; } } //文字位移 float cosRotate = 0f; float sinRotate = 0f; if (hasCharOffests && charIndex < charOffests.Count) { CharOffest charOffest = charOffests[charIndex]; bool needScale = charOffest.scale != Vector2.one; if (charOffest.rotation != 0f) { cosRotate = Mathf.Cos(charOffest.rotation); sinRotate = Mathf.Sin(charOffest.rotation); } if (charOffest != null) { Vector2 center = (m_TempVerts[0].position + m_TempVerts[2].position) / 2f; for (int j = 0; j < 4; ++j) { if (needScale) { m_TempVerts[j].position.x = center.x + (m_TempVerts[j].position.x - center.x) * charOffest.scale.x; m_TempVerts[j].position.y = center.y + (m_TempVerts[j].position.y - center.y) * charOffest.scale.y; } if (charOffest.rotation != 0f) { float dx = m_TempVerts[j].position.x - center.x; float dy = m_TempVerts[j].position.y - center.y; m_TempVerts[j].position.x = center.x + dx * cosRotate - dy * sinRotate; m_TempVerts[j].position.y = center.y + dx * sinRotate + dy * cosRotate; } m_TempVerts[j].position.x += charOffest.position.x; m_TempVerts[j].position.y += charOffest.position.y; } } } //渐变 if (m_EnabledGradient) { ApplyGradientColor(m_TempVerts, color, m_GradientColor, topY, bottomY); } //阴影与描边 if (m_EffectType != TextEffectType.NONE) { if (m_EffectType == TextEffectType.MATERIAL) { Vector2 bottomLeft = m_TempVerts[0].uv0; Vector2 topRight = m_TempVerts[2].uv0; if (bottomLeft.x > topRight.x) { bottomLeft = m_TempVerts[2].uv0; topRight = m_TempVerts[0].uv0; } Vector4 uvBounds = new Vector4(bottomLeft.x, bottomLeft.y, topRight.x, topRight.y); m_TempVerts[0].tangent = uvBounds; m_TempVerts[1].tangent = uvBounds; m_TempVerts[2].tangent = uvBounds; m_TempVerts[3].tangent = uvBounds; } else { m_TempVerts.CopyTo(m_TempEffectVerts, 0); ApplyColor(m_TempEffectVerts, m_EffectColor); ApplyOffestX(m_TempEffectVerts, m_EffectDistance.x); ApplyOffestY(m_TempEffectVerts, m_EffectDistance.y); toFill.AddUIVertexQuad(m_TempEffectVerts); if (m_EffectType != TextEffectType.SHADOW) { ApplyOffestY(m_TempEffectVerts, -m_EffectDistance.y - m_EffectDistance.y); toFill.AddUIVertexQuad(m_TempEffectVerts); ApplyOffestX(m_TempEffectVerts, -m_EffectDistance.x - m_EffectDistance.x); toFill.AddUIVertexQuad(m_TempEffectVerts); ApplyOffestY(m_TempEffectVerts, m_EffectDistance.y + m_EffectDistance.y); toFill.AddUIVertexQuad(m_TempEffectVerts); if (m_EffectType != TextEffectType.OUTLINE4) { const float sqrt2 = 1.414214f; ApplyOffestX(m_TempEffectVerts, m_EffectDistance.x); ApplyOffestY(m_TempEffectVerts, (sqrt2 - 1) * m_EffectDistance.y); toFill.AddUIVertexQuad(m_TempEffectVerts); ApplyOffestY(m_TempEffectVerts, -sqrt2 * 2 * m_EffectDistance.y); toFill.AddUIVertexQuad(m_TempEffectVerts); ApplyOffestY(m_TempEffectVerts, sqrt2 * m_EffectDistance.y); ApplyOffestX(m_TempEffectVerts, sqrt2 * m_EffectDistance.x); toFill.AddUIVertexQuad(m_TempEffectVerts); ApplyOffestX(m_TempEffectVerts, -sqrt2 * 2 * m_EffectDistance.x); toFill.AddUIVertexQuad(m_TempEffectVerts); } } } } ; toFill.AddUIVertexQuad(m_TempVerts); charIndex++; } ; }
protected override void OnPopulateMesh(VertexHelper vh) { #if UNITY_EDITOR if (!Application.isPlaying) { if (!Initialize()) { return; } } #endif // prepare vertices vh.Clear(); if (!gameObject.activeInHierarchy) { return; } // iterate through current particles int count = _particleSystem.GetParticles(_particles); for (int i = 0; i < count; ++i) { ParticleSystem.Particle particle = _particles[i]; // get particle properties Vector2 position = (_particleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); float rotation = -particle.rotation * Mathf.Deg2Rad; float rotation90 = rotation + Mathf.PI / 2; Color32 color = particle.GetCurrentColor(_particleSystem); float size = particle.GetCurrentSize(_particleSystem) * 0.5f; // apply scale if (_particleSystem.main.scalingMode == ParticleSystemScalingMode.Shape) { position /= canvas.scaleFactor; } // apply texture sheet animation Vector4 particleUV = _uv; if (_textureSheetAnimation.enabled) { float frameProgress = 1 - (particle.remainingLifetime / particle.startLifetime); // float frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.lifetime / particle.startLifetime)); // TODO - once Unity allows MinMaxCurve reading frameProgress = Mathf.Repeat(frameProgress * _textureSheetAnimation.cycleCount, 1); int frame = 0; switch (_textureSheetAnimation.animation) { case ParticleSystemAnimationType.WholeSheet: frame = Mathf.FloorToInt(frameProgress * _textureSheetAnimationFrames); break; case ParticleSystemAnimationType.SingleRow: frame = Mathf.FloorToInt(frameProgress * _textureSheetAnimation.numTilesX); int row = _textureSheetAnimation.rowIndex; // if (textureSheetAnimation.useRandomRow) { // FIXME - is this handled internally by rowIndex? // row = Random.Range(0, textureSheetAnimation.numTilesY, using: particle.randomSeed); // } frame += row * _textureSheetAnimation.numTilesX; break; } frame %= _textureSheetAnimationFrames; particleUV.x = (frame % _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.x; particleUV.y = Mathf.FloorToInt(frame / _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.y; particleUV.z = particleUV.x + _textureSheedAnimationFrameSize.x; particleUV.w = particleUV.y + _textureSheedAnimationFrameSize.y; } _quad[0] = UIVertex.simpleVert; _quad[0].color = color; _quad[0].uv0 = new Vector2(particleUV.x, particleUV.y); _quad[1] = UIVertex.simpleVert; _quad[1].color = color; _quad[1].uv0 = new Vector2(particleUV.x, particleUV.w); _quad[2] = UIVertex.simpleVert; _quad[2].color = color; _quad[2].uv0 = new Vector2(particleUV.z, particleUV.w); _quad[3] = UIVertex.simpleVert; _quad[3].color = color; _quad[3].uv0 = new Vector2(particleUV.z, particleUV.y); if (rotation == 0) { // no rotation Vector2 corner1 = new Vector2(position.x - size, position.y - size); Vector2 corner2 = new Vector2(position.x + size, position.y + size); _quad[0].position = new Vector2(corner1.x, corner1.y); _quad[1].position = new Vector2(corner1.x, corner2.y); _quad[2].position = new Vector2(corner2.x, corner2.y); _quad[3].position = new Vector2(corner2.x, corner1.y); } else { // apply rotation Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size; Vector2 up = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size; _quad[0].position = position - right - up; _quad[1].position = position - right + up; _quad[2].position = position + right + up; _quad[3].position = position + right - up; } vh.AddUIVertexQuad(_quad); } }
protected override void OnPopulateMesh(VertexHelper toFill) { if (fontSize == 0) { toFill.Clear(); return; } m_DisableDirty = true; if (font != null) { m_DisableFontTextureRebuiltCallback = true; cachedTextGenerator.Populate(IconDecoder.Decode(text), GetGenerationSettings(rectTransform.rect.size)); Rect rect = rectTransform.rect; Vector2 textAnchorPivot = GetTextAnchorPivot(alignment); Vector2 zero = Vector2.zero; zero.x = textAnchorPivot.x != 1.0 ? rect.xMin : rect.xMax; zero.y = textAnchorPivot.y != 0.0 ? rect.yMax : rect.yMin; Vector2 vector2 = PixelAdjustPoint(zero) - zero; IList<UIVertex> verts = cachedTextGenerator.verts; float num1 = 1f / pixelsPerUnit; int num2 = verts.Count - 4; toFill.Clear(); if (vector2 != Vector2.zero) { for (int index1 = 0; index1 < num2; ++index1) { int index2 = index1 & 3; m_TempVerts[index2] = verts[index1]; m_TempVerts[index2].position *= num1; m_TempVerts[index2].position.x += vector2.x; m_TempVerts[index2].position.y += vector2.y; if (index2 == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } else { for (int index1 = 0; index1 < num2; ++index1) { int index2 = index1 & 3; m_TempVerts[index2] = verts[index1]; m_TempVerts[index2].position *= num1; if (index2 == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } m_DisableFontTextureRebuiltCallback = false; } m_DisableDirty = false; }
/// <summary> /// 在开始生成网格之前,首先会将m_DisableFontTextureRebuiltCallback置为true,即在此函数执行期间,禁止rebuild的回调。 /// 如果被调用了FontTextureChanged会直接返回。FontTextureChanged内会调用UpdateGeometry,增加一个状态判断避免循环调用。 /// </summary> /// <param name="toFill"></param> protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) { return; } // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); // 文本内容、文字设置传给cachedTextGenerator生成顶点 // // 这一过程的源码并没有在UGUI中。接着获取顶点信息,保存到IList<UIVertex> verts,供后续的步骤使用。 // 判断是否需要计算偏移,取verts中的一个顶点(verts[0]),先计算其在RectTransform度量单位的坐标, // 保存在roundingOffset中,然后计算其PixelAdjustPoint之后的坐标。 // 如果二者相等则无需偏移,否则偏移量为roundingOffset。 // 最后是向VertexHelper写入顶点数据。 // 在verts中存储的顶点坐标,每四个一组(对应一个字符)以AddUIVertexQuad的形式填入VertexHelper。 // 遍历顶点列表verts时使用i & 3相当于i对4取模。 cachedTextGenerator.PopulateWithErrors(text, settings, gameObject); // Apply the offset to the vertices IList <UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; int vertCount = verts.Count; // We have no verts to process just return (case 1037923) if (vertCount <= 0) { toFill.Clear(); return; } Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel; roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset; toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; //相当于对4取模 m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; m_TempVerts[tempVertsIndex].position.x += roundingOffset.x; m_TempVerts[tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } else { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) { return; } mVertexHelper = toFill; // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. if (mTextConentChange) { m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); cachedTextGenerator.Populate(text, settings); } Rect inputRect = rectTransform.rect; // get the text alignment anchor point for the text in local space Vector2 textAnchorPivot = GetTextAnchorPivot(m_FontDataCustom.alignment); Vector2 refPoint = Vector2.zero; refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin); refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax); // Determine fraction of pixel to offset text mesh. Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint; float unitsPerPixel = 1 / pixelsPerUnit; mVerts = cachedTextGenerator.verts; //Last 4 verts are always a new line... int vertCount = mVerts.Count - 4; mVertexHelper.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { UIVertex uv = mVerts[i]; uv.position += mMoveVector3Value; mVerts[i] = uv; int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = mVerts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; m_TempVerts[tempVertsIndex].position.x += roundingOffset.x; m_TempVerts[tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) { if (CheckVertexOutLimit(m_TempVerts)) { for (int index = 0; index < 4; index++) { m_TempVerts[index].position += GetVertexNextPos(); mVerts[i - 3 + (index)] = m_TempVerts[index]; } } mVertexHelper.AddUIVertexQuad(m_TempVerts); } } } else { for (int i = 0; i < vertCount; ++i) { UIVertex uv = mVerts[i]; uv.position += mMoveVector3Value; mVerts[i] = uv; int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = mVerts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) { if (CheckVertexOutLimit(m_TempVerts)) { for (int index = 0; index < 4; index++) { m_TempVerts[index].position += GetVertexNextPos(); mVerts[i - 3 + (index)] = m_TempVerts[index]; } } mVertexHelper.AddUIVertexQuad(m_TempVerts); } } } m_DisableFontTextureRebuiltCallback = false; mTextConentChange = false; }
protected override void OnPopulateMesh(Mesh toFill) { float outer = -rectTransform.pivot.x * rectTransform.rect.width; float inner = -rectTransform.pivot.x * rectTransform.rect.width + thickness; toFill.Clear(); var vbo = new VertexHelper(toFill); Vector2 prevX = Vector2.zero; Vector2 prevY = Vector2.zero; Vector2 uv0 = new Vector2(0, 0); Vector2 uv1 = new Vector2(0, 1); Vector2 uv2 = new Vector2(1, 1); Vector2 uv3 = new Vector2(1, 0); Vector2 pos0; Vector2 pos1; Vector2 pos2; Vector2 pos3; float f = (fillPercent / 100f); float degrees = 360f / segments; int fa = (int)((segments + 1) * f); for (int i = -1 - (fa / 2); i < fa / 2 + 1; i++) { float rad = Mathf.Deg2Rad * (i * degrees); float c = Mathf.Cos(rad); float s = Mathf.Sin(rad); uv0 = new Vector2(0, 1); uv1 = new Vector2(1, 1); uv2 = new Vector2(1, 0); uv3 = new Vector2(0, 0); pos0 = prevX; pos1 = new Vector2(outer * c, outer * s); if (fill) { pos2 = Vector2.zero; pos3 = Vector2.zero; } else { pos2 = new Vector2(inner * c, inner * s); pos3 = prevY; } prevX = pos1; prevY = pos2; vbo.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 })); } if (vbo.currentVertCount > 3) { vbo.FillMesh(toFill); } }
/// <summary> /// メッシュ生成(5.3以降版) /// </summary> /// <param name="vh"></param> protected override void OnPopulateMesh( VertexHelper vh ) { vh.Clear(); if ( vertices_ != null ) { if ( oldColor_ != color ) { int count = vertices_.Count; for ( int i = 0; i < count; ++i ) { var v = vertices_[i]; v.color = color; vertices_[i] = v; } } //UpdateVertices( false ); vh.AddUIVertexQuad( vertices_.ToArray() ); } else { SetupVertices(); UpdateVertices( false ); vh.AddUIVertexQuad( vertices_.ToArray() ); } }
protected override void OnPopulateMesh(VertexHelper vh) { Texture tex = mainTexture; vh.Clear(); if (tex != null) { Rect r = GetPixelAdjustedRect(); Vector4 v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height); Vector2 whiteUV = Vector2.zero; Vector3 lb = new Vector3(v.x, v.y); Vector3 lt = new Vector3(v.x, v.w); Vector3 rt = new Vector3(v.z, v.w); Vector3 rb = new Vector3(v.z, v.y); int vert = 0; vh.AddVert(lb, color, whiteUV); vh.AddVert(lt, color, whiteUV); vh.AddVert(rt, color, whiteUV); vh.AddVert(rb, color, whiteUV); vh.AddTriangle(0, 1, 2); vh.AddTriangle(2, 3, 0); vert += 4; float width = rb.x - lb.x; float height = lt.y - lb.y; Vector3 center = Vector3.Lerp(lb, rt, 0.5f); Rect rect = new Rect(lb, new Vector2(width, height)); bool sizeIsCorrect = pixelsToDisplay.Length == (1 + (Mathf.CeilToInt(horizontalPixels) * 2)) * (1 + (Mathf.CeilToInt(verticalPixels) * 2)); UIVertex[] vertices = new UIVertex[4]; vertices[0].uv0 = whiteUV; vertices[1].uv0 = whiteUV; vertices[2].uv0 = whiteUV; vertices[3].uv0 = whiteUV; if (ExpectedVertices >= 65000) { Debug.LogWarning("to many vertices, currently " + ExpectedVertices + "/64999. make sure the ColorEyedropperPreview displays less pixels. You can achiee this by either editing it's settings in the inspector or resizing the component", this); } else { for (int radius = 1; radius <= Mathf.Ceil(horizontalPixels) || radius <= Mathf.Ceil(verticalPixels); radius++) { float offset = radius * (pixelSize + borderSize); // Top side for (int top = 0; top < radius * 2; top++) { float extraOffset = top * (pixelSize + borderSize); Vector3 pos = center + new Vector3(-offset, offset) + new Vector3(extraOffset, 0); if (SetQuadPositions(vertices, pos, rect)) { Color32 c; if (sizeIsCorrect && activated) c = pixelsToDisplay[(pixelsToDisplay.Length / 2) + (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * radius) - (radius - top)]; else c = InactiveColor; SetQuadColors(vertices, c); vh.AddUIVertexQuad(vertices); } } // Right side for (int right = 0; right < radius * 2; right++) { float extraOffset = right * (pixelSize + borderSize); Vector3 pos = center + new Vector3(offset, offset) + new Vector3(0, -extraOffset); if (SetQuadPositions(vertices, pos, rect)) { Color32 c; if (sizeIsCorrect && activated) c = pixelsToDisplay[(pixelsToDisplay.Length / 2) + radius + (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * (radius - right))]; else c = InactiveColor; SetQuadColors(vertices, c); vh.AddUIVertexQuad(vertices); } } // Bot side for (int bot = 0; bot < radius * 2; bot++) { float extraOffset = bot * (pixelSize + borderSize); Vector3 pos = center + new Vector3(offset, -offset) + new Vector3(-extraOffset, 0); if (SetQuadPositions(vertices, pos, rect)) { Color32 c; if (sizeIsCorrect && activated) c = pixelsToDisplay[(pixelsToDisplay.Length / 2) - (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * radius) + (radius - bot)]; else c = InactiveColor; SetQuadColors(vertices, c); vh.AddUIVertexQuad(vertices); } } // Left side for (int left = 0; left < radius * 2; left++) { float extraOffset = left * (pixelSize + borderSize); Vector3 pos = center + new Vector3(-offset, -offset) + new Vector3(0, extraOffset); if (SetQuadPositions(vertices, pos, rect)) { Color32 c; if (sizeIsCorrect && activated) c = pixelsToDisplay[(pixelsToDisplay.Length / 2) - radius - (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * (radius - left))]; else c = InactiveColor; SetQuadColors(vertices, c); vh.AddUIVertexQuad(vertices); } } } } // Selectionbox if (SetQuadPositions(vertices, center, rect, borderSize + 1f)) { SetQuadColors(vertices, selectionBoxColor); vh.AddUIVertexQuad(vertices); } // Center piece if (SetQuadPositions(vertices, center, rect)) { Color32 co; if (sizeIsCorrect && activated) co = pixelsToDisplay[pixelsToDisplay.Length / 2]; else co = InactiveColor; SetQuadColors(vertices, co); vh.AddUIVertexQuad(vertices); } } }
protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) { return; } if (EmojiIndex == null) { EmojiIndex = new Dictionary <string, EmojiInfo>(); //load emoji data, and you can overwrite this segment code base on your project; TextAsset emojiContent = Resources.Load <TextAsset>("Bin/Byte/emoji"); string[] lines = emojiContent.text.Split('\n'); for (int i = 1; i < lines.Length; i++) { if (!string.IsNullOrEmpty(lines[i])) { string[] strs = lines[i].Split('\t'); EmojiInfo info; info.x = float.Parse(strs[3]); info.y = float.Parse(strs[4]); info.size = float.Parse(strs[5]); info.len = 0; EmojiIndex.Add(strs[1], info); } } } Dictionary <int, EmojiInfo> emojiDic = new Dictionary <int, EmojiInfo>(); if (supportRichText) { MatchCollection matches = Regex.Matches(text, "\\[[a-z0-9A-Z]+\\]"); for (int i = 0; i < matches.Count; i++) { EmojiInfo info; if (EmojiIndex.TryGetValue(matches[i].Value, out info)) { info.len = matches[i].Length; emojiDic.Add(matches[i].Index, info); } } } // We don't care if we the font Texture changes while we are doing our Update; // The end result of cachedTextGenerator will be valid for this instance; // Otherwise we can get issues like Case 619238; m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); cachedTextGenerator.Populate(text, settings); Rect inputRect = rectTransform.rect; // get the text alignment anchor point for the text in local space; Vector2 textAnchorPivot = GetTextAnchorPivot(alignment); Vector2 refPoint = Vector2.zero; refPoint.x = Mathf.Lerp(inputRect.xMin, inputRect.xMax, textAnchorPivot.x); refPoint.y = Mathf.Lerp(inputRect.yMin, inputRect.yMax, textAnchorPivot.y); // Determine fraction of pixel to offset text mesh; Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint; // Apply the offset to the vertices; IList <UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; //Last 4 verts are always a new line...; int vertCount = verts.Count - 4; toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; m_TempVerts[tempVertsIndex].position.x += roundingOffset.x; m_TempVerts[tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } else { float repairDistance = 0; float repairDistanceHalf = 0; float repairY = 0; if (vertCount > 0) { repairY = verts[3].position.y; } for (int i = 0; i < vertCount; ++i) { EmojiInfo info; int index = i / 4; if (emojiDic.TryGetValue(index, out info)) { //compute the distance of '[' and get the distance of emoji; float charDis = (verts[i + 1].position.x - verts[i].position.x) * 3; m_TempVerts[3] = verts[i]; //1 m_TempVerts[2] = verts[i + 1]; //2 m_TempVerts[1] = verts[i + 2]; //3 m_TempVerts[0] = verts[i + 3]; //4 //the real distance of an emoji; m_TempVerts[2].position += new Vector3(charDis, 0, 0); m_TempVerts[1].position += new Vector3(charDis, 0, 0); //make emoji has equal width and height; float fixValue = (m_TempVerts[2].position.x - m_TempVerts[3].position.x - (m_TempVerts[2].position.y - m_TempVerts[1].position.y)); m_TempVerts[2].position -= new Vector3(fixValue, 0, 0); m_TempVerts[1].position -= new Vector3(fixValue, 0, 0); float curRepairDis = 0; if (verts[i].position.y < repairY) {// to judge current char in the same line or not; repairDistance = repairDistanceHalf; repairDistanceHalf = 0; repairY = verts[i + 3].position.y; } curRepairDis = repairDistance; int dot = 0;//repair next line distance; for (int j = info.len - 1; j > 0; j--) { if (verts.Count > (i + j * 4 + 2)) { if (verts[i + j * 4 + 3].position.y >= verts[i + 3].position.y) { repairDistance += verts[i + j * 4 + 1].position.x - m_TempVerts[2].position.x; break; } else { dot = i + 4 * j; } } } if (dot > 0) { int nextChar = i + info.len * 4; if (nextChar < verts.Count) { repairDistanceHalf = verts[nextChar].position.x - verts[dot].position.x; } } //repair its distance; for (int j = 0; j < 4; j++) { m_TempVerts[j].position -= new Vector3(curRepairDis, 0, 0); } m_TempVerts[0].position *= unitsPerPixel; m_TempVerts[1].position *= unitsPerPixel; m_TempVerts[2].position *= unitsPerPixel; m_TempVerts[3].position *= unitsPerPixel; float pixelOffset = emojiDic[index].size / 32 / 2; m_TempVerts[0].uv1 = new Vector2(emojiDic[index].x + pixelOffset, emojiDic[index].y + pixelOffset); m_TempVerts[1].uv1 = new Vector2(emojiDic[index].x - pixelOffset + emojiDic[index].size, emojiDic[index].y + pixelOffset); m_TempVerts[2].uv1 = new Vector2(emojiDic[index].x - pixelOffset + emojiDic[index].size, emojiDic[index].y - pixelOffset + emojiDic[index].size); m_TempVerts[3].uv1 = new Vector2(emojiDic[index].x + pixelOffset, emojiDic[index].y - pixelOffset + emojiDic[index].size); toFill.AddUIVertexQuad(m_TempVerts); i += 4 * info.len - 1; } else { int tempVertsIndex = i & 3; if (tempVertsIndex == 0 && verts[i].position.y < repairY) { repairY = verts[i + 3].position.y; repairDistance = repairDistanceHalf; repairDistanceHalf = 0; } m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position -= new Vector3(repairDistance, 0, 0); m_TempVerts[tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } } m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(VertexHelper toFill) { if ((UnityEngine.Object) this.font == (UnityEngine.Object) null) return; this.m_DisableFontTextureRebuiltCallback = true; this.cachedTextGenerator.Populate(this.text, this.GetGenerationSettings(this.rectTransform.rect.size)); Rect rect = this.rectTransform.rect; Vector2 textAnchorPivot = Text.GetTextAnchorPivot(this.m_FontData.alignment); Vector2 zero = Vector2.zero; zero.x = Mathf.Lerp(rect.xMin, rect.xMax, textAnchorPivot.x); zero.y = Mathf.Lerp(rect.yMin, rect.yMax, textAnchorPivot.y); Vector2 vector2 = this.PixelAdjustPoint(zero) - zero; IList<UIVertex> verts = this.cachedTextGenerator.verts; float num1 = 1f / this.pixelsPerUnit; int num2 = verts.Count - 4; toFill.Clear(); if (vector2 != Vector2.zero) { for (int index1 = 0; index1 < num2; ++index1) { int index2 = index1 & 3; this.m_TempVerts[index2] = verts[index1]; this.m_TempVerts[index2].position *= num1; this.m_TempVerts[index2].position.x += vector2.x; this.m_TempVerts[index2].position.y += vector2.y; if (index2 == 3) toFill.AddUIVertexQuad(this.m_TempVerts); } } else { for (int index1 = 0; index1 < num2; ++index1) { int index2 = index1 & 3; this.m_TempVerts[index2] = verts[index1]; this.m_TempVerts[index2].position *= num1; if (index2 == 3) toFill.AddUIVertexQuad(this.m_TempVerts); } } this.m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(VertexHelper vh) { if (Points == null) { return; } var sizeX = rectTransform.rect.width; var sizeY = rectTransform.rect.height; var offsetX = -rectTransform.pivot.x * rectTransform.rect.width; var offsetY = -rectTransform.pivot.y * rectTransform.rect.height; // don't want to scale based on the size of the rect, so this is switchable now if (!relativeSize) { sizeX = 1; sizeY = 1; } if (UseMargins) { sizeX -= Margin.x; sizeY -= Margin.y; offsetX += Margin.x / 2f; offsetY += Margin.y / 2f; } vh.Clear(); // Generate the quads that make up the wide line var segments = new List <UIVertex[]>(); if (LineList) { for (var i = 1; i < Points.Length; i += 2) { var start = Points[i - 1]; var end = Points[i]; start = new Vector2(start.x * sizeX + offsetX, start.y * sizeY + offsetY); end = new Vector2(end.x * sizeX + offsetX, end.y * sizeY + offsetY); if (LineCaps) { segments.Add(CreateLineCap(start, end, SegmentType.Start)); } segments.Add(CreateLineSegment(start, end, SegmentType.Middle)); if (LineCaps) { segments.Add(CreateLineCap(start, end, SegmentType.End)); } } } else { for (var i = 1; i < Points.Length; i++) { var start = Points[i - 1]; var end = Points[i]; start = new Vector2(start.x * sizeX + offsetX, start.y * sizeY + offsetY); end = new Vector2(end.x * sizeX + offsetX, end.y * sizeY + offsetY); if (LineCaps && i == 1) { segments.Add(CreateLineCap(start, end, SegmentType.Start)); } segments.Add(CreateLineSegment(start, end, SegmentType.Middle)); if (LineCaps && i == Points.Length - 1) { segments.Add(CreateLineCap(start, end, SegmentType.End)); } } } // Add the line segments to the vertex helper, creating any joins as needed for (var i = 0; i < segments.Count; i++) { if (!LineList && i < segments.Count - 1) { var vec1 = segments[i][1].position - segments[i][2].position; var vec2 = segments[i + 1][2].position - segments[i + 1][1].position; var angle = Vector2.Angle(vec1, vec2) * Mathf.Deg2Rad; // Positive sign means the line is turning in a 'clockwise' direction var sign = Mathf.Sign(Vector3.Cross(vec1.normalized, vec2.normalized).z); // Calculate the miter point var miterDistance = LineThickness / (2 * Mathf.Tan(angle / 2)); var miterPointA = segments[i][2].position - vec1.normalized * miterDistance * sign; var miterPointB = segments[i][3].position + vec1.normalized * miterDistance * sign; var joinType = LineJoins; if (joinType == JoinType.Miter) { // Make sure we can make a miter join without too many artifacts. if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_MITER_JOIN) { segments[i][2].position = miterPointA; segments[i][3].position = miterPointB; segments[i + 1][0].position = miterPointB; segments[i + 1][1].position = miterPointA; } else { joinType = JoinType.Bevel; } } if (joinType == JoinType.Bevel) { if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_BEVEL_NICE_JOIN) { if (sign < 0) { segments[i][2].position = miterPointA; segments[i + 1][1].position = miterPointA; } else { segments[i][3].position = miterPointB; segments[i + 1][0].position = miterPointB; } } var join = new UIVertex[] { segments[i][2], segments[i][3], segments[i + 1][0], segments[i + 1][1] }; vh.AddUIVertexQuad(join); } } vh.AddUIVertexQuad(segments[i]); } }
protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) { return; } // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. m_DisableFontTextureRebuiltCallback = true; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); cachedTextGenerator.PopulateWithErrors(text, settings, gameObject); // Apply the offset to the vertices IList <UIVertex> verts = cachedTextGenerator.verts; float unitsPerPixel = 1 / pixelsPerUnit; int vertCount = verts.Count; // We have no verts to process just return (case 1037923) if (vertCount <= 0) { toFill.Clear(); return; } Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel; roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset; toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; m_TempVerts[tempVertsIndex].position.x += roundingOffset.x; m_TempVerts[tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } else { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; m_TempVerts[tempVertsIndex] = verts[i]; m_TempVerts[tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(m_TempVerts); } } } m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(VertexHelper toFill) { if (font == null) { return; } // We don't care if we the font Texture changes while we are doing our Update. // The end result of cachedTextGenerator will be valid for this instance. // Otherwise we can get issues like Case 619238. m_DisableFontTextureRebuiltCallback = true; string richText = text; IList <UIVertex> verts = null; eventList.Clear(); // Caculate layout try { richText = CalculateLayoutWithImage(richText, out verts); } catch (Exception e) { Debug.LogWarning(e.ToString()); return; } // Last 4 verts are always a new line... int vertCount = verts.Count; for (int i = 0; i < 4; i++) { if (vertCount > 0) { verts.RemoveAt(vertCount - 1); vertCount -= 1; } } // Parse color tag List <Tag> tags = null; textInterpreter.Parse(richText, out tags); // Apply tag effect if (tags.Count > 0) { List <UIVertex> vertexs = verts as List <UIVertex>; if (vertexs != null) { int capacity = 0; for (int i = 0; i < tags.Count; i++) { Tag tag = tags[i]; switch (tag.type) { case TagType.Shadow: { capacity += (tag.end - tag.start) * 4; break; } case TagType.Outline: { capacity += (tag.end - tag.start) * 4 * 5; break; } } } if (capacity > 0) { capacity = Mathf.Max(capacity, 16); vertexs.Capacity += capacity; } } for (int i = 0; i < tags.Count; i++) { Tag tag = tags[i]; try { switch (tag.type) { case TagType.Shadow: { ApplyShadowEffect(tag as Shadow, verts); break; } case TagType.Outline: { ApplyOutlineEffect(tag as Outline, verts); break; } case TagType.Gradient: { ApplyGradientEffect(tag as GradientL, verts); break; } case TagType.Underline: { ApplyUnderlineEffect(tag as Underline, verts); break; } } } catch (Exception e) { Debug.LogWarning(e.ToString()); return; } } } vertCount = verts.Count; float unitsPerPixel = 1 / pixelsPerUnit; Rect inputRect = rectTransform.rect; // get the text alignment anchor point for the text in local space Vector2 textAnchorPivot = GetTextAnchorPivot(fontData.alignment); Vector2 refPoint = Vector2.zero; refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin); refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax); // Determine fraction of pixel to offset text mesh. Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint; toFill.Clear(); if (roundingOffset != Vector2.zero) { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; tempVerts[tempVertsIndex] = verts[i]; tempVerts[tempVertsIndex].position *= unitsPerPixel; tempVerts[tempVertsIndex].position.x += roundingOffset.x; tempVerts[tempVertsIndex].position.y += roundingOffset.y; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(tempVerts); } } } else { for (int i = 0; i < vertCount; ++i) { int tempVertsIndex = i & 3; tempVerts[tempVertsIndex] = verts[i]; tempVerts[tempVertsIndex].position *= unitsPerPixel; if (tempVertsIndex == 3) { toFill.AddUIVertexQuad(tempVerts); } } } m_DisableFontTextureRebuiltCallback = false; }
protected override void OnPopulateMesh(VertexHelper toFill) { if (this.font != null) { this.m_DisableFontTextureRebuiltCallback = true; Vector2 size = base.rectTransform.rect.size; TextGenerationSettings generationSettings = this.GetGenerationSettings(size); this.cachedTextGenerator.PopulateWithErrors(this.text, generationSettings, base.gameObject); IList<UIVertex> verts = this.cachedTextGenerator.verts; float num = 1f / this.pixelsPerUnit; int num2 = verts.Count - 4; UIVertex vertex = verts[0]; UIVertex vertex2 = verts[0]; Vector2 point = (Vector2) (new Vector2(vertex.position.x, vertex2.position.y) * num); point = base.PixelAdjustPoint(point) - point; toFill.Clear(); if (point != Vector2.zero) { for (int i = 0; i < num2; i++) { int index = i & 3; this.m_TempVerts[index] = verts[i]; this.m_TempVerts[index].position = (Vector3) (this.m_TempVerts[index].position * num); this.m_TempVerts[index].position.x += point.x; this.m_TempVerts[index].position.y += point.y; if (index == 3) { toFill.AddUIVertexQuad(this.m_TempVerts); } } } else { for (int j = 0; j < num2; j++) { int num6 = j & 3; this.m_TempVerts[num6] = verts[j]; this.m_TempVerts[num6].position = (Vector3) (this.m_TempVerts[num6].position * num); if (num6 == 3) { toFill.AddUIVertexQuad(this.m_TempVerts); } } } this.m_DisableFontTextureRebuiltCallback = false; } }
public void Save(VertexHelper vh) { vh.AddUIVertexQuad(V); }