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); } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } List<UIVertex> verts = new List<UIVertex>(); vh.GetUIVertexStream(verts); if (verts == null || verts.Count == 0) { return; } int start; int end = 0; for (float i = 0; i <= Mathf.PI * 2; i += Mathf.PI / (float)mDivideAmoumt) { start = end; end = verts.Count; ApplyShadow(verts, effectColor, start, end, effectDistance.x * Mathf.Cos(i), effectDistance.y * Mathf.Sin(i)); } vh.Clear(); vh.AddUIVertexTriangleStream(verts); }
public override void ModifyMesh(VertexHelper vh) { if (!this.IsActive()) return; List<UIVertex> list = ListPool<UIVertex>.Get(); vh.GetUIVertexStream(list); int num = list.Count * 5; if (list.Capacity < num) list.Capacity = num; int start1 = 0; int count1 = list.Count; this.ApplyShadowZeroAlloc(list, (Color32) this.effectColor, start1, list.Count, this.effectDistance.x, this.effectDistance.y); int start2 = count1; int count2 = list.Count; this.ApplyShadowZeroAlloc(list, (Color32) this.effectColor, start2, list.Count, this.effectDistance.x, -this.effectDistance.y); int start3 = count2; int count3 = list.Count; this.ApplyShadowZeroAlloc(list, (Color32) this.effectColor, start3, list.Count, -this.effectDistance.x, this.effectDistance.y); int start4 = count3; int count4 = list.Count; this.ApplyShadowZeroAlloc(list, (Color32) this.effectColor, start4, list.Count, -this.effectDistance.x, -this.effectDistance.y); vh.Clear(); vh.AddUIVertexTriangleStream(list); ListPool<UIVertex>.Release(list); }
public override void ModifyMesh(Mesh mesh) { if (this.IsActive()) { List<UIVertex> stream = new List<UIVertex>(); using (VertexHelper helper = new VertexHelper(mesh)) { helper.GetUIVertexStream(stream); } int num = stream.Count * 5; if (stream.Capacity < num) { stream.Capacity = num; } int start = 0; int count = stream.Count; base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, base.effectDistance.y); start = count; count = stream.Count; base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, -base.effectDistance.y); start = count; count = stream.Count; base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, base.effectDistance.y); start = count; count = stream.Count; base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, -base.effectDistance.y); using (VertexHelper helper2 = new VertexHelper()) { helper2.AddUIVertexTriangleStream(stream); helper2.FillMesh(mesh); } } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) return; var verts = ListPool<UIVertex>.Get(); vh.GetUIVertexStream(verts); var neededCpacity = verts.Count * 5; if (verts.Capacity < neededCpacity) verts.Capacity = neededCpacity; var start = 0; var end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y); vh.Clear(); vh.AddUIVertexTriangleStream(verts); ListPool<UIVertex>.Release(verts); }
public override void ModifyMesh(Mesh mesh) { if (this.IsActive() == false) { return; } var list = new List<UIVertex>(); using (var vertexHelper = new VertexHelper(mesh)) { vertexHelper.GetUIVertexStream(list); } this.ModifyVertices(list); // calls the old ModifyVertices which was used on pre 5.2 using (var vertexHelper = new VertexHelper()) { vertexHelper.AddUIVertexTriangleStream(list); vertexHelper.FillMesh(mesh); } }
static public int GetUIVertexStream(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); System.Collections.Generic.List <UnityEngine.UIVertex> a1; checkType(l, 2, out a1); self.GetUIVertexStream(a1); 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 }
public override void ModifyMesh(VertexHelper vertexHelper) { List<UIVertex> vertexList = new List<UIVertex>(); vertexHelper.GetUIVertexStream(vertexList); ModifyVertices(vertexList); vertexHelper.Clear(); vertexHelper.AddUIVertexTriangleStream(vertexList); }
public override void ModifyMesh(UnityEngine.UI.VertexHelper helper) { if (!IsActive()) { return; } #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif List <UIVertex> verts = ListPool <UIVertex> .Get(); helper.GetUIVertexStream(verts); CreateMeshRenderer(); m_mesh.Clear(); m_meshRenderer.material = GetComponent <Text> ().font.material; m_meshFilter.mesh = m_mesh; m_meshRenderer.enabled = false; GetArray(ref vertices, verts.Count); GetArray(ref triangles, verts.Count); GetArray(ref colors, verts.Count); GetArray(ref uvs, verts.Count); for (int i = 0; i < verts.Count; ++i) { var vert = verts [i]; vertices [i] = vert.position; if (i % 6 == 0 || i % 6 == 5) { vertices[i] = vert.position + new Vector3(-m_expand, m_expand); } else if (i % 6 == 1) { vertices[i] = vert.position + new Vector3(m_expand, m_expand); } else if (i % 6 == 2 || i % 6 == 3) { vertices[i] = vert.position + new Vector3(m_expand, -m_expand); } else { vertices[i] = vert.position + new Vector3(-m_expand, -m_expand); } uvs [i] = verts [i].uv0; triangles [i] = i; colors [i] = m_glowColor; } m_mesh.vertices = vertices; m_mesh.uv = uvs; m_mesh.triangles = triangles; m_mesh.colors = colors; verts.ReleaseToPool(); m_spriteChanged = true; }
public void ModifyMesh(VertexHelper helper) { var list = new List<UIVertex>(); helper.GetUIVertexStream(list); this.ModifyVertices(list); // calls the old ModifyVertices which was used on pre 5.2 helper.AddUIVertexTriangleStream(list); }
public override void ModifyMesh(VertexHelper vh) { if (this.IsActive()) { List<UIVertex> stream = ListPool<UIVertex>.Get(); vh.GetUIVertexStream(stream); this.ApplyShadow(stream, this.effectColor, 0, stream.Count, this.effectDistance.x, this.effectDistance.y); vh.Clear(); vh.AddUIVertexTriangleStream(stream); ListPool<UIVertex>.Release(stream); } }
public override void ModifyMesh(VertexHelper vertexHelper) { if (!this.IsActive()) return; List<UIVertex> list = new List<UIVertex>(); vertexHelper.GetUIVertexStream(list); ModifyVertices(list); vertexHelper.AddUIVertexTriangleStream(list); }
public override void ModifyMesh(VertexHelper vh) { List<UIVertex> list = new List<UIVertex>(); vh.GetUIVertexStream(list); vh.Clear(); for (int i = 0; i < list.Count; i++) { var v = list[i]; v.uv1 = AlphaUV[IndexMap[i]]; list[i] = v; } vh.AddUIVertexTriangleStream(list); }
// // ------------------------------------------------------------------>>>>>> TO HERE!! public override void ModifyMesh(VertexHelper vh) { if (!this.IsActive()) return; List<UIVertex> vertexList = new List<UIVertex>(); vh.GetUIVertexStream(vertexList); ModifyVertices(vertexList); vh.Clear(); vh.AddUIVertexTriangleStream(vertexList); }
static public int GetUIVertexStream(IntPtr l) { try { UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l); System.Collections.Generic.List <UnityEngine.UIVertex> a1; checkType(l, 2, out a1); self.GetUIVertexStream(a1); return(0); } catch (Exception e) { return(error(l, e)); } }
public void ModifyMesh(VertexHelper vertexHelper) { if (!this.enabled) return; List<UIVertex> list = new List<UIVertex>(); vertexHelper.GetUIVertexStream(list); ModifyVertices(list); // calls the old ModifyVertices which was used on pre 5.2 vertexHelper.Clear(); vertexHelper.AddUIVertexTriangleStream(list); }
public override void ModifyMesh (VertexHelper vh) { if (IsActive() == false) { return; } var vList = new List<UIVertex>(); vh.GetUIVertexStream(vList); ModifyVertices(vList); vh.Clear(); vh.AddUIVertexTriangleStream(vList); }
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); } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } var vertexList = new List<UIVertex>(); vh.GetUIVertexStream(vertexList); int count = vertexList.Count; ApplyGradient(vertexList, 0, count); vh.Clear(); vh.AddUIVertexTriangleStream(vertexList); }
public override void ModifyMesh(VertexHelper vh) #endif { if (!this.IsActive()) return; List<UIVertex> list = new List<UIVertex>(); vh.GetUIVertexStream(list); ModifyVertices(list); #if UNITY_5_2_1pX || UNITY_5_3 vh.Clear(); #endif vh.AddUIVertexTriangleStream(list); }
public override void ModifyMesh(UnityEngine.UI.VertexHelper vh) { if (!IsActive()) { return; } List <UIVertex> vertices = new List <UIVertex>(); vh.GetUIVertexStream(vertices); TextMove(ref vertices); vh.Clear(); vh.AddUIVertexTriangleStream(vertices); }
public override void ModifyMesh(Mesh mesh) { if (!this.IsActive()) return; List<UIVertex> list = new List<UIVertex>(); using (VertexHelper vertexHelper = new VertexHelper(mesh)) { vertexHelper.GetUIVertexStream(list); } ModifyVertices(list); using (VertexHelper vertexHelper2 = new VertexHelper()) { vertexHelper2.AddUIVertexTriangleStream(list); vertexHelper2.FillMesh(mesh); } }
public override void ModifyMesh(Mesh mesh) { if (this.IsActive()) { List<UIVertex> stream = new List<UIVertex>(); using (VertexHelper helper = new VertexHelper(mesh)) { helper.GetUIVertexStream(stream); } this.ApplyShadow(stream, this.effectColor, 0, stream.Count, this.effectDistance.x, this.effectDistance.y); using (VertexHelper helper2 = new VertexHelper()) { helper2.AddUIVertexTriangleStream(stream); helper2.FillMesh(mesh); } } }
public void ModifyMesh(Mesh mesh) { if (!this.enabled) return; List<UIVertex> list = new List<UIVertex>(); using (VertexHelper vertexHelper = new VertexHelper(mesh)) { vertexHelper.GetUIVertexStream(list); } ModifyVertices(list); // calls the old ModifyVertices which was used on pre 5.2 using (VertexHelper vertexHelper2 = new VertexHelper()) { vertexHelper2.AddUIVertexTriangleStream(list); vertexHelper2.FillMesh(mesh); } }
public override void ModifyMesh(Mesh mesh) { if (!this.IsActive()) return; List<UIVertex> list = new List<UIVertex>(); using (VertexHelper vertexHelper = new VertexHelper(mesh)) { vertexHelper.GetUIVertexStream(list); } ModifyVertices(list); // calls the old ModifyVertices which was used on pre 5.2 using (VertexHelper vertexHelper2 = new VertexHelper()) { vertexHelper2.AddUIVertexTriangleStream(list); vertexHelper2.FillMesh(mesh); } }
public override void ModifyMesh(VertexHelper helper) { if (!IsActive()) { return; } helper.GetUIVertexStream(vertexs); for (int i = 0; i < vertexs.Count; i++) { vertex = vertexs[i]; vertex.position.y += curve.Evaluate(Progress(vertex.position.x)) * ratio - ratio * 0.5f; vertexs[i] = vertex; } helper.AddUIVertexTriangleStream(vertexs); }
public override void ModifyMesh(VertexHelper vh) { if (IsActive()) { List <UIVertex> list = ListPool <UIVertex> .Get(); vh.GetUIVertexStream(list); List <UIVertex> verts = list; Color32 color = effectColor; int count = list.Count; Vector2 effectDistance = this.effectDistance; float x = effectDistance.x; Vector2 effectDistance2 = this.effectDistance; ApplyShadow(verts, color, 0, count, x, effectDistance2.y); vh.Clear(); vh.AddUIVertexTriangleStream(list); ListPool <UIVertex> .Release(list); } }
public override void ModifyMesh(VertexHelper vh) { if (this.IsActive() == false) { return; } List<UIVertex> list = this.temp;//ListPool<UIVertex>.Get(); vh.GetUIVertexStream(list); this.ModifyVertices(list); vh.Clear(); vh.AddUIVertexTriangleStream(list); //ListPool<UIVertex>.Release(list); this.temp.Clear(); }
public override void ModifyMesh(Mesh mesh) { if (!IsActive()) { return; } if (mesh.vertexCount != lastCount || mesh.vertices[0] != lastVector) { verts.Clear(); using (var helper = new VertexHelper(mesh)) helper.GetUIVertexStream(verts); var neededCpacity = verts.Count * 5; if (verts.Capacity < neededCpacity) { verts.Capacity = neededCpacity; } var start = 0; var end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y); } using (var helper = new VertexHelper()) { helper.AddUIVertexTriangleStream(verts); helper.FillMesh(mesh); } }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } vh.GetUIVertexStream(vertexs); int count = vertexs.Count; if (graphic is Image) { Image.Type type = (graphic as Image).type; switch (type) { case Image.Type.Simple: DrawSimple(vertexs, count); break; case Image.Type.Sliced: break; case Image.Type.Tiled: break; case Image.Type.Filled: break; } } else { DrawSimple(vertexs, count); } vh.Clear(); vh.AddUIVertexTriangleStream(vertexs); }
/** * Note: Unity 5.2.1 ModifyMesh(Mesh mesh) used VertexHelper.FillMesh(mesh); * For performance reasons, ModifyMesh(VertexHelper vh) was introduced * @see http://forum.unity3d.com/threads/unity-5-2-ui-performance-seems-much-worse.353650/ */ public override void ModifyMesh(VertexHelper vh) { if (!this.IsActive()) { return; } if (m_spacing == 0) { return; } List <UIVertex> list = new List <UIVertex>(); vh.GetUIVertexStream(list); ModifyVertices(list); vh.Clear(); vh.AddUIVertexTriangleStream(list); }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } List <UIVertex> output = new List <UIVertex>(); vh.GetUIVertexStream(output); if (m_horizontal) { ApplyGradientColorHorizontal(m_keyPointsColor, output); } else { ApplyGradientColorVertial(m_keyPointsColor, output); } vh.Clear(); vh.AddUIVertexTriangleStream(output); output.Clear(); }
private void ModifyVertices(VertexHelper vh) { List<UIVertex> verts = new List<UIVertex>(vh.currentVertCount); vh.GetUIVertexStream(verts); vh.Clear(); int step = 6; for (int i = 0; i < verts.Count; i += step) { //6 point var tl = multiplyColor(verts[i+0], colorTop); var tr = multiplyColor (verts [i+1], colorTop); var bl = multiplyColor (verts [i+4], colorBottom); var br = multiplyColor (verts [i + 3], colorBottom); var cl = calcCenterVertex(verts[i+0], verts [i+4]); var cr = calcCenterVertex (verts [i+1], verts [i+2]); vh.AddVert (tl); vh.AddVert (tr); vh.AddVert (cr); vh.AddVert (cr); vh.AddVert (cl); vh.AddVert (tl); vh.AddVert (cl); vh.AddVert (cr); vh.AddVert (br); vh.AddVert (br); vh.AddVert (bl); vh.AddVert (cl); } for (int i = 0; i < vh.currentVertCount; i += 12) { vh.AddTriangle (i + 0, i + 1, i + 2); vh.AddTriangle (i + 3, i + 4, i + 5); vh.AddTriangle (i + 6, i + 7, i + 8); vh.AddTriangle (i + 9, i + 10, i + 11); } }
protected override void OnPopulateMesh(VertexHelper vh) { base.OnPopulateMesh(vh); List<UIVertex> stream = new List<UIVertex>(); vh.GetUIVertexStream(stream); for (int i = 0; i < stream.Count; i++) { UIVertex v = stream[i]; float percentCircumference = v.position.x/circumference; Vector3 offset = Quaternion.Euler(0.0f,0.0f,-percentCircumference*360.0f)*Vector3.up; v.position = offset*radius*scaleFactor + offset*v.position.y; v.position += Vector3.down*radius*scaleFactor; stream[i] = v; } vh.AddUIVertexTriangleStream(stream); }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } var verts = ListPool <UIVertex> .Get(); vh.GetUIVertexStream(verts); var neededCpacity = verts.Count * 5; if (verts.Capacity < neededCpacity) { verts.Capacity = neededCpacity; } var start = 0; var end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y); vh.Clear(); vh.AddUIVertexTriangleStream(verts); ListPool <UIVertex> .Release(verts); }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) { return; } List<UIVertex> vertexList = new List<UIVertex>(); vh.GetUIVertexStream(vertexList); int count = vertexList.Count; float bottomY = vertexList[0].position.y; float topY = vertexList[0].position.y; for (int i = 1; i < count; i++) { float y = vertexList[i].position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } } float uiElementHeight = topY - bottomY; for (int i = 0; i < count; i++) { UIVertex uiVertex = vertexList[i]; uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight); vertexList[i] = uiVertex; } vh.Clear(); vh.AddUIVertexTriangleStream(vertexList); }
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); } }
protected override void OnPopulateMesh(VertexHelper vh) { base.OnPopulateMesh(vh); List <UIVertex> vbo = new List <UIVertex>(); vh.GetUIVertexStream(vbo); if (overrideSprite) { var outter = UnityEngine.Sprites.DataUtility.GetOuterUV(overrideSprite); float w = outter.z - outter.x; float h = outter.w - outter.y; if (w == 0) { w = 1; } if (h == 0) { h = 1; } for (int i = 0; i < vbo.Count; ++i) { var vertex = vbo[i]; var uv = vertex.uv0; var u = (uv.x - outter.x) / w; var v = (uv.y - outter.y) / h; vertex.uv1 = new Vector2(u, v); vbo[i] = vertex; } } vh.Clear(); vh.AddUIVertexTriangleStream(vbo); vbo.Clear(); }
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.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()) { return; } var verts = new List <UIVertex> (); vh.GetUIVertexStream(verts); var neededCpacity = verts.Count * 5; if (verts.Capacity < neededCpacity) { verts.Capacity = neededCpacity; } if (glintEffect) { for (int i = 0; i < verts.Count; i++) { UIVertex item = verts [i]; for (int j = -glintWidth; j <= glintWidth; j++) { if (i % 6 == Mathf.Repeat(glintVertex + j, 6)) { item.color = glintColor; } } verts [i] = item; } } Vector2 m_effectDistance = new Vector2(m_size, m_size); var start = 0; var end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, m_effectDistance.x, m_effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, m_effectDistance.x, -m_effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -m_effectDistance.x, m_effectDistance.y); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -m_effectDistance.x, -m_effectDistance.y); ////////////////////////////// start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, 0, m_effectDistance.y * 1.5f); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, m_effectDistance.x * 1.5f, 0); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -m_effectDistance.x * 1.5f, 0); start = end; end = verts.Count; ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, 0, -m_effectDistance.y * 1.5f); vh.Clear(); vh.AddUIVertexTriangleStream(verts); }
public override void ModifyMesh(UnityEngine.UI.VertexHelper helper) { if (!IsActive()) { return; } List <UIVertex> verts = ListPool <UIVertex> .Get(); helper.GetUIVertexStream(verts); Text text = GetComponent <Text>(); if (text == null) { Debug.LogWarning("LetterSpacing: Missing Text component"); return; } 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 = text.text; float lineOffset = (line.Length - 1) * letterOffset * alignmentFactor; for (int charIdx = 0; charIdx < line.Length; charIdx++) { int idx1 = glyphIdx * 6 + 0; int idx2 = glyphIdx * 6 + 1; int idx3 = glyphIdx * 6 + 2; int idx4 = glyphIdx * 6 + 3; int idx5 = glyphIdx * 6 + 4; int idx6 = glyphIdx * 6 + 5; // Check for truncated text (doesn't generate verts for all characters) if (idx4 > verts.Count - 1) { return; } UIVertex vert1 = verts[idx1]; UIVertex vert2 = verts[idx2]; UIVertex vert3 = verts[idx3]; UIVertex vert4 = verts[idx4]; UIVertex vert5 = verts[idx5]; UIVertex vert6 = verts[idx6]; pos = Vector3.right * (letterOffset * charIdx - lineOffset); vert1.position += pos; vert2.position += pos; vert3.position += pos; vert4.position += pos; vert5.position += pos; vert6.position += pos; verts[idx1] = vert1; verts[idx2] = vert2; verts[idx3] = vert3; verts[idx4] = vert4; verts[idx5] = vert5; verts[idx6] = vert6; glyphIdx++; } // Offset for carriage return character that still generates verts glyphIdx++; } helper.Clear(); helper.AddUIVertexTriangleStream(verts); verts.ReleaseToPool(); }
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--; } } } }
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 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 Color32 topColor = Color.white; //public Color32 bottomColor = Color.black; //public override void ModifyMesh(VertexHelper helper) //{ // if (!this.IsActive() || helper.currentVertCount == 0) // return; // List<UIVertex> vertexs = new List<UIVertex>(); // helper.GetUIVertexStream(vertexs); // float bottomY = vertexs[0].position.y; // float topY = vertexs[0].position.y; // for (int i = 1; i < vertexs.Count; i++) // { // float y = vertexs[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); // } //} public override void ModifyMesh(VertexHelper vh) { if (!IsActive() || mGradient == null) { return; } List<UIVertex> vertexList = new List<UIVertex>(); vh.GetUIVertexStream(vertexList); if (vertexList == null || vertexList.Count == 0) { return; } float leftX = vertexList[0].position.x; float rightX = vertexList[0].position.x; float bottomY = vertexList[0].position.y; float topY = vertexList[0].position.y; for (int i = 1; i < vertexList.Count; i++) { float y = vertexList[i].position.y; if (y > topY) { topY = y; } else if (y < bottomY) { bottomY = y; } float x = vertexList[i].position.x; if (x > rightX) { rightX = x; } else if (x < leftX) { leftX = x; } } for (int i = 0; i < vertexList.Count; i++) { UIVertex uiVertex = vertexList[i]; if (mDirection == Direction.Vertical) { uiVertex.color = mGradient.Evaluate((uiVertex.position.y - bottomY) / (topY - bottomY)); } else { uiVertex.color = mGradient.Evaluate((uiVertex.position.x - leftX) / (rightX - leftX)); } vertexList[i] = uiVertex; } vh.Clear(); vh.AddUIVertexTriangleStream(vertexList); }
/// <summary> /// Modifies the mesh. /// </summary> public virtual void ModifyMesh(VertexHelper vh) { if (!isActiveAndEnabled) { return; } UIVertex vt; vh.GetUIVertexStream(s_Verts); //================================ // Only main effect modify original vertices. //================================ if (mainEffect == this) { // Calcurate bluring uv from blur factor and texture size. float blurringUv = m_Blur / graphic.mainTexture.width; // Pack some effect factors to 1 float. Vector2 factor = new Vector2( PackToFloat(m_ToneLevel, 0, blurringUv * 4), PackToFloat(m_Color.r, m_Color.g, m_Color.b, m_Color.a) ); for (int i = 0; i < s_Verts.Count; i++) { vt = s_Verts[i]; // Set UIEffect prameters to vertex. vt.uv1 = factor; s_Verts[i] = vt; } } //================================ // Append shadow vertices. //================================ if (ShadowMode.Shadow <= m_ShadowMode) { var inputVertCount = s_Verts.Count; var start = 0; var end = inputVertCount; // Calcurate bluring uv from blur factor and texture size. float blurringUv = m_ShadowBlur / graphic.mainTexture.width; // Pack some effect factors to 1 float. Vector2 factor = new Vector2( PackToFloat(m_ToneLevel, 0, blurringUv * 4), PackToFloat(m_ShadowColor.r, m_ShadowColor.g, m_ShadowColor.b, 1) ); ApplyShadowZeroAlloc(s_Verts, ref start, ref end, m_EffectDistance.x, m_EffectDistance.y, factor); // Append shadow for Outline. if (ShadowMode.Outline <= m_ShadowMode) { ApplyShadowZeroAlloc(s_Verts, ref start, ref end, m_EffectDistance.x, -m_EffectDistance.y, factor); ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -m_EffectDistance.x, m_EffectDistance.y, factor); ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -m_EffectDistance.x, -m_EffectDistance.y, factor); } // Append shadow for Outline8. if (ShadowMode.Outline8 <= m_ShadowMode) { ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -m_EffectDistance.x, 0, factor); ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, -m_EffectDistance.y, factor); ApplyShadowZeroAlloc(s_Verts, ref start, ref end, m_EffectDistance.x, 0, factor); ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, m_EffectDistance.y, factor); } } vh.Clear(); vh.AddUIVertexTriangleStream(s_Verts); s_Verts.Clear(); }
public override void ModifyMesh(VertexHelper vh) { if (!IsActive()) return; var output = ListPool<UIVertex>.Get(); vh.GetUIVertexStream(output); ApplyShadow(output, effectColor, 0, output.Count, effectDistance.x, effectDistance.y); vh.Clear(); vh.AddUIVertexTriangleStream(output); ListPool<UIVertex>.Release(output); }
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); } } }
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 (!this.IsActive()) return; List<UIVertex> list = ListPool<UIVertex>.Get(); vh.GetUIVertexStream(list); this.ApplyShadow(list, (Color32) this.effectColor, 0, list.Count, this.effectDistance.x, this.effectDistance.y); vh.Clear(); vh.AddUIVertexTriangleStream(list); ListPool<UIVertex>.Release(list); }
public override void ModifyMesh(UnityEngine.UI.VertexHelper helper) { var verts = ListPool <UIVertex> .Get(); var newVerts = ListPool <UIVertex> .Get(); helper.GetUIVertexStream(verts); helper.Clear(); int count = verts.Count; int shapeCount = count / 6; int shapeIndex = 0; for (int i = 0; i < shapeCount; ++i) { int curIndex = i * 6; bool isUVVertical = (GetComponent <Graphic>() is Text) && (verts [curIndex].uv0.x == verts [curIndex + 1].uv0.x); Vector2 minUV = verts [curIndex + 0].uv0; Vector2 maxUV = verts [curIndex + 2].uv0; Vector3 minPos = verts [curIndex + 0].position; Vector3 maxPos = verts [curIndex + 2].position; Vector3 lengthPos = (maxPos - minPos) / m_Fineness; Vector2 lengthUV = (maxUV - minUV) / m_Fineness; for (int j = 0; j < m_Fineness; ++j) { for (int k = 0; k < 6; ++k) { var vert = verts [curIndex + k]; float x = 0; float y = 0; float uvx = 0; float uvy = 0; bool isX = (k == 0 || k == 4 || k == 5); bool isY = (k == 0 || k == 1 || k == 5); if ((isUVVertical && isX) || (!isUVVertical && isY)) { uvy = isUVVertical ? minUV.y + lengthUV.y * j : minUV.y; y = minPos.y; } else { uvy = isUVVertical ? minUV.y + lengthUV.y * (j + 1) : maxUV.y; y = maxPos.y; } y = (isY ? minPos.y : maxPos.y); if ((isUVVertical && isY) || (!isUVVertical && isX)) { uvx = isUVVertical ? minUV.x : minUV.x + lengthUV.x * j; } else { uvx = isUVVertical ? maxUV.x : minUV.x + lengthUV.x * (j + 1); } x = (isX ? minPos.x + lengthPos.x * j : minPos.x + lengthPos.x * (j + 1)); vert.position = new Vector3(x, y, minPos.z); vert.uv0 = new Vector2(uvx, uvy); newVerts.Add(vert); } } shapeIndex += m_Fineness; } helper.Clear(); helper.AddUIVertexTriangleStream(newVerts); newVerts.ReleaseToPool(); verts.ReleaseToPool(); }
public override void ModifyMesh(VertexHelper helper)//List<UIVertex> verts { if (!IsActive()) { return; } List <UIVertex> verts = new List <UIVertex>(); helper.GetUIVertexStream(verts); Text text = GetComponent <Text>(); if (text == null) { TTLoger.LogWarning("LetterSpacing: Missing Text component"); return; } string s = text.text; rt.ParseRichText(s); string[] lines = s.Split('\n'); Vector3 pos; float letterOffset = spacing * (float)text.fontSize / ScaleFactor; float alignmentFactor = 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 i = 0; i < rt.root.childCount; ++i) { // 获取行对象 RichTextSegment lineSeg = rt.root.GetChild(i) as RichTextSegment; int startShowGlyphIndexInLine = 0; // 遍历行内对象 for (int k = 0; k < lineSeg.childCount; ++k) { // 获取行内对象 RichTextSegment child = lineSeg.GetChild(k); // for (int showGlyphIdx = 0; showGlyphIdx < child.showGlyphCount; ++showGlyphIdx) { int glyphIndex = child.startIndex + showGlyphIdx; int idx1 = glyphIndex * 6 + 0; int idx2 = glyphIndex * 6 + 1; int idx3 = glyphIndex * 6 + 2; int idx4 = glyphIndex * 6 + 3; int idx5 = glyphIndex * 6 + 4; int idx6 = glyphIndex * 6 + 5; if (idx6 > verts.Count - 1) { return; } UIVertex vert1 = verts[idx1]; UIVertex vert2 = verts[idx2]; UIVertex vert3 = verts[idx3]; UIVertex vert4 = verts[idx4]; UIVertex vert5 = verts[idx5]; UIVertex vert6 = verts[idx6]; float f = (letterOffset * (startShowGlyphIndexInLine + showGlyphIdx) - lineOffset); pos = Vector3.right * f; vert1.position += pos; vert2.position += pos; vert3.position += pos; vert4.position += pos; vert5.position += pos; vert6.position += pos; verts[idx1] = vert1; verts[idx2] = vert2; verts[idx3] = vert3; verts[idx4] = vert4; verts[idx5] = vert5; verts[idx6] = vert6; } startShowGlyphIndexInLine += child.showGlyphCount; } } } helper.Clear(); helper.AddUIVertexTriangleStream(verts); }
//5.2.1p1 public void ModifyMesh(VertexHelper vh) { if (enabled && gameObject.activeInHierarchy) { var verts = new List<UIVertex>(); var glyph = new GlyphQuad(); vh.GetUIVertexStream(verts); vh.Dispose(); for (int c = 0; c < Text.text.Length; c++) { glyph.LoadTris(verts, c * 6); float xDistance = AbsolutePosition + glyph.Rect.center.x; float tf = AbsoluteToRelative(xDistance); Vector3 pos = this.GetInterpolatedSourcePosition(tf); Vector3 tan = this.GetTangent(tf); var off = pos - Rect.localPosition - glyph.Center; // position offset to spline glyph.Transpose(new Vector3(0, glyph.Center.y, 0)); // shift to match baseline // Rotate, then offset to real position glyph.Rotate(Quaternion.AngleAxis(Mathf.Atan2(tan.x, -tan.y) * Mathf.Rad2Deg - 90, Vector3.forward)); glyph.Transpose(off); glyph.Save(vh); } } }
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; } }