public SetUIVertex ( |
||
vertex | ||
i | int | |
return | void |
public override void ModifyMesh(VertexHelper helper) { if (!IsActive() || helper.currentVertCount == 0) return; List<UIVertex> vertices = new List<UIVertex>(); helper.GetUIVertexStream(vertices); float bottomY = vertices[0].position.y; float topY = vertices[0].position.y; for (int i = 1; i < vertices.Count; i++) { float y = vertices[i].position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } } float uiElementHeight = topY - bottomY; UIVertex v = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref v, i); v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight); helper.SetUIVertex(v, i); } }
static public int SetUIVertex(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l); UnityEngine.UIVertex a1; checkValueType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); self.SetUIVertex(a1, a2); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
/// <summary> /// Modifies the mesh. /// </summary> public override void ModifyMesh(VertexHelper vh) { if (!isActiveAndEnabled) { return; } bool isText = graphic is Text; float normalizedIndex = ptex.GetNormalizedIndex(this); // rect. var tex = m_NoiseTexture; var aspectRatio = m_KeepAspectRatio && tex ? ((float)tex.width) / tex.height : -1; Rect rect = m_EffectArea.GetEffectArea(vh, ((RectTransform)transform).rect, aspectRatio); // Calculate vertex position. UIVertex vertex = default(UIVertex); float x, y; int count = vh.currentVertCount; for (int i = 0; i < count; i++) { vh.PopulateUIVertex(ref vertex, i); m_EffectArea.GetPositionFactor(i, rect, vertex.position, isText, false, out x, out y); vertex.uv0 = new Vector2( Packer.ToFloat(vertex.uv0.x, vertex.uv0.y), Packer.ToFloat(x, y, normalizedIndex) ); vh.SetUIVertex(vertex, i); } }
protected override void OnPopulateMesh(VertexHelper toFill) { base.OnPopulateMesh(toFill); var rect = GetPixelAdjustedRect(); if (rect.width < m_Extend.x || rect.height < m_Extend.y) { return; } var ratioX = (rect.width - m_Extend.x) / rect.width; var ratioY = (rect.height - m_Extend.y) / rect.height; var verticesCount = toFill.currentVertCount; for (int i = 0; i < verticesCount; i++) { var v = new UIVertex(); toFill.PopulateUIVertex(ref v, i); v.position.x *= ratioX; v.position.y *= ratioY; toFill.SetUIVertex(v, i); } }
public override void ModifyMesh(VertexHelper vh) { if (!this.IsActive()) { return; } // var index = 0; for (var i = 0; i < vh.currentVertCount; ++i) { if (index >= 2) { UIVertex v = new UIVertex(); vh.PopulateUIVertex(ref v, i); v.color = bottom; vh.SetUIVertex(v, i); } // ++index; if (index >= 4) { index = 0; } } }
//------------------------------------------------------------- //! エフェクト計算. //------------------------------------------------------------- private void ModifyVertices(VertexHelper vh) { UIVertex v = new UIVertex(); float fRate = 0.0f; int flipIndex = 0; for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref v, i); if (flipIndex == 0) { fRate = 1.0f; } else if (flipIndex == 3) { fRate = 1.0f; } else { fRate = 0.0f; } if (++flipIndex >= 4) { flipIndex = 0; } v.color = Color32.Lerp( BottomColor, TopColor, fRate + Offset); vh.SetUIVertex(v, i); } }
public override void ModifyMesh(VertexHelper vh) { UIVertex vertex = new UIVertex(); for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vertex, i); vertex.uv1 = new Vector2(vertex.position.x, vertex.position.y); vh.SetUIVertex(vertex, i); } }
private void setSpriteVertex(VertexHelper toFill, int vertexIndex, Vector3 position, Vector2 uv0) { UIVertex v = new UIVertex(); toFill.PopulateUIVertex(ref v, vertexIndex); v.position = position; v.uv0 = uv0; v.uv1 = new Vector2(0, 1.0f); toFill.SetUIVertex(v, vertexIndex); }
public override void ModifyMesh(VertexHelper vh) { UIVertex vert = new UIVertex(); for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vert, i); vert.uv1 = new Vector2(vert.position.x, vert.position.y); vh.SetUIVertex(vert, i); } }
void modifyText(VertexHelper helper, int i, int charYPos, int charXPos) { UIVertex lb = new UIVertex(); helper.PopulateUIVertex(ref lb, i * 4); UIVertex lt = new UIVertex(); helper.PopulateUIVertex(ref lt, i * 4 + 1); UIVertex rt = new UIVertex(); helper.PopulateUIVertex(ref rt, i * 4 + 2); UIVertex rb = new UIVertex(); helper.PopulateUIVertex(ref rb, i * 4 + 3); Vector3 center = Vector3.Lerp(lb.position, rt.position, 0.5f); Matrix4x4 move = Matrix4x4.TRS(-center, Quaternion.identity, Vector3.one); float x = -charXPos * lineSpace + xOffset; float y = -charYPos * textSpace + yOffset; Vector3 pos = new Vector3(x, y, 0); Matrix4x4 place = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one); Matrix4x4 transform = place * move; lb.position = transform.MultiplyPoint(lb.position); lt.position = transform.MultiplyPoint(lt.position); rt.position = transform.MultiplyPoint(rt.position); rb.position = transform.MultiplyPoint(rb.position); helper.SetUIVertex(lb, i * 4); helper.SetUIVertex(lt, i * 4 + 1); helper.SetUIVertex(rt, i * 4 + 2); helper.SetUIVertex(rb, i * 4 + 3); }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) return; UIVertex vert = new UIVertex(); for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vert, i); vert.uv1.x = (i >> 1); vert.uv1.y = ((i >> 1) ^ (i & 1)); vh.SetUIVertex(vert, i); } }
public override void ModifyMesh (VertexHelper vh) { if (!this.IsActive()) return; List<UIVertex> list = new List<UIVertex>(); vh.GetUIVertexStream(list); ModifyVertices(list); // calls the old ModifyVertices which was used on pre 5.2 for (int i = 0; i < list.Count; ++i) { vh.SetUIVertex (list [i], i); } }
static public int SetUIVertex(IntPtr l) { try { UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l); UnityEngine.UIVertex a1; checkValueType(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); self.SetUIVertex(a1, a2); return(0); } catch (Exception e) { return(error(l, e)); } }
public override void ModifyMesh(VertexHelper vh) { UIVertex _vert = new UIVertex(); globalMinX = 0f; globalMaxX = 0f; globalMinY = 0f; globalMaxY = 0f; for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref _vert, i); globalMinX = Mathf.Min(globalMinX, _vert.position.x); globalMinY = Mathf.Min(globalMinY, _vert.position.y); globalMaxX = Mathf.Max(globalMaxX, _vert.position.x); globalMaxY = Mathf.Max(globalMaxY, _vert.position.y); } for (int i = 0; i < vh.currentVertCount; i += 4) { vh.PopulateUIVertex(ref _vert, i); _uv1.x = Mathf.InverseLerp(globalMinX, globalMaxX, _vert.position.x); _uv1.y = Mathf.InverseLerp(globalMinX, globalMaxX, _vert.position.x); localMinX = Mathf.Infinity; localMaxX = -Mathf.Infinity; localMinY = Mathf.Infinity; localMaxY = -Mathf.Infinity; for (int j = i; j < i + 4; j++) { vh.PopulateUIVertex(ref _vert, j); localMinX = Mathf.Min(_vert.position.x, localMinX); localMaxX = Mathf.Max(_vert.position.x, localMaxX); localMinY = Mathf.Min(_vert.position.y, localMinY); localMaxY = Mathf.Max(_vert.position.y, localMaxY); _vert.uv1 = _uv1; _uv2.x = Mathf.InverseLerp(localMinX, localMaxX, _vert.position.x); _uv2.y = Mathf.InverseLerp(localMinY, localMaxY, _vert.position.y); _vert.uv2 = _uv2; //_vert.uv2 = new Vector2 Mathf.InverseLerp(localMinX, localMaxX, _vert.position.x); //_vert.uv1 = new Vector2(i * 0.01f, i * 0.01f); //_vert.uv2 = new Vector2((i + 1.0f) / vh.currentVertCount, (i + 1.0f) / vh.currentVertCount); vh.SetUIVertex(_vert, j); } } }
public override void ModifyMesh(VertexHelper verts) { RectTransform rt = this.transform as RectTransform; for (int i = 0; i < verts.currentVertCount; ++i) { UIVertex uiVertex = new UIVertex(); verts.PopulateUIVertex(ref uiVertex, i); // Modify positions uiVertex.position = new Vector3( (this.m_Horizontal ? (uiVertex.position.x + (rt.rect.center.x - uiVertex.position.x) * 2) : uiVertex.position.x), (this.m_Veritical ? (uiVertex.position.y + (rt.rect.center.y - uiVertex.position.y) * 2) : uiVertex.position.y), uiVertex.position.z ); // Apply verts.SetUIVertex(uiVertex, i); } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } float bottomY = 0; float topY = 0; for (int i = 0; i < vh.currentVertCount; i++) { UIVertex v = new UIVertex(); vh.PopulateUIVertex(ref v, i); if (i == 0) { bottomY = v.position.y; topY = v.position.y; } else { float y = v.position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } } } float uiElementHeight = topY - bottomY; for (int i = 0; i < vh.currentVertCount; i++) { UIVertex v = new UIVertex(); vh.PopulateUIVertex(ref v, i); v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight); vh.SetUIVertex(v, i); } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } int count = vh.currentVertCount; if (count > 0) { UIVertex vertex = new UIVertex(); vh.PopulateUIVertex(ref vertex, 0); float bottomY = vertex.position.y; float topY = vertex.position.y; for (int i = 1; i < count; i++) { vh.PopulateUIVertex(ref vertex, i); float y = vertex.position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } } float uiElementHeight = topY - bottomY; for (int i = 0; i < count; i++) { vh.PopulateUIVertex(ref vertex, i); vertex.color = Color32.Lerp(gradientBottom, gradientTop, (vertex.position.y - bottomY) / uiElementHeight); vh.SetUIVertex(vertex, i); } } }
/// <summary> /// Modifies the mesh. /// </summary> public override void ModifyMesh(VertexHelper vh) { if (!isActiveAndEnabled) { return; } bool isText = graphic is Text; float normalizedIndex = ptex.GetNormalizedIndex(this); // rect. Rect rect = m_EffectArea.GetEffectArea(vh, ((RectTransform)transform).rect); // rotation. float rad = m_Rotation * Mathf.Deg2Rad; Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)); dir.x *= rect.height / rect.width; dir = dir.normalized; // Calculate vertex position. UIVertex vertex = default(UIVertex); Vector2 nomalizedPos; Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix. for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vertex, i); m_EffectArea.GetNormalizedFactor(i, localMatrix, vertex.position, isText, out nomalizedPos); vertex.uv0 = new Vector2( Packer.ToFloat(vertex.uv0.x, vertex.uv0.y), Packer.ToFloat(nomalizedPos.y, normalizedIndex) ); vh.SetUIVertex(vertex, i); } }
public override void ModifyMesh(VertexHelper helper) { if (!IsActive() || helper.currentVertCount == 0) { return; } List <UIVertex> vertices = new List <UIVertex>(); helper.GetUIVertexStream(vertices); float bottomY = vertices[0].position.y; float topY = vertices[0].position.y; for (int i = 1; i < vertices.Count; i++) { float y = vertices[i].position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } } float uiElementHeight = topY - bottomY; UIVertex v = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref v, i); v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight); helper.SetUIVertex(v, i); } }
/// <summary> /// Call used to modify mesh. /// </summary> public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } // Gradient space. Rect rect = default(Rect); UIVertex vertex = default(UIVertex); if (!(graphic is Text) || m_GradientStyle == GradientStyle.Rect) { // RectTransform. rect = graphic.rectTransform.rect; } else if (m_GradientStyle == GradientStyle.Split) { // Each characters. rect.Set(0, 0, 1, 1); } else if (m_GradientStyle == GradientStyle.Fit) { // Fit to contents. rect.xMin = rect.yMin = float.MaxValue; rect.xMax = rect.yMax = float.MinValue; for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vertex, i); rect.xMin = Mathf.Min(rect.xMin, vertex.position.x); rect.yMin = Mathf.Min(rect.yMin, vertex.position.y); rect.xMax = Mathf.Max(rect.xMax, vertex.position.x); rect.yMax = Mathf.Max(rect.yMax, vertex.position.y); } } // Gradient rotation. float rad = rotation * Mathf.Deg2Rad; Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)); if (!m_IgnoreAspectRatio && Direction.Angle <= m_Direction) { dir.x *= rect.height / rect.width; dir = dir.normalized; } // Calculate vertex color. Color color; Vector2 nomalizedPos; Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix. for (int i = 0; i < vh.currentVertCount; i++) { vh.PopulateUIVertex(ref vertex, i); // Normalize vertex position by local matrix. if (m_GradientStyle == GradientStyle.Split) { // Each characters. nomalizedPos = localMatrix * s_SplitedCharacterPosition[i % 4] + offset2; } else { nomalizedPos = localMatrix * vertex.position + offset2; } // Interpolate vertex color. if (direction == Direction.Diagonal) { color = Color.LerpUnclamped( Color.LerpUnclamped(m_Color1, m_Color2, nomalizedPos.x), Color.LerpUnclamped(m_Color3, m_Color4, nomalizedPos.x), nomalizedPos.y); } else { color = Color.LerpUnclamped(m_Color2, m_Color1, nomalizedPos.y); } // Correct color. vertex.color *= (m_ColorSpace == ColorSpace.Gamma) ? color.gamma : (m_ColorSpace == ColorSpace.Linear) ? color.linear : color; vh.SetUIVertex(vertex, i); } }
public override void ModifyMesh(VertexHelper helper) { if (!IsActive() || helper.currentVertCount == 0) { return; } List <UIVertex> _vertexList = new List <UIVertex>(); helper.GetUIVertexStream(_vertexList); int nCount = _vertexList.Count; switch (GradientType) { case Type.Horizontal: { float left = _vertexList[0].position.x; float right = _vertexList[0].position.x; float x = 0f; for (int i = nCount - 1; i >= 1; --i) { x = _vertexList[i].position.x; if (x > right) { right = x; } else if (x < left) { left = x; } } float width = 1f / (right - left); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.x - left) * width - Offset)); helper.SetUIVertex(vertex, i); } } break; case Type.Vertical: { float bottom = _vertexList[0].position.y; float top = _vertexList[0].position.y; float y = 0f; for (int i = nCount - 1; i >= 1; --i) { y = _vertexList[i].position.y; if (y > top) { top = y; } else if (y < bottom) { bottom = y; } } float height = 1f / (top - bottom); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - bottom) * height - Offset)); helper.SetUIVertex(vertex, i); } } break; case Type.Diamond: { float bottom = _vertexList[0].position.y; float top = _vertexList[0].position.y; float y = 0f; for (int i = nCount - 1; i >= 1; --i) { y = _vertexList[i].position.y; if (y > top) { top = y; } else if (y < bottom) { bottom = y; } } float height = 1f / (top - bottom); helper.Clear(); for (int i = 0; i < nCount; i++) { helper.AddVert(_vertexList[i]); } float center = (bottom + top) / 2f; UIVertex centralVertex = new UIVertex(); centralVertex.position = (Vector3.right + Vector3.up) * center + Vector3.forward * _vertexList[0].position.z; centralVertex.normal = _vertexList[0].normal; centralVertex.color = Color.white; helper.AddVert(centralVertex); for (int i = 1; i < nCount; i++) { helper.AddTriangle(i - 1, i, nCount); } helper.AddTriangle(0, nCount - 1, nCount); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate( Vector3.Distance(vertex.position, centralVertex.position) * height - Offset)); helper.SetUIVertex(vertex, i); } } break; case Type.Radial: { float left = _vertexList[0].position.x; float right = _vertexList[0].position.x; float bottom = _vertexList[0].position.y; float top = _vertexList[0].position.y; float x = 0f; float y = 0f; for (int i = nCount - 1; i >= 1; --i) { x = _vertexList[i].position.x; if (x > right) { right = x; } else if (x < left) { left = x; } y = _vertexList[i].position.y; if (y > top) { top = y; } else if (y < bottom) { bottom = y; } } float width = 1f / (right - left); float height = 1f / (top - bottom); helper.Clear(); float centerX = (right + left) / 2f; float centerY = (bottom + top) / 2f; float radiusX = (right - left) / 2f; float radiusY = (top - bottom) / 2f; UIVertex centralVertex = new UIVertex(); centralVertex.position = Vector3.right * centerX + Vector3.up * centerY + Vector3.forward * _vertexList[0].position.z; centralVertex.normal = _vertexList[0].normal; centralVertex.color = Color.white; int steps = 64; for (int i = 0; i < steps; i++) { UIVertex curVertex = new UIVertex(); float angle = (float)i * 360f / (float)steps; float curX = Mathf.Cos(Mathf.Deg2Rad * angle) * radiusX; float curY = Mathf.Sin(Mathf.Deg2Rad * angle) * radiusY; curVertex.position = Vector3.right * curX + Vector3.up * curY + Vector3.forward * _vertexList[0].position.z; curVertex.normal = _vertexList[0].normal; curVertex.color = Color.white; helper.AddVert(curVertex); } helper.AddVert(centralVertex); for (int i = 1; i < steps; i++) { helper.AddTriangle(i - 1, i, steps); } helper.AddTriangle(0, steps - 1, steps); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate( Mathf.Sqrt( Mathf.Pow(Mathf.Abs(vertex.position.x - centerX) * width, 2f) + Mathf.Pow(Mathf.Abs(vertex.position.y - centerY) * height, 2f)) * 2f - Offset)); helper.SetUIVertex(vertex, i); } } break; } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive() || vh.currentVertCount == 0) { return; } var text = GetComponent <Text>(); if (text == null) { Debug.LogError("Missing Text component"); return; } // 水平對齊方式 HorizontalAligmentType alignment; if (text.alignment == TextAnchor.LowerLeft || text.alignment == TextAnchor.MiddleLeft || text.alignment == TextAnchor.UpperLeft) { alignment = HorizontalAligmentType.Left; } else if (text.alignment == TextAnchor.LowerCenter || text.alignment == TextAnchor.MiddleCenter || text.alignment == TextAnchor.UpperCenter) { alignment = HorizontalAligmentType.Center; } else { alignment = HorizontalAligmentType.Right; } var vertexs = new List <UIVertex>(); vh.GetUIVertexStream(vertexs); // var indexCount = vh.currentIndexCount; var lineTexts = text.text.Split('\n'); var lines = new Line[lineTexts.Length]; // 根據lines陣列中各個元素的長度計算每一行中第一個點的索引,每個字、字母、空母均佔6個點 for (var i = 0; i < lines.Length; i++) { // 除最後一行外,vertexs對於前面幾行都有回車符佔了6個點 if (i == 0) { lines[i] = new Line(0, lineTexts[i].Length + 1); } else if (i > 0 && i < lines.Length - 1) { lines[i] = new Line(lines[i - 1].EndVertexIndex + 1, lineTexts[i].Length + 1); } else { lines[i] = new Line(lines[i - 1].EndVertexIndex + 1, lineTexts[i].Length); } } UIVertex vt; for (var i = 0; i < lines.Length; i++) { for (var j = lines[i].StartVertexIndex; j <= lines[i].EndVertexIndex; j++) { if (j < 0 || j >= vertexs.Count) { continue; } vt = vertexs[j]; var charCount = lines[i].EndVertexIndex - lines[i].StartVertexIndex; if (i == lines.Length - 1) { charCount += 6; } if (alignment == HorizontalAligmentType.Left) { vt.position += new Vector3(Spacing * ((j - lines[i].StartVertexIndex) / 6), 0, 0); } else if (alignment == HorizontalAligmentType.Right) { vt.position += new Vector3(Spacing * (-(charCount - j + lines[i].StartVertexIndex) / 6 + 1), 0, 0); if (lines.Length == 1) { vt.position += new Vector3(Spacing, 0, 0); } } else if (alignment == HorizontalAligmentType.Center) { var offset = (charCount / 6) % 2 == 0 ? 0.5f : 0f; vt.position += new Vector3(Spacing * ((j - lines[i].StartVertexIndex) / 6 - charCount / 12 + offset), 0, 0); } vertexs[j] = vt; // 以下注意點與索引的對應關係 if (j % 6 <= 2) { vh.SetUIVertex(vt, (j / 6) * 4 + j % 6); } if (j % 6 == 4) { vh.SetUIVertex(vt, (j / 6) * 4 + j % 6 - 1); } } } }
public override void ModifyMesh(VertexHelper helper) { if (!IsActive() || helper.currentVertCount == 0) { return; } List <UIVertex> _vertexList = new List <UIVertex>(); helper.GetUIVertexStream(_vertexList); int nCount = _vertexList.Count; switch (GradientType) { case Type.Vertical: { float fBottomY = _vertexList[0].position.y; float fTopY = _vertexList[0].position.y; float fYPos = 0f; for (int i = nCount - 1; i >= 1; --i) { fYPos = _vertexList[i].position.y; if (fYPos > fTopY) { fTopY = fYPos; } else if (fYPos < fBottomY) { fBottomY = fYPos; } } float fUIElementHeight = 1f / (fTopY - fBottomY); UIVertex v = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref v, i); Byte alpha = v.color.a; v.color = Color32.Lerp(EndColor, StartColor, (v.position.y - fBottomY) * fUIElementHeight - Offset); v.color.a = (Byte)((v.color.a * alpha) / 255); helper.SetUIVertex(v, i); } } break; case Type.Horizontal: { float fLeftX = _vertexList[0].position.x; float fRightX = _vertexList[0].position.x; float fXPos = 0f; for (int i = nCount - 1; i >= 1; --i) { fXPos = _vertexList[i].position.x; if (fXPos > fRightX) { fRightX = fXPos; } else if (fXPos < fLeftX) { fLeftX = fXPos; } } float fUIElementWidth = 1f / (fRightX - fLeftX); UIVertex v = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref v, i); Byte alpha = v.color.a; v.color = Color32.Lerp(EndColor, StartColor, (v.position.x - fLeftX) * fUIElementWidth - Offset); v.color.a = (Byte)((v.color.a * alpha) / 255); helper.SetUIVertex(v, i); } } break; default: break; } }
public override void ModifyMesh(VertexHelper vh) { List <UIVertex> verts = new List <UIVertex> (); vh.GetUIVertexStream(verts); if (!IsActive()) { return; } Text text = GetComponent <Text>(); if (text == null) { Debug.LogWarning("LetterSpacing: Missing Text component"); return; } string[] lines = text.text.Split('\n'); Vector3 pos; float letterOffset = spacing * (float)text.fontSize / 100f; float alignmentFactor = 0; int glyphIdx = 0; switch (text.alignment) { case TextAnchor.LowerLeft: case TextAnchor.MiddleLeft: case TextAnchor.UpperLeft: alignmentFactor = 0f; break; case TextAnchor.LowerCenter: case TextAnchor.MiddleCenter: case TextAnchor.UpperCenter: alignmentFactor = 0.5f; break; case TextAnchor.LowerRight: case TextAnchor.MiddleRight: case TextAnchor.UpperRight: alignmentFactor = 1f; break; } for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++) { string line = lines[lineIdx]; float lineOffset = (line.Length - 1) * letterOffset * alignmentFactor; for (int charIdx = 0; charIdx < line.Length; charIdx++) { int idx1 = glyphIdx * 4 + 0; int idx2 = glyphIdx * 4 + 1; int idx3 = glyphIdx * 4 + 2; int idx4 = glyphIdx * 4 + 3; // Check for truncated text (doesn't generate verts for all characters) if (idx4 > verts.Count - 1) { return; } var vert1 = verts[idx1]; var vert2 = verts[idx2]; var vert3 = verts[idx3]; var vert4 = verts[idx4]; pos = Vector3.right * (letterOffset * charIdx - lineOffset); //vert1.position += pos; //vert2.position += pos; //vert3.position += pos; //vert4.position += pos; //verts[idx1] = vert1; //verts[idx2] = vert2; //verts[idx3] = vert3; //verts[idx4] = vert4; //Debug.Log ("offset = " + idx1); vh.PopulateUIVertex(ref vert1, idx1); //vert1.color = Color.red; vert1.position += pos; vh.SetUIVertex(vert1, idx1); vh.PopulateUIVertex(ref vert2, idx2); //vert1.color = Color.red; vert2.position += pos; vh.SetUIVertex(vert2, idx2); vh.PopulateUIVertex(ref vert3, idx3); //vert1.color = Color.red; vert3.position += pos; vh.SetUIVertex(vert3, idx3); vh.PopulateUIVertex(ref vert4, idx4); //vert1.color = Color.red; vert4.position += pos; vh.SetUIVertex(vert4, idx4); //vh.SetUIVertex ( vert2, idx2 ); //vh.SetUIVertex ( vert3, idx3 ); //vh.SetUIVertex ( vert4, idx4 ); glyphIdx++; } // Offset for carriage return character that still generates verts glyphIdx++; } }
public override void ModifyMesh(VertexHelper vh) { if (!enabled) { return; } var size = widthsize; if (size < text.fontSize) { size = text.fontSize; } var count = vh.currentVertCount / 4; var content = text.text; var richtext = text.supportRichText; if (string.IsNullOrEmpty(content)) { return; } int i = 0; if (richtext) { i = GetNextValidIndex(content, i); } float a = size / 2.0f * 1.30f; float b = size * 1.30f; float d = 0; float s = 0; float si = 0; UIVertex v1 = new UIVertex(); UIVertex v2 = new UIVertex(); vh.PopulateUIVertex(ref v1, i * 4); float x = 0; if (text.alignment != 0) { x = v1.position.x; } //float y = v1.position.y; char c = '\x0'; for (; i < count; ++i) { c = content[i]; if (c == '\n') { if (richtext) { i = GetNextValidIndex(content, i + 1); if (i >= count) { break; } } s = 0; continue; } else if (richtext && c == '<') { i = GetNextValidIndex(content, i); if (i >= count) { break; } c = content[i]; } vh.PopulateUIVertex(ref v1, i * 4 + 0); vh.PopulateUIVertex(ref v2, i * 4 + 2); d = v2.position.x - v1.position.x; if (d > b) { //字形大小超过文本尺寸时 //可能使用<size>富文本标记 si = d; } else if (uEmuera.Utils.CheckHalfSize(c)) { si = size / 2.0f; } //else if(c == ' ') // si = size; //else if(d < a) // si = size / 2.0f; else { si = size; } var o = s + (si - d) / 2; v1.position.x = x + o; v2.position.x = v1.position.x + d; vh.SetUIVertex(v1, i * 4 + 0); vh.SetUIVertex(v2, i * 4 + 2); vh.PopulateUIVertex(ref v1, i * 4 + 3); vh.PopulateUIVertex(ref v2, i * 4 + 1); v1.position.x = x + o; v2.position.x = v1.position.x + d; vh.SetUIVertex(v1, i * 4 + 3); vh.SetUIVertex(v2, i * 4 + 1); s += si; } }
public override void ModifyMesh(VertexHelper helper) { if (!IsActive() || helper.currentVertCount == 0) { return; } List <UIVertex> _vertexList = new List <UIVertex>(); helper.GetUIVertexStream(_vertexList); int nCount = _vertexList.Count; switch (GradientType) { case Type.Horizontal: { float left = _vertexList[0].position.x; float right = _vertexList[0].position.x; float x = 0f; for (int i = nCount - 1; i >= 1; --i) { x = _vertexList[i].position.x; if (x > right) { right = x; } else if (x < left) { left = x; } } float width = 1f / (right - left); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.x - left) * width - Offset)); helper.SetUIVertex(vertex, i); } } break; case Type.Vertical: { float bottom = _vertexList[0].position.y; float top = _vertexList[0].position.y; float y = 0f; for (int i = nCount - 1; i >= 1; --i) { y = _vertexList[i].position.y; if (y > top) { top = y; } else if (y < bottom) { bottom = y; } } float height = 1f / (top - bottom); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - bottom) * height - Offset)); helper.SetUIVertex(vertex, i); } } break; } }
public override void ModifyMesh(VertexHelper vh) { int count = vh.currentVertCount; if (!IsActive() || count == 0) { return; } var vertexList = new List <UIVertex>(); vh.GetUIVertexStream(vertexList); UIVertex uiVertex = new UIVertex(); if (gradientMode == GradientMode.Global) { if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft) { #if UNITY_EDITOR if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) { UnityEngine.Debug.LogWarning("Diagonal dir is not supported in Global mode"); } #endif gradientDir = GradientDir.Vertical; } float bottomY = gradientDir == GradientDir.Vertical ? vertexList[vertexList.Count - 1].position.y : vertexList[vertexList.Count - 1].position.x; float topY = gradientDir == GradientDir.Vertical ? vertexList[0].position.y : vertexList[0].position.x; float uiElementHeight = topY - bottomY; for (int i = 0; i < count; i++) { vh.PopulateUIVertex(ref uiVertex, i); if (!overwriteAllColor && uiVertex.color != targetGraphic.color) { continue; } uiVertex.color *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.position.y : uiVertex.position.x) - bottomY) / uiElementHeight); vh.SetUIVertex(uiVertex, i); } } else { for (int i = 0; i < count; i++) { vh.PopulateUIVertex(ref uiVertex, i); if (!overwriteAllColor && !CompareCarefully(uiVertex.color, targetGraphic.color)) { continue; } switch (gradientDir) { case GradientDir.Vertical: uiVertex.color *= (i % 4 == 0 || (i - 1) % 4 == 0) ? vertex1 : vertex2; break; case GradientDir.Horizontal: uiVertex.color *= (i % 4 == 0 || (i - 3) % 4 == 0) ? vertex1 : vertex2; break; case GradientDir.DiagonalLeftToRight: uiVertex.color *= (i % 4 == 0) ? vertex1 : ((i - 2) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)); break; case GradientDir.DiagonalRightToLeft: uiVertex.color *= ((i - 1) % 4 == 0) ? vertex1 : ((i - 3) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)); break; } vh.SetUIVertex(uiVertex, i); } } }
/// UNITY METHODS /// protected override void OnPopulateMesh(VertexHelper toFill) { originalText = m_Text; m_Text = GetOutputText(); base.OnPopulateMesh(toFill); m_DisableFontTextureRebuiltCallback = true; m_Text = originalText; positions.Clear(); vert = new UIVertex(); for (int i = 0; i < m_ImagesVertexIndex.Count; i++) { int endIndex = m_ImagesVertexIndex[i]; if (endIndex < toFill.currentVertCount) { toFill.PopulateUIVertex(ref vert, endIndex); positions.Add(new Vector2((vert.position.x + fontSize / 2), (vert.position.y + fontSize / 2)) + imageOffset); // Erase the lower left corner of the black specks toFill.PopulateUIVertex(ref vert, endIndex - 3); Vector3 pos = vert.position; for (int j = endIndex, m = endIndex - 3; j > m; j--) { toFill.PopulateUIVertex(ref vert, endIndex); vert.position = pos; toFill.SetUIVertex(vert, j); } } } // Hyperlinks surround processing box for (int h = 0; h < m_HrefInfos.Count; h++) { m_HrefInfos[h].boxes.Clear(); if (m_HrefInfos[h].startIndex >= toFill.currentVertCount) { continue; } // Hyperlink inside the text is added to surround the vertex index coordinate frame toFill.PopulateUIVertex(ref vert, m_HrefInfos[h].startIndex); Vector3 pos = vert.position; Bounds bounds = new Bounds(pos, Vector3.zero); for (int i = m_HrefInfos[h].startIndex, m = m_HrefInfos[h].endIndex; i < m; i++) { if (i >= toFill.currentVertCount) { break; } toFill.PopulateUIVertex(ref vert, i); pos = vert.position; // Wrap re-add surround frame if (pos.x < bounds.min.x) { m_HrefInfos[h].boxes.Add(new Rect(bounds.min, bounds.size)); bounds = new Bounds(pos, Vector3.zero); } else { bounds.Encapsulate(pos); // Extended enclosed box } } m_HrefInfos[h].boxes.Add(new Rect(bounds.min, bounds.size)); } // Update the quad images updateQuad = true; m_DisableFontTextureRebuiltCallback = false; }
public override void ModifyMesh(VertexHelper helper) { for (int i = 0; i < helper.currentVertCount; i++) { UIVertex vert = new UIVertex(); helper.PopulateUIVertex(ref vert, i); if (currentChar < 0) { vert.color = Color.clear; } else { if (i / 4 > currentChar) { vert.color = Color.clear; } } helper.SetUIVertex(vert, i); } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } List <UIVertex> verts = new List <UIVertex> (); vh.GetUIVertexStream(verts); Text text = GetComponent <Text>(); if (text == null) { Debug.LogWarning("CenterGlyphs on Line: Missing Text component"); return; } string[] lines = text.text.Split('\n'); Vector3 pos = Vector3.zero; //float letterOffset = 0f * (float)text.fontSize / 100f; //float alignmentFactor = 0; int glyphIdx = 0; switch (text.alignment) { case TextAnchor.LowerLeft: case TextAnchor.MiddleLeft: case TextAnchor.UpperLeft: //alignmentFactor = 0f; break; case TextAnchor.LowerCenter: case TextAnchor.MiddleCenter: case TextAnchor.UpperCenter: //alignmentFactor = 0.5f; break; case TextAnchor.LowerRight: case TextAnchor.MiddleRight: case TextAnchor.UpperRight: //alignmentFactor = 1f; break; } for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++) { string line = lines[lineIdx]; //float lineOffset = (line.Length -1) * letterOffset * alignmentFactor; for (int charIdx = 0; charIdx < line.Length; charIdx++) { int idx1 = glyphIdx * 4 + 0; int idx2 = glyphIdx * 4 + 1; int idx3 = glyphIdx * 4 + 2; int idx4 = glyphIdx * 4 + 3; // Check for truncated text (doesn't generate verts for all characters) if (idx4 > verts.Count - 1) { return; } var vert1 = verts[idx1]; var vert2 = verts[idx2]; var vert3 = verts[idx3]; var vert4 = verts[idx4]; vh.PopulateUIVertex(ref vert1, idx1); vh.PopulateUIVertex(ref vert2, idx2); vh.PopulateUIVertex(ref vert3, idx3); vh.PopulateUIVertex(ref vert4, idx4); var height = vert1.position - vert4.position; Vector3[] corners = new Vector3[4]; this.GetComponent <RectTransform> ().GetLocalCorners(corners); //var dimensions = corners[2] - corners[0]; //Debug.Log ("Rect size = " + dimensions); //Debug.Log ("Char height = " + height.magnitude ); //Debug.Log ("Lower char corner y value = " + vert4.position.y); //float off = ((dimensions.y / 2f) - (height.magnitude / 2f)); //Debug.Log ("Char Off = " + off ); // Diff to be in the center... var half_height = height.magnitude / 2f; //float diff_y = Mathf.Max( Mathf.Abs(half_height), Mathf.Abs(vert4.position.y) ) - Mathf.Min( Mathf.Abs(half_height), Mathf.Abs(vert4.position.y) ); //Debug.Log ("diff_y =" + diff_y); float off_y = -half_height - vert4.position.y; pos.y = off_y; //pos = new Vector3 (0f, +height.magnitude / 2f, 0f); // ; // Vector3.up * ((height)*lineOffset); //vert1.color = Color.red; vert1.position += pos; vh.SetUIVertex(vert1, idx1); vert2.position += pos; vh.SetUIVertex(vert2, idx2); //vert1.color = Color.red; //vert3.color = Color.green; vert3.position += pos; vh.SetUIVertex(vert3, idx3); //vert1.color = Color.red; vert4.position += pos; vh.SetUIVertex(vert4, idx4); //vh.SetUIVertex ( vert2, idx2 ); //vh.SetUIVertex ( vert3, idx3 ); //vh.SetUIVertex ( vert4, idx4 ); glyphIdx++; } // Offset for carriage return character that still generates verts glyphIdx++; } }
public override void ModifyMesh(VertexHelper vh) { if (!enabled) { return; } var size = widthsize; if (size < text.fontSize) { size = text.fontSize; } var count = vh.currentVertCount / 4; var content = text.text; var length = content.Length; var richtext = text.supportRichText; if (string.IsNullOrWhiteSpace(content)) { return; } int i = 0; if (richtext) { i = GetNextValidIndex(content, i); } float a = size / 2.0f * 1.30f; float b = size * 1.30f; float d = 0; float s = 0; float si = 0; UIVertex v1 = new UIVertex(); UIVertex v2 = new UIVertex(); float linestart = -rectTransform.sizeDelta.x * rectTransform.pivot.x; //顶点索引记录 int vi = 0; char c = '\x0'; for (; i < length && vi < count; ++i) { c = content[i]; if (c == '\n') { if (richtext) { var ni = i + 1; i = GetNextValidIndex(content, ni); if (i >= length) { break; } else if (i == ni) { //非特殊 i -= 1; } } s = 0; continue; } else if (c == ' ') { s += size / 2.0f; continue; } else if (richtext && c == '<') { var nexti = GetNextValidIndex(content, i); if (nexti > i) { i = nexti; if (i >= length) { break; } i -= 1; continue; } } vh.PopulateUIVertex(ref v1, vi * 4 + 0); vh.PopulateUIVertex(ref v2, vi * 4 + 2); d = v2.position.x - v1.position.x; if (d > b) { //字形大小超过文本尺寸时 //可能使用<size>富文本标记 si = d; } else if (uEmuera.Utils.CheckHalfSize(c)) { si = size / 2.0f; } else if (c == ' ') { si = size / 2.0f; } //else if(c == ' ') // si = size; //else if(d < a) // si = size / 2.0f; else { si = size; } var o = s + (si - d) / 2.0f; v1.position.x = linestart + o; v2.position.x = v1.position.x + d; vh.SetUIVertex(v1, vi * 4 + 0); vh.SetUIVertex(v2, vi * 4 + 2); vh.PopulateUIVertex(ref v1, vi * 4 + 3); vh.PopulateUIVertex(ref v2, vi * 4 + 1); v1.position.x = linestart + o; v2.position.x = v1.position.x + d; vh.SetUIVertex(v1, vi * 4 + 3); vh.SetUIVertex(v2, vi * 4 + 1); vi += 1; s += si; } }
public override void ModifyMesh(VertexHelper helper) { if (this.IsActive() && (helper.currentVertCount != 0)) { List <UIVertex> stream = new List <UIVertex>(); helper.GetUIVertexStream(stream); int count = stream.Count; Type gradientType = this.GradientType; if (gradientType == Type.Horizontal) { float x = stream[0].position.x; float num3 = stream[0].position.x; float num4 = 0f; int num5 = count - 1; while (true) { if (num5 < 1) { float num6 = 1f / (num3 - x); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = this.BlendColor((Color)vertex.color, this.EffectGradient.Evaluate(((vertex.position.x - x) * num6) - this.Offset)); helper.SetUIVertex(vertex, i); } break; } UIVertex vertex3 = stream[num5]; num4 = vertex3.position.x; if (num4 > num3) { num3 = num4; } else if (num4 < x) { x = num4; } num5--; } } else if (gradientType == Type.Vertical) { float y = stream[0].position.y; float num9 = stream[0].position.y; float num10 = 0f; int num11 = count - 1; while (true) { if (num11 < 1) { float num12 = 1f / (num9 - y); UIVertex vertex = new UIVertex(); for (int i = 0; i < helper.currentVertCount; i++) { helper.PopulateUIVertex(ref vertex, i); vertex.color = this.BlendColor((Color)vertex.color, this.EffectGradient.Evaluate(((vertex.position.y - y) * num12) - this.Offset)); helper.SetUIVertex(vertex, i); } break; } UIVertex vertex7 = stream[num11]; num10 = vertex7.position.y; if (num10 > num9) { num9 = num10; } else if (num10 < y) { y = num10; } num11--; } } } }