Clear all vertices from the stream.
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(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); }
/// <summary> /// Virtual function to create the UI mesh. /// </summary> protected override void OnPopulateMesh(UnityEngine.UI.VertexHelper vh) { //base.OnPopulateMesh(vh); vh.Clear(); // Weird things can happen since we're derived off a Graphic if (Application.isPlaying == false) { return; } // Combine the UI elements we're tracking into a line strip. List <Vector2> lineStrip = new List <Vector2>(); foreach (RectTransform rt in this.points) { lineStrip.Add(rt.anchoredPosition); } List <Vector2> infs = GetInflationVectors(lineStrip); // Create the inflated mesh at the width the user specified from the control. CreateInflatedMesh(vh, lineStrip, infs, this.width, new Color(1.0f, 0.5f, 0.25f)); // And then create an inflated line strip mesh on top that's just 1 radius thickness // that represents the unprocessed line. CreateInflatedMesh(vh, lineStrip, infs, 1.0f, Color.black); }
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); }
static public int Clear(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); self.Clear(); 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 }
void EditMesh(VertexHelper vh) { vh.Clear(); int count = vertexInfoList.Count; if (count < 3) return;//3개서부터 보임 for (int n = 0; n < vertexInfoList.Count; n++) { vh.AddVert(getRadiusPosition(vertexInfoList[n], n), checkVertexColor(vertexInfoList[n].color) ,Vector2.zero); } if (!innerPolygon) { for (int n = 0; n < count - 2; n++) { vh.AddTriangle(0, n + 1, n + 2); } } else { for (int n = 0; n < count; n++) { vh.AddVert(getRadiusPosition(vertexInfoList[n], n, width), checkVertexColor(vertexInfoList[n].color), Vector2.zero); } for (int n = 0; n < count; n++) { vh.AddTriangle(n, (n + 1) % count, count + (1 + n) % count); vh.AddTriangle(n, n + count, count + (1 + n) % count); } } }
protected override void OnPopulateMesh(VertexHelper vh) { if (this.mesh == null) return; var color32 = this.color; vh.Clear(); var vs = this.mesh.vertices; for (int i = 0; i < vs.Length; ++i) { var v = vs[i]; vh.AddVert(new Vector3(v.x, v.y), color32, Vector2.zero); } var ts = this.mesh.triangles; for (int i = 0; i < ts.Length; i += 3) { var t1 = ts[i]; var t2 = ts[i + 1]; var t3 = ts[i + 2]; vh.AddTriangle(t1, t2, t3); } }
public override void ModifyMesh(VertexHelper vertexHelper) { List<UIVertex> vertexList = new List<UIVertex>(); vertexHelper.GetUIVertexStream(vertexList); ModifyVertices(vertexList); vertexHelper.Clear(); vertexHelper.AddUIVertexTriangleStream(vertexList); }
static public int Clear(IntPtr l) { try { UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l); self.Clear(); return(0); } catch (Exception e) { return(error(l, e)); } }
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 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); }
public override void ModifyMesh(VertexHelper vh) { if (!this.IsActive()) return; List<UIVertex> list = new List<UIVertex>(); vh.GetUIVertexStream(list); ModifyVertices(list); vh.Clear(); vh.AddUIVertexTriangleStream(list); }
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); }
/// private function void EditMesh(VertexHelper vh) { vh.Clear(); UIVertex[] prvVert = null; for (int n = 0; n < points.Count-1; n++) { if (CheckLength(GetLength(n))) { break; } prvVert = DrawLine(n, vh, prvVert); } }
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 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 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); }
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 })); } }
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(); }
protected override void OnPopulateMesh(VertexHelper vh) { Texture mainTexture = this.mainTexture; vh.Clear(); if (mainTexture != null) { Rect pixelAdjustedRect = base.GetPixelAdjustedRect(); Vector4 vector = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height); float num = mainTexture.width * mainTexture.texelSize.x; float num2 = mainTexture.height * mainTexture.texelSize.y; Color color = this.color; vh.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(this.m_UVRect.xMin * num, this.m_UVRect.yMin * num2)); vh.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(this.m_UVRect.xMin * num, this.m_UVRect.yMax * num2)); vh.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(this.m_UVRect.xMax * num, this.m_UVRect.yMax * num2)); vh.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(this.m_UVRect.xMax * num, this.m_UVRect.yMin * num2)); vh.AddTriangle(0, 1, 2); vh.AddTriangle(2, 3, 0); } }
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); } }
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); }
protected override void OnPopulateMesh(UnityEngine.UI.VertexHelper vh) { if (!HollowRect) { return; } Color32 color32 = color; vh.Clear(); Rect innerRect = new Rect(pos, size); Rect outerRect = GetPixelAdjustedRect(); AddQuad(vh, new Vector2(outerRect.xMin, outerRect.yMax), new Vector2(outerRect.xMax, innerRect.center.y), color); AddQuad(vh, new Vector2(outerRect.xMin, innerRect.center.y), new Vector2(HollowRect.anchoredPosition.x - innerRect.width / 2, HollowRect.anchoredPosition.y - innerRect.height / 2), color); AddQuad(vh, new Vector2(HollowRect.anchoredPosition.x + innerRect.width / 2, innerRect.center.y), new Vector2(outerRect.xMax, HollowRect.anchoredPosition.y - innerRect.height / 2), color); AddQuad(vh, new Vector2(outerRect.xMin, HollowRect.anchoredPosition.y - innerRect.height / 2), new Vector2(outerRect.xMax, -outerRect.yMax), color); }
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); }
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; }
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 vh) { if (!isActiveAndEnabled) { return; } if (rectTransform == null) { rectTransform = GetComponent <RectTransform>(); } if (image == null) { image = GetComponent <Image>(); } if (image.type != Image.Type.Simple) { return; } Sprite sprite = image.overrideSprite; if (sprite == null || sprite.triangles.Length == 6) { // only 2 triangles return; } // Kanglai: at first I copy codes from Image.GetDrawingDimensions // to calculate Image's dimensions. But now for easy to read, I just take usage of corners. if (vh.currentVertCount != 4) { return; } rectTransform.GetLocalCorners(fourCorners); // Kanglai: recalculate vertices from Sprite! int len = sprite.vertices.Length; var vertices = new List <UIVertex>(len); Vector2 Center = sprite.bounds.center; Vector2 invExtend = new Vector2(1 / sprite.bounds.size.x, 1 / sprite.bounds.size.y); for (int i = 0; i < len; i++) { // normalize float x = (sprite.vertices[i].x - Center.x) * invExtend.x + 0.5f; float y = (sprite.vertices[i].y - Center.y) * invExtend.y + 0.5f; // lerp to position vertice.position = new Vector2(Mathf.Lerp(fourCorners[0].x, fourCorners[2].x, x), Mathf.Lerp(fourCorners[0].y, fourCorners[2].y, y)); vertice.color = image.color; vertice.uv0 = sprite.uv[i]; vertices.Add(vertice); } len = sprite.triangles.Length; var triangles = new List <int>(len); for (int i = 0; i < len; i++) { triangles.Add(sprite.triangles[i]); } vh.Clear(); vh.AddUIVertexStream(vertices, triangles); }
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; } }
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); } }
/// <summary> /// Generate vertices for a tiled Image. /// </summary> void GenerateTiledSprite(VertexHelper toFill) { Vector4 outer, inner, border; Vector2 spriteSize; if (overrideSprite != null) { outer = Sprites.DataUtility.GetOuterUV(overrideSprite); inner = Sprites.DataUtility.GetInnerUV(overrideSprite); border = overrideSprite.border; spriteSize = overrideSprite.rect.size; } else { outer = Vector4.zero; inner = Vector4.zero; border = Vector4.zero; spriteSize = Vector2.one * 100; } Rect rect = GetPixelAdjustedRect(); float tileWidth = (spriteSize.x - border.x - border.z) / pixelsPerUnit; float tileHeight = (spriteSize.y - border.y - border.w) / pixelsPerUnit; border = GetAdjustedBorders(border / pixelsPerUnit, rect); var uvMin = new Vector2(inner.x, inner.y); var uvMax = new Vector2(inner.z, inner.w); var v = UIVertex.simpleVert; v.color = color; // Min to max max range for tiled region in coordinates relative to lower left corner. float xMin = border.x; float xMax = rect.width - border.z; float yMin = border.y; float yMax = rect.height - border.w; toFill.Clear(); var clipped = uvMax; // if either with is zero we cant tile so just assume it was the full width. if (tileWidth == 0) tileWidth = xMax - xMin; if (tileHeight == 0) tileHeight = yMax - yMin; if (m_FillCenter) { for (float y1 = yMin; y1 < yMax; y1 += tileHeight) { float y2 = y1 + tileHeight; if (y2 > yMax) { clipped.y = uvMin.y + (uvMax.y - uvMin.y) * (yMax - y1) / (y2 - y1); y2 = yMax; } clipped.x = uvMax.x; for (float x1 = xMin; x1 < xMax; x1 += tileWidth) { float x2 = x1 + tileWidth; if (x2 > xMax) { clipped.x = uvMin.x + (uvMax.x - uvMin.x) * (xMax - x1) / (x2 - x1); x2 = xMax; } AddQuad(toFill, new Vector2(x1, y1) + rect.position, new Vector2(x2, y2) + rect.position, color, uvMin, clipped); } } } if (hasBorder) { clipped = uvMax; for (float y1 = yMin; y1 < yMax; y1 += tileHeight) { float y2 = y1 + tileHeight; if (y2 > yMax) { clipped.y = uvMin.y + (uvMax.y - uvMin.y) * (yMax - y1) / (y2 - y1); y2 = yMax; } AddQuad(toFill, new Vector2(0, y1) + rect.position, new Vector2(xMin, y2) + rect.position, color, new Vector2(outer.x, uvMin.y), new Vector2(uvMin.x, clipped.y)); AddQuad(toFill, new Vector2(xMax, y1) + rect.position, new Vector2(rect.width, y2) + rect.position, color, new Vector2(uvMax.x, uvMin.y), new Vector2(outer.z, clipped.y)); } // Bottom and top tiled border clipped = uvMax; for (float x1 = xMin; x1 < xMax; x1 += tileWidth) { float x2 = x1 + tileWidth; if (x2 > xMax) { clipped.x = uvMin.x + (uvMax.x - uvMin.x) * (xMax - x1) / (x2 - x1); x2 = xMax; } AddQuad(toFill, new Vector2(x1, 0) + rect.position, new Vector2(x2, yMin) + rect.position, color, new Vector2(uvMin.x, outer.y), new Vector2(clipped.x, uvMin.y)); AddQuad(toFill, new Vector2(x1, yMax) + rect.position, new Vector2(x2, rect.height) + rect.position, color, new Vector2(uvMin.x, uvMax.y), new Vector2(clipped.x, outer.w)); } // Corners AddQuad(toFill, new Vector2(0, 0) + rect.position, new Vector2(xMin, yMin) + rect.position, color, new Vector2(outer.x, outer.y), new Vector2(uvMin.x, uvMin.y)); AddQuad(toFill, new Vector2(xMax, 0) + rect.position, new Vector2(rect.width, yMin) + rect.position, color, new Vector2(uvMax.x, outer.y), new Vector2(outer.z, uvMin.y)); AddQuad(toFill, new Vector2(0, yMax) + rect.position, new Vector2(xMin, rect.height) + rect.position, color, new Vector2(outer.x, uvMax.y), new Vector2(uvMin.x, outer.w)); AddQuad(toFill, new Vector2(xMax, yMax) + rect.position, new Vector2(rect.width, rect.height) + rect.position, color, new Vector2(uvMax.x, uvMax.y), new Vector2(outer.z, outer.w)); } }
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(); }
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 (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; }
/// <summary> /// Fill the vertex buffer data. /// </summary> protected virtual void OnPopulateMesh(VertexHelper vh) { var r = GetPixelAdjustedRect(); var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height); Color32 color32 = color; vh.Clear(); vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(0f, 0f)); vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(0f, 1f)); vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(1f, 1f)); vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(1f, 0f)); vh.AddTriangle(0, 1, 2); vh.AddTriangle(2, 3, 0); }
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> /// Generate vertices for a simple Image. /// </summary> void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect) { Vector4 v = GetDrawingDimensions(lPreserveAspect); var uv = (overrideSprite != null) ? Sprites.DataUtility.GetOuterUV(overrideSprite) : Vector4.zero; var color32 = color; vh.Clear(); vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(uv.x, uv.y)); vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(uv.x, uv.w)); vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(uv.z, uv.w)); vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(uv.z, uv.y)); vh.AddTriangle(0, 1, 2); vh.AddTriangle(2, 3, 0); }
private void GenerateSlicedSprite(VertexHelper toFill) { if (!hasBorder) { GenerateSimpleSprite(toFill, false); return; } Vector4 outer, inner, padding, border; if (overrideSprite != null) { outer = Sprites.DataUtility.GetOuterUV(overrideSprite); inner = Sprites.DataUtility.GetInnerUV(overrideSprite); padding = Sprites.DataUtility.GetPadding(overrideSprite); border = overrideSprite.border; } else { outer = Vector4.zero; inner = Vector4.zero; padding = Vector4.zero; border = Vector4.zero; } Rect rect = GetPixelAdjustedRect(); border = GetAdjustedBorders(border / pixelsPerUnit, rect); padding = padding / pixelsPerUnit; s_VertScratch[0] = new Vector2(padding.x, padding.y); s_VertScratch[3] = new Vector2(rect.width - padding.z, rect.height - padding.w); s_VertScratch[1].x = border.x; s_VertScratch[1].y = border.y; s_VertScratch[2].x = rect.width - border.z; s_VertScratch[2].y = rect.height - border.w; for (int i = 0; i < 4; ++i) { s_VertScratch[i].x += rect.x; s_VertScratch[i].y += rect.y; } s_UVScratch[0] = new Vector2(outer.x, outer.y); s_UVScratch[1] = new Vector2(inner.x, inner.y); s_UVScratch[2] = new Vector2(inner.z, inner.w); s_UVScratch[3] = new Vector2(outer.z, outer.w); toFill.Clear(); for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!m_FillCenter && x == 1 && y == 1) continue; int y2 = y + 1; AddQuad(toFill, new Vector2(s_VertScratch[x].x, s_VertScratch[y].y), new Vector2(s_VertScratch[x2].x, s_VertScratch[y2].y), color, new Vector2(s_UVScratch[x].x, s_UVScratch[y].y), new Vector2(s_UVScratch[x2].x, s_UVScratch[y2].y)); } } }
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); } } }
void GenerateFilledSprite(VertexHelper toFill, bool preserveAspect) { toFill.Clear(); if (m_FillAmount < 0.001f) return; Vector4 v = GetDrawingDimensions(preserveAspect); Vector4 outer = overrideSprite != null ? Sprites.DataUtility.GetOuterUV(overrideSprite) : Vector4.zero; UIVertex uiv = UIVertex.simpleVert; uiv.color = color; float tx0 = outer.x; float ty0 = outer.y; float tx1 = outer.z; float ty1 = outer.w; // Horizontal and vertical filled sprites are simple -- just end the Image prematurely if (m_FillMethod == FillMethod.Horizontal || m_FillMethod == FillMethod.Vertical) { if (fillMethod == FillMethod.Horizontal) { float fill = (tx1 - tx0) * m_FillAmount; if (m_FillOrigin == 1) { v.x = v.z - (v.z - v.x) * m_FillAmount; tx0 = tx1 - fill; } else { v.z = v.x + (v.z - v.x) * m_FillAmount; tx1 = tx0 + fill; } } else if (fillMethod == FillMethod.Vertical) { float fill = (ty1 - ty0) * m_FillAmount; if (m_FillOrigin == 1) { v.y = v.w - (v.w - v.y) * m_FillAmount; ty0 = ty1 - fill; } else { v.w = v.y + (v.w - v.y) * m_FillAmount; ty1 = ty0 + fill; } } } s_Xy[0] = new Vector2(v.x, v.y); s_Xy[1] = new Vector2(v.x, v.w); s_Xy[2] = new Vector2(v.z, v.w); s_Xy[3] = new Vector2(v.z, v.y); s_Uv[0] = new Vector2(tx0, ty0); s_Uv[1] = new Vector2(tx0, ty1); s_Uv[2] = new Vector2(tx1, ty1); s_Uv[3] = new Vector2(tx1, ty0); { if (m_FillAmount < 1f && m_FillMethod != FillMethod.Horizontal && m_FillMethod != FillMethod.Vertical) { if (fillMethod == FillMethod.Radial90) { if (RadialCut(s_Xy, s_Uv, m_FillAmount, m_FillClockwise, m_FillOrigin)) AddQuad(toFill, s_Xy, color, s_Uv); } else if (fillMethod == FillMethod.Radial180) { for (int side = 0; side < 2; ++side) { float fx0, fx1, fy0, fy1; int even = m_FillOrigin > 1 ? 1 : 0; if (m_FillOrigin == 0 || m_FillOrigin == 2) { fy0 = 0f; fy1 = 1f; if (side == even) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } } else { fx0 = 0f; fx1 = 1f; if (side == even) { fy0 = 0.5f; fy1 = 1f; } else { fy0 = 0f; fy1 = 0.5f; } } s_Xy[0].x = Mathf.Lerp(v.x, v.z, fx0); s_Xy[1].x = s_Xy[0].x; s_Xy[2].x = Mathf.Lerp(v.x, v.z, fx1); s_Xy[3].x = s_Xy[2].x; s_Xy[0].y = Mathf.Lerp(v.y, v.w, fy0); s_Xy[1].y = Mathf.Lerp(v.y, v.w, fy1); s_Xy[2].y = s_Xy[1].y; s_Xy[3].y = s_Xy[0].y; s_Uv[0].x = Mathf.Lerp(tx0, tx1, fx0); s_Uv[1].x = s_Uv[0].x; s_Uv[2].x = Mathf.Lerp(tx0, tx1, fx1); s_Uv[3].x = s_Uv[2].x; s_Uv[0].y = Mathf.Lerp(ty0, ty1, fy0); s_Uv[1].y = Mathf.Lerp(ty0, ty1, fy1); s_Uv[2].y = s_Uv[1].y; s_Uv[3].y = s_Uv[0].y; float val = m_FillClockwise ? fillAmount * 2f - side : m_FillAmount * 2f - (1 - side); if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(val), m_FillClockwise, ((side + m_FillOrigin + 3) % 4))) { AddQuad(toFill, s_Xy, color, s_Uv); } } } else if (fillMethod == FillMethod.Radial360) { for (int corner = 0; corner < 4; ++corner) { float fx0, fx1, fy0, fy1; if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } else { fy0 = 0.5f; fy1 = 1f; } s_Xy[0].x = Mathf.Lerp(v.x, v.z, fx0); s_Xy[1].x = s_Xy[0].x; s_Xy[2].x = Mathf.Lerp(v.x, v.z, fx1); s_Xy[3].x = s_Xy[2].x; s_Xy[0].y = Mathf.Lerp(v.y, v.w, fy0); s_Xy[1].y = Mathf.Lerp(v.y, v.w, fy1); s_Xy[2].y = s_Xy[1].y; s_Xy[3].y = s_Xy[0].y; s_Uv[0].x = Mathf.Lerp(tx0, tx1, fx0); s_Uv[1].x = s_Uv[0].x; s_Uv[2].x = Mathf.Lerp(tx0, tx1, fx1); s_Uv[3].x = s_Uv[2].x; s_Uv[0].y = Mathf.Lerp(ty0, ty1, fy0); s_Uv[1].y = Mathf.Lerp(ty0, ty1, fy1); s_Uv[2].y = s_Uv[1].y; s_Uv[3].y = s_Uv[0].y; float val = m_FillClockwise ? m_FillAmount * 4f - ((corner + m_FillOrigin) % 4) : m_FillAmount * 4f - (3 - ((corner + m_FillOrigin) % 4)); if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(val), m_FillClockwise, ((corner + 2) % 4))) AddQuad(toFill, s_Xy, color, s_Uv); } } } else { AddQuad(toFill, s_Xy, color, s_Uv); } } }
/// <summary> /// Update all renderer data. /// </summary> #if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear(); List<UIVertex> aVerts = new List<UIVertex>(); _OnFillVBO(aVerts); List<int> aIndicies = new List<int>(new int[] { 0, 1, 2, 2, 3, 0 }); vh.AddUIVertexStream(aVerts, aIndicies); }
protected override void OnPopulateMesh(VertexHelper toFill) { toFill.Clear(); }
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>("Binary/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++) { if (EmojiIndex.TryGetValue(matches[i].Value, out var 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) { int index = i / 4; if (emojiDic.TryGetValue(index, out var 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 vh) { Texture mainTexture = this.mainTexture; vh.Clear(); if (!((Object) mainTexture != (Object) null)) return; Rect pixelAdjustedRect = this.GetPixelAdjustedRect(); Vector4 vector4 = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height); Color color = this.color; vh.AddVert(new Vector3(vector4.x, vector4.y), (Color32) color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin)); vh.AddVert(new Vector3(vector4.x, vector4.w), (Color32) color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax)); vh.AddVert(new Vector3(vector4.z, vector4.w), (Color32) color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax)); vh.AddVert(new Vector3(vector4.z, vector4.y), (Color32) color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin)); vh.AddTriangle(0, 1, 2); vh.AddTriangle(2, 3, 0); }
private void GenerateFilledSprite(VertexHelper toFill, bool preserveAspect) { toFill.Clear(); if ((double) this.m_FillAmount < 1.0 / 1000.0) return; Vector4 drawingDimensions = this.GetDrawingDimensions(preserveAspect); Vector4 vector4 = !((UnityEngine.Object) this.overrideSprite != (UnityEngine.Object) null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite); UIVertex.simpleVert.color = (Color32) this.color; float num1 = vector4.x; float num2 = vector4.y; float num3 = vector4.z; float num4 = vector4.w; if (this.m_FillMethod == Image.FillMethod.Horizontal || this.m_FillMethod == Image.FillMethod.Vertical) { if (this.fillMethod == Image.FillMethod.Horizontal) { float num5 = (num3 - num1) * this.m_FillAmount; if (this.m_FillOrigin == 1) { drawingDimensions.x = drawingDimensions.z - (drawingDimensions.z - drawingDimensions.x) * this.m_FillAmount; num1 = num3 - num5; } else { drawingDimensions.z = drawingDimensions.x + (drawingDimensions.z - drawingDimensions.x) * this.m_FillAmount; num3 = num1 + num5; } } else if (this.fillMethod == Image.FillMethod.Vertical) { float num5 = (num4 - num2) * this.m_FillAmount; if (this.m_FillOrigin == 1) { drawingDimensions.y = drawingDimensions.w - (drawingDimensions.w - drawingDimensions.y) * this.m_FillAmount; num2 = num4 - num5; } else { drawingDimensions.w = drawingDimensions.y + (drawingDimensions.w - drawingDimensions.y) * this.m_FillAmount; num4 = num2 + num5; } } } Image.s_Xy[0] = (Vector3) new Vector2(drawingDimensions.x, drawingDimensions.y); Image.s_Xy[1] = (Vector3) new Vector2(drawingDimensions.x, drawingDimensions.w); Image.s_Xy[2] = (Vector3) new Vector2(drawingDimensions.z, drawingDimensions.w); Image.s_Xy[3] = (Vector3) new Vector2(drawingDimensions.z, drawingDimensions.y); Image.s_Uv[0] = (Vector3) new Vector2(num1, num2); Image.s_Uv[1] = (Vector3) new Vector2(num1, num4); Image.s_Uv[2] = (Vector3) new Vector2(num3, num4); Image.s_Uv[3] = (Vector3) new Vector2(num3, num2); if ((double) this.m_FillAmount < 1.0 && this.m_FillMethod != Image.FillMethod.Horizontal && this.m_FillMethod != Image.FillMethod.Vertical) { if (this.fillMethod == Image.FillMethod.Radial90) { if (!Image.RadialCut(Image.s_Xy, Image.s_Uv, this.m_FillAmount, this.m_FillClockwise, this.m_FillOrigin)) return; Image.AddQuad(toFill, Image.s_Xy, (Color32) this.color, Image.s_Uv); } else if (this.fillMethod == Image.FillMethod.Radial180) { for (int index = 0; index < 2; ++index) { int num5 = this.m_FillOrigin <= 1 ? 0 : 1; float t1; float t2; float t3; float t4; if (this.m_FillOrigin == 0 || this.m_FillOrigin == 2) { t1 = 0.0f; t2 = 1f; if (index == num5) { t3 = 0.0f; t4 = 0.5f; } else { t3 = 0.5f; t4 = 1f; } } else { t3 = 0.0f; t4 = 1f; if (index == num5) { t1 = 0.5f; t2 = 1f; } else { t1 = 0.0f; t2 = 0.5f; } } Image.s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t3); Image.s_Xy[1].x = Image.s_Xy[0].x; Image.s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t4); Image.s_Xy[3].x = Image.s_Xy[2].x; Image.s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t1); Image.s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t2); Image.s_Xy[2].y = Image.s_Xy[1].y; Image.s_Xy[3].y = Image.s_Xy[0].y; Image.s_Uv[0].x = Mathf.Lerp(num1, num3, t3); Image.s_Uv[1].x = Image.s_Uv[0].x; Image.s_Uv[2].x = Mathf.Lerp(num1, num3, t4); Image.s_Uv[3].x = Image.s_Uv[2].x; Image.s_Uv[0].y = Mathf.Lerp(num2, num4, t1); Image.s_Uv[1].y = Mathf.Lerp(num2, num4, t2); Image.s_Uv[2].y = Image.s_Uv[1].y; Image.s_Uv[3].y = Image.s_Uv[0].y; float num6 = !this.m_FillClockwise ? this.m_FillAmount * 2f - (float) (1 - index) : this.fillAmount * 2f - (float) index; if (Image.RadialCut(Image.s_Xy, Image.s_Uv, Mathf.Clamp01(num6), this.m_FillClockwise, (index + this.m_FillOrigin + 3) % 4)) Image.AddQuad(toFill, Image.s_Xy, (Color32) this.color, Image.s_Uv); } } else { if (this.fillMethod != Image.FillMethod.Radial360) return; for (int index = 0; index < 4; ++index) { float t1; float t2; if (index < 2) { t1 = 0.0f; t2 = 0.5f; } else { t1 = 0.5f; t2 = 1f; } float t3; float t4; if (index == 0 || index == 3) { t3 = 0.0f; t4 = 0.5f; } else { t3 = 0.5f; t4 = 1f; } Image.s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t1); Image.s_Xy[1].x = Image.s_Xy[0].x; Image.s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t2); Image.s_Xy[3].x = Image.s_Xy[2].x; Image.s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t3); Image.s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t4); Image.s_Xy[2].y = Image.s_Xy[1].y; Image.s_Xy[3].y = Image.s_Xy[0].y; Image.s_Uv[0].x = Mathf.Lerp(num1, num3, t1); Image.s_Uv[1].x = Image.s_Uv[0].x; Image.s_Uv[2].x = Mathf.Lerp(num1, num3, t2); Image.s_Uv[3].x = Image.s_Uv[2].x; Image.s_Uv[0].y = Mathf.Lerp(num2, num4, t3); Image.s_Uv[1].y = Mathf.Lerp(num2, num4, t4); Image.s_Uv[2].y = Image.s_Uv[1].y; Image.s_Uv[3].y = Image.s_Uv[0].y; float num5 = !this.m_FillClockwise ? this.m_FillAmount * 4f - (float) (3 - (index + this.m_FillOrigin) % 4) : this.m_FillAmount * 4f - (float) ((index + this.m_FillOrigin) % 4); if (Image.RadialCut(Image.s_Xy, Image.s_Uv, Mathf.Clamp01(num5), this.m_FillClockwise, (index + 2) % 4)) Image.AddQuad(toFill, Image.s_Xy, (Color32) this.color, Image.s_Uv); } } } else Image.AddQuad(toFill, Image.s_Xy, (Color32) this.color, Image.s_Uv); }
protected override void OnPopulateMesh(UnityEngine.UI.VertexHelper vh) { vh.Clear(); }
protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear(); }