Exemplo n.º 1
0
        //private void ResetData()
        //{
        //    if (m_mesh && false)
        //    {
        //        Debug.Log("Drawing Mesh");
        //        var cr = GetComponent<CanvasRenderer>();
        //        cr.SetMesh(m_mesh);
        //        if (m_materials != null && m_materials.Count > 0)
        //        {
        //            Debug.Log("Adding Materials");
        //            cr.materialCount = m_materials.Count;

        //            for (int i = 0; i < m_materials.Count; i++)
        //                cr.SetMaterial(m_materials[i], i);
        //        }
        //    }
        //}

        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Debug.Log("Populate Mesh Data");
            vh.Clear();
            vh.FillMesh(m_mesh);
            base.OnPopulateMesh(vh);
        }
Exemplo n.º 2
0
        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
                    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);
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
			vh.Clear();

			if (Points.Length < 2)
				return;

            var sizeX = rectTransform.rect.width;
            var sizeY = rectTransform.rect.height;
            var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
            var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;

			var sizeVector = new Vector2(sizeX, sizeY);
			var offsetVector = new Vector2(offsetX, offsetY);

			for (var i = 0; i < Points.Length - 1; i++)
			{
				var current = new Vector2(Points[i].x * sizeVector.x, Points[i].y * sizeVector.y) + offsetVector;
				var next = new Vector2(Points[i + 1].x * sizeVector.x, Points[i + 1].y * sizeVector.y) + offsetVector;

				var line = next - current;
				var normalized = line.normalized;
				var up = normalized.Rotate(-90) * LineThickness / 2;

				var vertices = new Vector2[4];
				vertices[0] = current + up;
				vertices[1] = next + up;
				vertices[2] = next - up;
				vertices[3] = current - up;

				var uvs = new Vector2[4] { Vector2.zero, new Vector2(1, 0), Vector2.one, new Vector2(0, 1) };
				vh.AddUIVertexQuad(CreateUIVertexQuad(vertices, uvs));
			}
        }
Exemplo n.º 4
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            var r = GetPixelAdjustedRect();
            var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);
            float dif = (v.w - v.y) * 2;
            Color32 color32 = color;
            vh.Clear();

            color32.a = (byte)0;
            vh.AddVert(new Vector3(v.x - 50, width * v.y + yoffset * dif), color32, new Vector2(0f, 0f));
            vh.AddVert(new Vector3(v.z + 50, width * v.y + yoffset * dif), color32, new Vector2(1f, 0f));

            color32.a = (byte)(color.a * 255);
            vh.AddVert(new Vector3(v.x - 50, width * (v.y / 4) + yoffset * dif), color32, new Vector2(0f, 1f));
            vh.AddVert(new Vector3(v.z + 50, width * (v.y / 4) + yoffset * dif), color32, new Vector2(1f, 1f));

            color32.a = (byte)(color.a * 255);
            vh.AddVert(new Vector3(v.x - 50, width * (v.w / 4) + yoffset * dif), color32, new Vector2(0f, 1f));
            vh.AddVert(new Vector3(v.z + 50, width * (v.w / 4) + yoffset * dif), color32, new Vector2(1f, 1f));
            color32.a = (byte)(color.a * 255);

            color32.a = (byte)0;
            vh.AddVert(new Vector3(v.x - 50, width * v.w + yoffset * dif), color32, new Vector2(0f, 1f));
            vh.AddVert(new Vector3(v.z + 50, width * v.w + yoffset * dif), color32, new Vector2(1f, 1f));

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 1);

            vh.AddTriangle(2, 3, 4);
            vh.AddTriangle(4, 5, 3);

            vh.AddTriangle(4, 5, 6);
            vh.AddTriangle(6, 7, 5);
        }
Exemplo n.º 5
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            float outer = -rectTransform.pivot.x * rectTransform.rect.width;
            float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thickness;

            toFill.Clear();
            var vbo = new VertexHelper(toFill);

            Vector2 prevX = Vector2.zero;
            Vector2 prevY = Vector2.zero;
            Vector2 uv0 = new Vector2(0, 0);
            Vector2 uv1 = new Vector2(0, 1);
            Vector2 uv2 = new Vector2(1, 1);
            Vector2 uv3 = new Vector2(1, 0);
            Vector2 pos0;
            Vector2 pos1;
            Vector2 pos2;
            Vector2 pos3;

            float f = (this.fillPercent / 100f);
            float degrees = 360f / segments;
            int fa = (int)((segments + 1) * f);

            for (int i = 0; i < fa; i++)
            {
                float rad = Mathf.Deg2Rad * (i * degrees);
                float c = Mathf.Cos(rad);
                float s = Mathf.Sin(rad);

                uv0 = new Vector2(0, 1);
                uv1 = new Vector2(1, 1);
                uv2 = new Vector2(1, 0);
                uv3 = new Vector2(0, 0);

                pos0 = prevX;
                pos1 = new Vector2(outer * c, outer * s);

                if (fill)
                {
                    pos2 = Vector2.zero;
                    pos3 = Vector2.zero;
                }
                else
                {
                    pos2 = new Vector2(inner * c, inner * s);
                    pos3 = prevY;
                }

                prevX = pos1;
                prevY = pos2;

                vbo.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));

            }

            if (vbo.currentVertCount > 3)
            {
                vbo.FillMesh(toFill);
            }
        }
Exemplo n.º 6
0
 public void Triangulate(VertexHelper vh)
 {
     int triangleCount = vh.currentVertCount - 2;
     Debug.Log(triangleCount);
     for (int i = 0; i <= triangleCount / 2 + 1; i += 2)
     {
         vh.AddTriangle(i, i + 1, i + 2);
         vh.AddTriangle(i + 2, i + 3, i + 1);
     }
 }
Exemplo n.º 7
0
 public override void ModifyMesh(VertexHelper vh)
 {
   UIVertex vertex = new UIVertex();
   for (int i = 0; i < vh.currentVertCount; ++i)
   {
     vh.PopulateUIVertex(ref vertex, i);
     vertex.uv1 = new Vector2(vertex.position.x, vertex.position.y);
     vh.SetUIVertex(vertex, i);
   }
 }
Exemplo n.º 8
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();

            Vector2 prevX = Vector2.zero;
            Vector2 prevY = Vector2.zero;
            Vector2 uv0 = new Vector2(0, 0);
            Vector2 uv1 = new Vector2(0, 1);
            Vector2 uv2 = new Vector2(1, 1);
            Vector2 uv3 = new Vector2(1, 0);
            Vector2 pos0;
            Vector2 pos1;
            Vector2 pos2;
            Vector2 pos3;
            float degrees = 360f / sides;
            int vertices = sides + 1;
            if (VerticesDistances.Length != vertices)
            {
                VerticesDistances = new float[vertices];
                for (int i = 0; i < vertices - 1; i++) VerticesDistances[i] = 1;
            }
            // last vertex is also the first!
            VerticesDistances[vertices - 1] = VerticesDistances[0];
            for (int i = 0; i < vertices; i++)
            {
                float outer = -rectTransform.pivot.x * size * VerticesDistances[i];
                float inner = -rectTransform.pivot.x * size * VerticesDistances[i] + thickness;
                float rad = Mathf.Deg2Rad * (i * degrees + rotation);
                float c = Mathf.Cos(rad);
                float s = Mathf.Sin(rad);
                uv0 = new Vector2(0, 1);
                uv1 = new Vector2(1, 1);
                uv2 = new Vector2(1, 0);
                uv3 = new Vector2(0, 0);
                pos0 = prevX;
                pos1 = new Vector2(outer * c, outer * s);
                if (fill)
                {
                    pos2 = Vector2.zero;
                    pos3 = Vector2.zero;
                }
                else
                {
                    pos2 = new Vector2(inner * c, inner * s);
                    pos3 = prevY;
                }
                prevX = pos1;
                prevY = pos2;
                vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
            }
        }
Exemplo n.º 9
0
 public override void ModifyMesh(VertexHelper vh)
 {
     int count = vh.currentVertCount;
     if (!IsActive() || count == 0)
     {
         return;
     }
     for (int index = 0; index < vh.currentVertCount; index++)
     {
         UIVertex uiVertex = new UIVertex();
         vh.PopulateUIVertex(ref uiVertex, index);
         uiVertex.position.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.position.x) * curveMultiplier;
         vh.SetUIVertex(uiVertex, index);
     }
 }
Exemplo n.º 10
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();
            float wHalf = rectTransform.rect.width / 2;
            //float hHalf = rectTransform.rect.height / 2;
            a = Math.Min(1, Math.Max(0, a));
            b = Math.Min(1, Math.Max(0, b));
            c = Math.Min(1, Math.Max(0, c));
            d = Math.Min(1, Math.Max(0, d));

            Color32 color32 = color;
            vh.AddVert(new Vector3(-wHalf * a, 0), color32, new Vector2(0f, 0f));
            vh.AddVert(new Vector3(0, wHalf * b), color32, new Vector2(0f, 1f));
            vh.AddVert(new Vector3(wHalf * c, 0), color32, new Vector2(1f, 1f));
            vh.AddVert(new Vector3(0, -wHalf * d), color32, new Vector2(1f, 0f));

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
Exemplo n.º 11
0
        public void ModifyMesh(VertexHelper verts)
        {
            RectTransform rt = this.transform as RectTransform;
         
            for (int i = 0; i < verts.currentVertCount; ++i)
            {
                UIVertex uiVertex = new UIVertex();
                verts.PopulateUIVertex(ref uiVertex,i);

                // Modify positions
                uiVertex.position = new Vector3(
                    (this.m_Horizontal ? (uiVertex.position.x + (rt.rect.center.x - uiVertex.position.x) * 2) : uiVertex.position.x),
                    (this.m_Veritical ?  (uiVertex.position.y + (rt.rect.center.y - uiVertex.position.y) * 2) : uiVertex.position.y),
                    uiVertex.position.z
                );

                // Apply
                verts.SetUIVertex(uiVertex, i);
            }
        }
Exemplo n.º 12
0
		//
		// Methods
		//
		public override void ModifyMesh (Mesh mesh)
		{
			if (!this.IsActive ())
			{
				return;
			}

            List<UIVertex> verts = new List<UIVertex>();
            using (var helper = new VertexHelper(mesh))
            {
                helper.GetUIVertexStream(verts);
            }

            Text foundtext = GetComponent<Text>();

			float best_fit_adjustment = 1f;

			if (foundtext && foundtext.resizeTextForBestFit)  
			{
				best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive 
			}
			
			int start = 0;
			int count = verts.Count;
			base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
			start = count;
			count = verts.Count;
			base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
			start = count;
			count = verts.Count;
			base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
			start = count;
			count = verts.Count;
			base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);

            using (var helper = new VertexHelper())
            {
                helper.AddUIVertexTriangleStream(verts);
                helper.FillMesh(mesh);
            }
        }
Exemplo n.º 13
0
		public override void ModifyMesh(VertexHelper vh)
		{
			int count = vh.currentVertCount;
			if (!IsActive() || count == 0)
			{
				return;
			}

			var k = 0;
			var upCount = 0;
			float progressMax = vh.currentVertCount * 0.5f;
			for (int index = 0; index < vh.currentVertCount; ++index) {

				UIVertex uiVertex = new UIVertex();
				vh.PopulateUIVertex(ref uiVertex, index);

				if (k < 2) {

					var progress = upCount++ - progressMax * 0.5f;
					uiVertex.position.y += curveForTextUpper.Evaluate((rectTrans.rect.width * rectTrans.pivot.x + uiVertex.position.x) / rectTrans.rect.width) * curveMultiplierUpper;
					uiVertex.position.x += progress * curveMultiplierX;

				} else if (k < 4) {

					uiVertex.position.y += curveForText.Evaluate((rectTrans.rect.width * rectTrans.pivot.x + uiVertex.position.x) / rectTrans.rect.width) * curveMultiplier;

				}

				++k;

				if (k >= 4) k = 0;

				vh.SetUIVertex(uiVertex, index);

			}

		}
Exemplo n.º 14
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (! IsActive()) return;

            int count = vh.currentVertCount;
            if (!IsActive() || count == 0)
            {
                return;
            }
            for (int index = 0; index < vh.currentVertCount; index++)
            {
                UIVertex uiVertex = new UIVertex();
                vh.PopulateUIVertex(ref uiVertex, index);

                // get x position
                var x = uiVertex.position.x;                

                // calculate bend based on pivot and radius
                uiVertex.position.z = -radius * Mathf.Cos(x / radius);
                uiVertex.position.x = radius * Mathf.Sin(x / radius);
                
                vh.SetUIVertex(uiVertex, index);
            }
        }
Exemplo n.º 15
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        float minX = (0f - rectTransform.pivot.x) * rectTransform.rect.width;
        float minY = (0f - rectTransform.pivot.y) * rectTransform.rect.height;
        float maxX = (1f - rectTransform.pivot.x) * rectTransform.rect.width;
        float maxY = (1f - rectTransform.pivot.y) * rectTransform.rect.height;

        var color32 = (Color32)color;

        if (xSize < 1)
        {
            xSize = 1;
        }
        if (ySize < 1)
        {
            ySize = 1;
        }

        vh.Clear();

        if (isInitVertices && vertices.Length != (xSize + 1) * (ySize + 1))
        {
            isInitVertices = false;
        }

        if (!isInitVertices)
        {
            verticesRun = new Vector3[(xSize + 1) * (ySize + 1)];
            vertices    = new Vector2[(xSize + 1) * (ySize + 1)];
        }

        Vector2[] uv       = new Vector2[vertices.Length];
        Vector4[] tangents = new Vector4[vertices.Length];
        Vector4   tangent  = new Vector4(1f, 0f, 0f, -1f);

        for (int i = 0, y = 0; y <= ySize; y++)
        {
            for (int x = 0; x <= xSize; x++, i++)
            {
                float xTime = CurveX.Evaluate(AddedTime + (1.0f / (float)xSize) * (float)x) - 1.0f;
                float yTime = CurveY.Evaluate(AddedTime + (1.0f / (float)ySize) * (float)y) - 1.0f;

                float yTimeNoise = 0.0f;
                float xTimeNoise = 0.0f;
                if (isEnablePerlinNoise)
                {
                    yTimeNoise = Mathf.PerlinNoise(Time.time * (float)x, 0) * ForcePerlinNoise;
                    xTimeNoise = Mathf.PerlinNoise(0, Time.time * (float)y) * ForcePerlinNoise;
                }

                xTime = xTime * ForceCurve;
                yTime = yTime * ForceCurve;

                if (!isInitVertices)
                {
                    vertices[i] = new Vector2((float)x, (float)y);
                }
                uv[i]       = new Vector2((float)x / xSize, (float)y / ySize);
                tangents[i] = tangent;


                verticesRun[i] = new Vector2((minX + ((vertices[i].x + yTime + yTimeNoise) * ((maxX - minX) / xSize))), (minY + ((vertices[i].y + xTime + xTimeNoise) * ((maxY - minY) / ySize))));
                vh.AddVert(new Vector3((minX + ((vertices[i].x + yTime + yTimeNoise) * ((maxX - minX) / xSize))), (minY + ((vertices[i].y + xTime + xTimeNoise) * ((maxY - minY) / ySize)))), color32, new Vector2(uv[i].x, uv[i].y));
            }
        }

        int[] triangles = new int[xSize * ySize * 6];
        for (int ti = 0, vi = 0, y = 0; y < ySize; y++, vi++)
        {
            for (int x = 0; x < xSize; x++, ti += 6, vi++)
            {
                triangles[ti]     = vi;
                triangles[ti + 3] = triangles[ti + 2] = vi + 1;
                triangles[ti + 4] = triangles[ti + 1] = vi + xSize + 1;
                triangles[ti + 5] = vi + xSize + 2;
                vh.AddTriangle(triangles[ti], triangles[ti + 1], triangles[ti + 2]);
                vh.AddTriangle(triangles[ti + 3], triangles[ti + 4], triangles[ti + 5]);
            }
        }
        isInitVertices = true;
    }
Exemplo n.º 16
0
        /// <summary>
        /// Update the UI renderer mesh.
        /// </summary>

        protected override void OnPopulateMesh(VertexHelper vh)
        {
            List<UIVertex> vbo = new List<UIVertex>();
            vh.GetUIVertexStream(vbo);

            switch (type)
            {
                case Type.Simple:
                    GenerateSimpleSprite(vbo, m_PreserveAspect);
                    break;
                case Type.Sliced:
                    GenerateSlicedSprite(vbo);
                    break;
                case Type.Tiled:
                    GenerateTiledSprite(vbo);
                    break;
                case Type.Filled:
                    GenerateFilledSprite(vbo, m_PreserveAspect);
                    break;
            }
            vh.Clear();
            vh.AddUIVertexTriangleStream(vbo);
        }
Exemplo n.º 17
0
 protected virtual void ProcessCharactersAtLine(VertexHelper vh, int lineIndex, int startCharIdx, int endCharIdx, IList <UILineInfo> lines, IList <UICharInfo> chars)
 {
 }
Exemplo n.º 18
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        // Debug.Log("OnPopulateMesh called");
        vh.Clear();

        IPointsOnCurveProvider pointsProvider =
            GetComponentInParent <IPointsOnCurveProvider>();

        if (pointsProvider == null)
        {
            return;
        }
        IList <Vector2> pointsOnCurve = pointsProvider
                                        .GetPointsOnCurve();

        if (pointsOnCurve == null ||
            pointsOnCurve.Count == 0)
        {
            return;
        }
        float curveWidth     = rectTransform.rect.height;
        float halfCurveWidth = curveWidth * 0.5f;

        // Add 2 points before the curve.
        Vector2 forward = (pointsOnCurve[1] -
                           pointsOnCurve[0]).normalized;
        Vector2  left = new Vector2(-forward.y, forward.x);
        UIVertex vert = UIVertex.simpleVert;

        vert.position = pointsOnCurve[0]
                        - halfCurveWidth * forward
                        + halfCurveWidth * left;
        vert.color = color;
        vert.uv0   = new Vector2(0f, 1f);
        vh.AddVert(vert);

        vert.position = pointsOnCurve[0]
                        - halfCurveWidth * forward
                        - halfCurveWidth * left;
        vert.color = color;
        vert.uv0   = new Vector2(0f, 0f);
        vh.AddVert(vert);

        // Calculate left vector on each point. Then generate
        // vertices.
        for (int i = 0; i < pointsOnCurve.Count; i++)
        {
            forward = Vector2.zero;
            if (i < pointsOnCurve.Count - 1)
            {
                forward += (pointsOnCurve[i + 1] -
                            pointsOnCurve[i]).normalized;
            }
            if (i > 0)
            {
                forward += (pointsOnCurve[i] -
                            pointsOnCurve[i - 1]).normalized;
            }
            forward.Normalize();
            left = new Vector2(-forward.y, forward.x);

            float u = (float)i / (pointsOnCurve.Count - 1);
            u = u * 0.5f + 0.25f;

            vert.position = pointsOnCurve[i] +
                            halfCurveWidth * left;
            vert.color = color;
            vert.uv0   = new Vector2(u, 1f);
            vh.AddVert(vert);

            vert.position = pointsOnCurve[i] -
                            halfCurveWidth * left;
            vert.color = color;
            vert.uv0   = new Vector2(u, 0f);
            vh.AddVert(vert);
        }

        // Add 2 points after the curve.
        forward = (pointsOnCurve[pointsOnCurve.Count - 1] -
                   pointsOnCurve[pointsOnCurve.Count - 2]).normalized;
        left          = new Vector2(-forward.y, forward.x);
        vert.position = pointsOnCurve[pointsOnCurve.Count - 1]
                        + halfCurveWidth * forward
                        + halfCurveWidth * left;
        vert.color = color;
        vert.uv0   = new Vector2(1f, 1f);
        vh.AddVert(vert);

        vert.position = pointsOnCurve[pointsOnCurve.Count - 1]
                        + halfCurveWidth * forward
                        - halfCurveWidth * left;
        vert.color = color;
        vert.uv0   = new Vector2(1f, 0f);
        vh.AddVert(vert);

        // Triangles.
        for (int i = 0; i < pointsOnCurve.Count + 1; i++)
        {
            // #2i: left
            // #2i+1: right
            // #2i+2: next left
            // #2i+3: next right
            vh.AddTriangle(2 * i + 1, 2 * i, 2 * i + 2);
            vh.AddTriangle(2 * i + 3, 2 * i + 1, 2 * i + 2);
        }
    }
Exemplo n.º 19
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!this.IsActive ())
			{
				return;
			}
            List < UIVertex > verts = new List<UIVertex>();
            vh.GetUIVertexStream(verts);

            Text foundtext = GetComponent<Text>();
			
			float best_fit_adjustment = 1f;
			
			if (foundtext && foundtext.resizeTextForBestFit)  
			{
				best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive 

			}

			float distanceX = this.effectDistance.x * best_fit_adjustment;
			float distanceY = this.effectDistance.y * best_fit_adjustment;

			int start = 0;
			int count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, distanceY);
			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, -distanceY);
			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, distanceY);
			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, -distanceY);

			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, 0);
			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, 0);

			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, distanceY);
			start = count;
			count = verts.Count;
			this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY);

            vh.Clear();
            vh.AddUIVertexTriangleStream(verts);
        }
Exemplo n.º 20
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (m_points == null)
                return;
            Vector2[] pointsToDraw = m_points;
            //If Bezier is desired, pick the implementation
            if (BezierMode != BezierType.None && m_points.Length > 3)
            {
                BezierPath bezierPath = new BezierPath();

                bezierPath.SetControlPoints(pointsToDraw);
                bezierPath.SegmentsPerCurve = BezierSegmentsPerCurve;
                List<Vector2> drawingPoints;
                switch (BezierMode)
                {
                    case BezierType.Basic:
                        drawingPoints = bezierPath.GetDrawingPoints0();
                        break;
                    case BezierType.Improved:
                        drawingPoints = bezierPath.GetDrawingPoints1();
                        break;
                    default:
                        drawingPoints = bezierPath.GetDrawingPoints2();
                        break;
                }
                pointsToDraw = drawingPoints.ToArray();
            }

            var sizeX = rectTransform.rect.width;
            var sizeY = rectTransform.rect.height;
            var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
            var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;

            // don't want to scale based on the size of the rect, so this is switchable now
            if (!relativeSize)
            {
                sizeX = 1;
                sizeY = 1;
            }

            if (UseMargins)
            {
                sizeX -= Margin.x;
                sizeY -= Margin.y;
                offsetX += Margin.x / 2f;
                offsetY += Margin.y / 2f;
            }

            vh.Clear();

            // Generate the quads that make up the wide line
            var segments = new List<UIVertex[]>();
            if (LineList)
            {
                for (var i = 1; i < pointsToDraw.Length; i += 2)
                {
                    var start = pointsToDraw[i - 1];
                    var end = pointsToDraw[i];
                    start = new Vector2(start.x * sizeX + offsetX, start.y * sizeY + offsetY);
                    end = new Vector2(end.x * sizeX + offsetX, end.y * sizeY + offsetY);

                    if (LineCaps)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.Start));
                    }

                    segments.Add(CreateLineSegment(start, end, SegmentType.Middle));

                    if (LineCaps)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.End));
                    }
                }
            }
            else
            {
                for (var i = 1; i < pointsToDraw.Length; i++)
                {
                    var start = pointsToDraw[i - 1];
                    var end = pointsToDraw[i];
                    start = new Vector2(start.x * sizeX + offsetX, start.y * sizeY + offsetY);
                    end = new Vector2(end.x * sizeX + offsetX, end.y * sizeY + offsetY);

                    if (LineCaps && i == 1)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.Start));
                    }

                    segments.Add(CreateLineSegment(start, end, SegmentType.Middle));

                    if (LineCaps && i == pointsToDraw.Length - 1)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.End));
                    }
                }
            }

            // Add the line segments to the vertex helper, creating any joins as needed
            for (var i = 0; i < segments.Count; i++)
            {
                if (!LineList && i < segments.Count - 1)
                {
                    var vec1 = segments[i][1].position - segments[i][2].position;
                    var vec2 = segments[i + 1][2].position - segments[i + 1][1].position;
                    var angle = Vector2.Angle(vec1, vec2) * Mathf.Deg2Rad;

                    // Positive sign means the line is turning in a 'clockwise' direction
                    var sign = Mathf.Sign(Vector3.Cross(vec1.normalized, vec2.normalized).z);

                    // Calculate the miter point
                    var miterDistance = LineThickness / (2 * Mathf.Tan(angle / 2));
                    var miterPointA = segments[i][2].position - vec1.normalized * miterDistance * sign;
                    var miterPointB = segments[i][3].position + vec1.normalized * miterDistance * sign;

                    var joinType = LineJoins;
                    if (joinType == JoinType.Miter)
                    {
                        // Make sure we can make a miter join without too many artifacts.
                        if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_MITER_JOIN)
                        {
                            segments[i][2].position = miterPointA;
                            segments[i][3].position = miterPointB;
                            segments[i + 1][0].position = miterPointB;
                            segments[i + 1][1].position = miterPointA;
                        }
                        else
                        {
                            joinType = JoinType.Bevel;
                        }
                    }

                    if (joinType == JoinType.Bevel)
                    {
                        if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_BEVEL_NICE_JOIN)
                        {
                            if (sign < 0)
                            {
                                segments[i][2].position = miterPointA;
                                segments[i + 1][1].position = miterPointA;
                            }
                            else
                            {
                                segments[i][3].position = miterPointB;
                                segments[i + 1][0].position = miterPointB;
                            }
                        }

                        var join = new UIVertex[] { segments[i][2], segments[i][3], segments[i + 1][0], segments[i + 1][1] };
                        vh.AddUIVertexQuad(join);
                    }
                }
                vh.AddUIVertexQuad(segments[i]);
            }
        }
Exemplo n.º 21
0
 public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
                               float smoothness = 2f)
 {
     DrawSector(vh, p, radius, color, 0, 360, smoothness);
 }
Exemplo n.º 22
0
    void GenerateFilledSprite(VertexHelper toFill, bool preserveAspect)
    {
        toFill.Clear();

        if (fillAmount < 0.001f)
        {
            return;
        }

        Vector4 v     = GetDrawingDimensions(preserveAspect);
        Vector4 outer = activeSprite != null?UnityEngine.Sprites.DataUtility.GetOuterUV(activeSprite) : 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 (fillMethod == FillMethod.Horizontal || fillMethod == FillMethod.Vertical)
        {
            if (fillMethod == FillMethod.Horizontal)
            {
                float fill = (tx1 - tx0) * fillAmount;

                if (fillOrigin == 1)
                {
                    v.x = v.z - (v.z - v.x) * fillAmount;
                    tx0 = tx1 - fill;
                }
                else
                {
                    v.z = v.x + (v.z - v.x) * fillAmount;
                    tx1 = tx0 + fill;
                }
            }
            else if (fillMethod == FillMethod.Vertical)
            {
                float fill = (ty1 - ty0) * fillAmount;

                if (fillOrigin == 1)
                {
                    v.y = v.w - (v.w - v.y) * fillAmount;
                    ty0 = ty1 - fill;
                }
                else
                {
                    v.w = v.y + (v.w - v.y) * 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 (fillAmount < 1f && fillMethod != FillMethod.Horizontal && fillMethod != FillMethod.Vertical)
            {
                if (fillMethod == FillMethod.Radial90)
                {
                    if (RadialCut(s_Xy, s_Uv, fillAmount, fillClockwise, 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 = fillOrigin > 1 ? 1 : 0;

                        if (fillOrigin == 0 || 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 = fillClockwise ? fillAmount * 2f - side : fillAmount * 2f - (1 - side);

                        if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(val), fillClockwise, ((side + 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 = fillClockwise ?
                                    fillAmount * 4f - ((corner + fillOrigin) % 4) :
                                    fillAmount * 4f - (3 - ((corner + fillOrigin) % 4));

                        if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(val), fillClockwise, ((corner + 2) % 4)))
                        {
                            AddQuad(toFill, s_Xy, color, s_Uv);
                        }
                    }
                }
            }
            else
            {
                AddQuad(toFill, s_Xy, color, s_Uv);
            }
        }
    }
Exemplo n.º 23
0
    /// <summary>
    /// 生成Tiled模式Sprite
    /// </summary>
    void GenerateTiledSprite(VertexHelper toFill)
    {
        Vector4 outer, inner, border;
        Vector2 spriteSize;

        Sprite  overrideSprite = this.overrideSprite;
        Color32 color          = this.color;

        if (overrideSprite != null)
        {
            outer      = DataUtility.GetOuterUV(overrideSprite);
            inner      = 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 (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)
        {
            // Left and right tiled border
            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));
        }
    }
Exemplo n.º 24
0
    private void GenerateSlicedSprite(VertexHelper toFill)
    {
        //如果没有边框则跟普通精灵顶点三角形是一样的
        if (!hasBorder)
        {
            GenerateSimpleSprite(toFill, false);
            return;
        }

        Vector4 outer, inner, padding, border;

        if (activeSprite != null)
        {
            outer   = DataUtility.GetOuterUV(activeSprite);
            inner   = DataUtility.GetInnerUV(activeSprite);
            padding = DataUtility.GetPadding(activeSprite);
            border  = activeSprite.border;
        }
        else
        {
            outer   = Vector4.zero;
            inner   = Vector4.zero;
            padding = Vector4.zero;
            border  = Vector4.zero;
        }

        Rect rect = GetPixelAdjustedRect();
        //调整后的边框大小
        Vector4 adjustedBorders = 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 = adjustedBorders.x;
        s_VertScratch[1].y = adjustedBorders.y;

        s_VertScratch[2].x = rect.width - adjustedBorders.z;
        s_VertScratch[2].y = rect.height - adjustedBorders.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();
        //生成9个矩形区域
        for (int x = 0; x < 3; ++x)
        {
            int x2 = x + 1;

            for (int y = 0; y < 3; ++y)
            {
                if (!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));
            }
        }
    }
Exemplo n.º 25
0
 protected override void OnPopulateMesh(VertexHelper toFill)
 {
     base.OnPopulateMesh(toFill);
     StartCoroutine(MClearUpExplainMode(this, text));
 }
Exemplo n.º 26
0
 static public void SetUIVertexPosition(VertexHelper vh, int index, Vector3 position)
 {
     vh.PopulateUIVertex(ref s_TempUIVertex, index);
     s_TempUIVertex.position = position;
     vh.SetUIVertex(s_TempUIVertex, index);
 }
Exemplo n.º 27
0
 static public void SetUIVertexColorAlpha(VertexHelper vh, int index, byte alpha)
 {
     vh.PopulateUIVertex(ref s_TempUIVertex, index);
     s_TempUIVertex.color.a = alpha;
     vh.SetUIVertex(s_TempUIVertex, index);
 }
Exemplo n.º 28
0
 static public void SetUIVertexColor(VertexHelper vh, int index, Color color)
 {
     vh.PopulateUIVertex(ref s_TempUIVertex, index);
     s_TempUIVertex.color = color;
     vh.SetUIVertex(s_TempUIVertex, index);
 }
        protected override void OnPopulateMesh(Mesh toFill)
        {
            // requires sets of quads
            if (Points == null || Points.Length < 2)
                Points = new[] { new Vector2(0, 0), new Vector2(1, 1) };
            var capSize = 24;
            var sizeX = rectTransform.rect.width;
            var sizeY = rectTransform.rect.height;
            var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
            var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;

            // don't want to scale based on the size of the rect, so this is switchable now
            if (!relativeSize)
            {
                sizeX = 1;
                sizeY = 1;
            }
            // build a new set of points taking into account the cap sizes.
            // would be cool to support corners too, but that might be a bit tough :)
            var pointList = new List<Vector2>();
            pointList.Add(Points[0]);
            var capPoint = Points[0] + (Points[1] - Points[0]).normalized * capSize;
            pointList.Add(capPoint);

            // should bail before the last point to add another cap point
            for (int i = 1; i < Points.Length - 1; i++)
            {
                pointList.Add(Points[i]);
            }
            capPoint = Points[Points.Length - 1] - (Points[Points.Length - 1] - Points[Points.Length - 2]).normalized * capSize;
            pointList.Add(capPoint);
            pointList.Add(Points[Points.Length - 1]);

            var TempPoints = pointList.ToArray();
            if (UseMargins)
            {
                sizeX -= Margin.x;
                sizeY -= Margin.y;
                offsetX += Margin.x / 2f;
                offsetY += Margin.y / 2f;
            }

            toFill.Clear();
            var vbo = new VertexHelper(toFill);

            Vector2 prevV1 = Vector2.zero;
            Vector2 prevV2 = Vector2.zero;

            for (int i = 1; i < TempPoints.Length; i++)
            {
                var prev = TempPoints[i - 1];
                var cur = TempPoints[i];
                prev = new Vector2(prev.x * sizeX + offsetX, prev.y * sizeY + offsetY);
                cur = new Vector2(cur.x * sizeX + offsetX, cur.y * sizeY + offsetY);

                float angle = Mathf.Atan2(cur.y - prev.y, cur.x - prev.x) * 180f / Mathf.PI;

                var v1 = prev + new Vector2(0, -LineThickness / 2);
                var v2 = prev + new Vector2(0, +LineThickness / 2);
                var v3 = cur + new Vector2(0, +LineThickness / 2);
                var v4 = cur + new Vector2(0, -LineThickness / 2);

                v1 = RotatePointAroundPivot(v1, prev, new Vector3(0, 0, angle));
                v2 = RotatePointAroundPivot(v2, prev, new Vector3(0, 0, angle));
                v3 = RotatePointAroundPivot(v3, cur, new Vector3(0, 0, angle));
                v4 = RotatePointAroundPivot(v4, cur, new Vector3(0, 0, angle));

                Vector2 uvTopLeft = Vector2.zero;
                Vector2 uvBottomLeft = new Vector2(0, 1);

                Vector2 uvTopCenter = new Vector2(0.5f, 0);
                Vector2 uvBottomCenter = new Vector2(0.5f, 1);

                Vector2 uvTopRight = new Vector2(1, 0);
                Vector2 uvBottomRight = new Vector2(1, 1);

                Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };

                if (i > 1)
                    vbo.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));

                if (i == 1)
                    uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
                else if (i == TempPoints.Length - 1)
                    uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };

                vbo.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));

                prevV1 = v3;
                prevV2 = v4;
            }

            if (vbo.currentVertCount > 3)
            {
                vbo.FillMesh(toFill);
            }
        }
Exemplo n.º 30
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
            {
                return;
            }

            UIVertex uiVertex    = new UIVertex();
            int      vertexCount = vh.currentVertCount;

            if (Mode == GradientMode.SingleLine)
            {
                for (int i = 0; i < vertexCount; ++i)
                {
                    vh.PopulateUIVertex(ref uiVertex, i);

                    //垂直颜色渐变
                    if (Direction == GradientDirection.Vertical)
                    {
                        if (i % 4 == 0 || (i - 1) % 4 == 0)
                        {
                            uiVertex.color = firstColor;
                        }
                        else
                        {
                            uiVertex.color = secondColor;
                        }
                    }
                    else if (Direction == GradientDirection.Horizontal)
                    {
                        if (i % 4 == 0 || (i + 1) % 4 == 0)
                        {
                            uiVertex.color = firstColor;
                        }
                        else
                        {
                            uiVertex.color = secondColor;
                        }
                    }

                    vh.SetUIVertex(uiVertex, i);
                }
            }
            else if (Mode == GradientMode.Segment)
            {
                if (vertexCount >= 4)
                {
                    UIVertex firstVertex = new UIVertex();
                    vh.PopulateUIVertex(ref firstVertex, 0);
                    UIVertex lastVertex = new UIVertex();
                    vh.PopulateUIVertex(ref lastVertex, vertexCount - 2);

                    float factorA = Direction == GradientDirection.Vertical ? firstVertex.position.y : firstVertex.position.x;
                    float factorB = Direction == GradientDirection.Vertical ? lastVertex.position.y : lastVertex.position.x;

                    float distance = factorA - factorB;

                    for (int i = 0; i < vertexCount; ++i)
                    {
                        vh.PopulateUIVertex(ref uiVertex, i);
                        if (Direction == GradientDirection.Vertical)
                        {
                            uiVertex.color = Color32.Lerp(secondColor, firstColor, (uiVertex.position.y - lastVertex.position.y) / distance);
                        }
                        else
                        {
                            uiVertex.color = Color32.Lerp(secondColor, firstColor, (uiVertex.position.x - lastVertex.position.x) / distance);
                        }

                        vh.SetUIVertex(uiVertex, i);
                    }
                }
            }
        }
Exemplo n.º 31
0
        public override VertexHelper DrawBase(VertexHelper vh)
        {
            // 绘制边框虚线
            if (!radarData.Base)
            {
                return(vh);
            }
            float perRadian = Mathf.PI * 2.0f / radarData.ItemCount;

            for (int i = 0; i <= radarData.ItemCount; i++)
            {
                float   startRadian = perRadian * i;
                float   endRadian   = perRadian * (i + 1);
                Vector2 startPos    = new Vector2(Mathf.Cos(startRadian), Mathf.Sin(startRadian)) * radarData.Radius;
                Vector2 endPos      = new Vector2(Mathf.Cos(endRadian), Mathf.Sin(endRadian)) * radarData.Radius;
                GetQuadDottedline(vh, startPos, endPos, radarData.MeshColor, radarData.MeshWidth);
            }
            if (radarData.ShowInternalMesh)
            {
                float perRadius = radarData.Radius / radarData.Layers;
                for (int i = 1; i < radarData.Layers; i++)
                {
                    float radius = perRadius * i;
                    for (int j = 0; j <= radarData.ItemCount; j++)
                    {
                        float   startRadian = perRadian * j;
                        float   endRadian   = perRadian * (j + 1);
                        Vector2 startPos    = new Vector2(Mathf.Cos(startRadian), Mathf.Sin(startRadian)) * radius;
                        Vector2 endPos      = new Vector2(Mathf.Cos(endRadian), Mathf.Sin(endRadian)) * radius;
                        GetQuadDottedline(vh, startPos, endPos, radarData.InternalMeshColor, radarData.InternalMeshWidth);
                    }
                }
            }
            if (radarData.Colorful)
            {
                float perRadius = radarData.Radius / radarData.Layers;
                for (int i = 1; i <= radarData.Layers; i++)
                {
                    float radius = perRadius * i;
                    Color color  = radarData.GetLayerColor(i - 1);
                    for (int j = 0; j <= radarData.ItemCount; j++)
                    {
                        float   startRadian = perRadian * j;
                        float   endRadian   = perRadian * (j + 1);
                        Vector2 startPosF   = new Vector2(Mathf.Cos(startRadian), Mathf.Sin(startRadian)) * radius;
                        Vector2 endPosF     = new Vector2(Mathf.Cos(endRadian), Mathf.Sin(endRadian)) * radius;
                        Vector2 startPosS   = new Vector2(Mathf.Cos(startRadian), Mathf.Sin(startRadian)) * (radius - perRadius);
                        Vector2 endPosS     = new Vector2(Mathf.Cos(endRadian), Mathf.Sin(endRadian)) * (radius - perRadius);

                        vh.AddUIVertexQuad(new UIVertex[]
                        {
                            GetUIVertex(startPosF, color),
                            GetUIVertex(startPosS, color),
                            GetUIVertex(endPosS, color),
                            GetUIVertex(endPosF, color)
                        });
                    }
                }
            }
            return(vh);
        }
Exemplo n.º 32
0
 protected virtual void DrawChart(VertexHelper vh)
 {
 }
Exemplo n.º 33
0
        void SplitTrianglesAtGradientStops(List<UIVertex> _vertexList, Rect bounds, float zoomOffset, VertexHelper helper)
        {
            List<float> stops = FindStops(zoomOffset, bounds);
            if (stops.Count > 0)
            {
                helper.Clear();

                int nCount = _vertexList.Count;
                for (int i = 0; i < nCount; i += 3)
                {
                    float[] positions = GetPositions(_vertexList, i);
                    List<int> originIndices = new List<int>(3);
                    List<UIVertex> starts = new List<UIVertex>(3);
                    List<UIVertex> ends = new List<UIVertex>(2);

                    for (int s = 0; s < stops.Count; s++)
                    {
                        int initialCount = helper.currentVertCount;
                        bool hadEnds = ends.Count > 0;
                        bool earlyStart = false;

                        // find any start vertices for this stop
                        for (int p = 0; p < 3; p++)
                        {
                            if (!originIndices.Contains(p) && positions[p] < stops[s])
                            {
                                // make sure the first index crosses the stop
                                int p1 = (p + 1) % 3;
                                var start = _vertexList[p + i];
                                if (positions[p1] > stops[s])
                                {
                                    originIndices.Insert(0, p);
                                    starts.Insert(0, start);
                                    earlyStart = true;
                                }
                                else
                                {
                                    originIndices.Add(p);
                                    starts.Add(start);
                                }
                            }
                        }

                        // bail if all before or after the stop
                        if (originIndices.Count == 0)
                            continue;
                        if (originIndices.Count == 3)
                            break;

                        // report any start vertices
                        foreach (var start in starts)
                            helper.AddVert(start);

                        // make two ends, splitting at the stop
                        ends.Clear();
                        foreach (int index in originIndices)
                        {
                            int oppositeIndex = (index + 1) % 3;
                            if (positions[oppositeIndex] < stops[s])
                                oppositeIndex = (oppositeIndex + 1) % 3;
                            ends.Add(CreateSplitVertex(_vertexList[index + i], _vertexList[oppositeIndex + i], stops[s]));
                        }
                        if (ends.Count == 1)
                        {
                            int oppositeIndex = (originIndices[0] + 2) % 3;
                            ends.Add(CreateSplitVertex(_vertexList[originIndices[0] + i], _vertexList[oppositeIndex + i], stops[s]));
                        }

                        // report end vertices
                        foreach (var end in ends)
                            helper.AddVert(end);

                        // make triangles
                        if (hadEnds)
                        {
                            helper.AddTriangle(initialCount - 2, initialCount, initialCount + 1);
                            helper.AddTriangle(initialCount - 2, initialCount + 1, initialCount - 1);
                            if (starts.Count > 0)
                            {
                                if (earlyStart)
                                    helper.AddTriangle(initialCount - 2, initialCount + 3, initialCount);
                                else
                                    helper.AddTriangle(initialCount + 1, initialCount + 3, initialCount - 1);
                            }
                        }
                        else
                        {
                            int vertexCount = helper.currentVertCount;
                            helper.AddTriangle(initialCount, vertexCount - 2, vertexCount - 1);
                            if (starts.Count > 1)
                                helper.AddTriangle(initialCount, vertexCount - 1, initialCount + 1);
                        }

                        starts.Clear();
                    }

                    // clean up after looping through gradient stops
                    if (ends.Count > 0)
                    {
                        // find any final vertices after the gradient stops
                        if (starts.Count == 0)
                        {
                            for (int p = 0; p < 3; p++)
                            {
                                if (!originIndices.Contains(p) && positions[p] > stops[stops.Count - 1])
                                {
                                    int p1 = (p + 1) % 3;
                                    UIVertex end = _vertexList[p + i];
                                    if (positions[p1] > stops[stops.Count - 1])
                                        starts.Insert(0, end);
                                    else
                                        starts.Add(end);
                                }
                            }
                        }

                        // report final vertices
                        foreach (var start in starts)
                            helper.AddVert(start);

                        // make final triangle(s)
                        int vertexCount = helper.currentVertCount;
                        if (starts.Count > 1)
                        {
                            helper.AddTriangle(vertexCount - 4, vertexCount - 2, vertexCount - 1);
                            helper.AddTriangle(vertexCount - 4, vertexCount - 1, vertexCount - 3);
                        }
                        else if (starts.Count > 0)
                        {
                            helper.AddTriangle(vertexCount - 3, vertexCount - 1, vertexCount - 2);
                        }
                    }
                    else
                    {
                        // if the triangle wasn't split, add it as-is
                        helper.AddVert(_vertexList[i]);
                        helper.AddVert(_vertexList[i + 1]);
                        helper.AddVert(_vertexList[i + 2]);
                        int vertexCount = helper.currentVertCount;
                        helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1);
                    }
                }
            }
        }
Exemplo n.º 34
0
		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.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.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);
			}
		}
Exemplo n.º 35
0
    /// <summary>
    /// Generate vertices for a tiled Image.
    /// </summary>

    void GenerateTiledSprite(VertexHelper toFill)
    {
        //Debug.Log("==============================&&&&&");
        Vector4 outer, inner, border;
        Vector2 spriteSize;

        if (sprite != null)
        {
            outer      = DataUtility.GetOuterUV(sprite);
            inner      = DataUtility.GetInnerUV(sprite);
            border     = sprite.border;
            spriteSize = sprite.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);

        // 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 width 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 (sprite != null && (hasBorder || sprite.packed || sprite.texture.wrapMode != TextureWrapMode.Repeat))
        {
            // Sprite has border, or is not in repeat mode, or cannot be repeated because of packing.
            // We cannot use texture tiling so we will generate a mesh of quads to tile the texture.

            // Evaluate how many vertices we will generate. Limit this number to something sane,
            // especially since meshes can not have more than 65000 vertices.

            long nTilesW = 0;
            long nTilesH = 0;
            if (fillCenter)
            {
                nTilesW = (long)Mathf.Ceil((xMax - xMin) / tileWidth);
                nTilesH = (long)Mathf.Ceil((yMax - yMin) / tileHeight);

                double nVertices = 0;
                if (hasBorder)
                {
                    nVertices = (nTilesW + 2.0) * (nTilesH + 2.0) * 4.0; // 4 vertices per tile
                }
                else
                {
                    nVertices = nTilesW * nTilesH * 4.0; // 4 vertices per tile
                }

                if (nVertices > 65000.0)
                {
                    //Debug.LogError("Too many sprite tiles on Image \"" + name + "\". The tile size will be increased. To remove the limit on the number of tiles, convert the Sprite to an Advanced texture, remove the borders, clear the Packing tag and set the Wrap mode to Repeat.", this);

                    double maxTiles = 65000.0 / 4.0; // Max number of vertices is 65000; 4 vertices per tile.
                    double imageRatio;
                    if (hasBorder)
                    {
                        imageRatio = (nTilesW + 2.0) / (nTilesH + 2.0);
                    }
                    else
                    {
                        imageRatio = (double)nTilesW / nTilesH;
                    }

                    float targetTilesW = Mathf.Sqrt((float)(maxTiles / imageRatio));
                    float targetTilesH = (float)(targetTilesW * imageRatio);
                    if (hasBorder)
                    {
                        targetTilesW -= 2;
                        targetTilesH -= 2;
                    }

                    nTilesW    = (long)Mathf.Floor(targetTilesW);
                    nTilesH    = (long)Mathf.Floor(targetTilesH);
                    tileWidth  = (xMax - xMin) / nTilesW;
                    tileHeight = (yMax - yMin) / nTilesH;
                }
            }
            else
            {
                if (hasBorder)
                {
                    // Texture on the border is repeated only in one direction.
                    nTilesW = (long)Mathf.Ceil((xMax - xMin) / tileWidth);
                    nTilesH = (long)Mathf.Ceil((yMax - yMin) / tileHeight);
                    double nVertices = (nTilesH + nTilesW + 2.0 /*corners*/) * 2.0 /*sides*/ * 4.0 /*vertices per tile*/;
                    if (nVertices > 65000.0)
                    {
                        //Debug.LogError("Too many sprite tiles on Image \"" + name + "\". The tile size will be increased. To remove the limit on the number of tiles, convert the Sprite to an Advanced texture, remove the borders, clear the Packing tag and set the Wrap mode to Repeat.", this);

                        double maxTiles     = 65000.0 / 4.0; // Max number of vertices is 65000; 4 vertices per tile.
                        double imageRatio   = (double)nTilesW / nTilesH;
                        float  targetTilesW = (float)((maxTiles - 4 /*corners*/) / (2 * (1.0 + imageRatio)));
                        float  targetTilesH = (float)(targetTilesW * imageRatio);

                        nTilesW    = (long)Mathf.Floor(targetTilesW);
                        nTilesH    = (long)Mathf.Floor(targetTilesH);
                        tileWidth  = (xMax - xMin) / nTilesW;
                        tileHeight = (yMax - yMin) / nTilesH;
                    }
                }
                else
                {
                    nTilesH = nTilesW = 0;
                }
            }

            if (fillCenter)
            {
                // TODO: we could share vertices between quads. If vertex sharing is implemented. update the computation for the number of vertices accordingly.
                for (long j = 0; j < nTilesH; j++)
                {
                    float y1  = yMin + j * tileHeight;
                    float y2  = yMin + (j + 1) * tileHeight;
                    float y2e = y2;
                    if (y2 > yMax)
                    {
                        clipped.y = uvMin.y + (uvMax.y - uvMin.y) * (yMax - y1) / (y2 - y1);
                        y2        = yMax;
                    }
                    clipped.x = uvMax.x;
                    for (long i = 0; i < nTilesW; i++)
                    {
                        float x1  = xMin + i * tileWidth;
                        float x2  = xMin + (i + 1) * tileWidth;
                        float x2e = x2;
                        if (x2 > xMax)
                        {
                            clipped.x = uvMin.x + (uvMax.x - uvMin.x) * (xMax - x1) / (x2 - x1);
                            x2        = xMax;
                        }

                        var uvMin1   = uvMin;
                        var clipped1 = clipped;
                        //Debug.Log("i::" + i + "  j:::" + j);
                        switch (mirrorType)
                        {
                        case MirrorType.Horizontal:
                            if (i % 2 == 1)
                            {
                                float offsetX = 0;
                                if (x2e > xMax)
                                {
                                    offsetX = uvMax.x - (uvMax.x - uvMin.x) * (xMax - x1) / (x2e - x1);
                                }
                                uvMin1 = new Vector2(uvMax.x, uvMin.y);
                                //clipped1 = new Vector2(uvMin.x, clipped.y);
                                clipped1 = new Vector2(offsetX, clipped.y);
                            }
                            break;

                        case MirrorType.Vertical:
                            if (j % 2 == 1)
                            {
                                float offsetY = 0;
                                if (y2e > yMax)
                                {
                                    offsetY = uvMax.y - (uvMax.y - uvMin.y) * (yMax - y1) / (y2e - y1);
                                }
                                //uvMin1 = new Vector2(uvMin.x, clipped.y);
                                uvMin1 = new Vector2(uvMin.x, uvMax.y);
                                //clipped1 = new Vector2(clipped.x, uvMin.y);
                                clipped1 = new Vector2(clipped.x, offsetY);
                            }
                            break;

                        case MirrorType.Quarter:
                            if (j % 2 == 1 && i % 2 == 1)
                            {
                                float offsetX = uvMin.x;
                                if (x2e > xMax)
                                {
                                    offsetX = uvMax.x - (uvMax.x - uvMin.x) * (xMax - x1) / (x2e - x1);
                                }

                                float offsetY = uvMin.y;
                                if (y2e > yMax)
                                {
                                    offsetY = uvMax.y - (uvMax.y - uvMin.y) * (yMax - y1) / (y2e - y1);
                                }

                                clipped1 = new Vector2(offsetX, offsetY);
                                uvMin1   = uvMax;
                            }
                            else if (j % 2 == 1)
                            {
                                float offsetY = 0;
                                if (y2e > yMax)
                                {
                                    offsetY = uvMax.y - (uvMax.y - uvMin.y) * (yMax - y1) / (y2e - y1);
                                }
                                //uvMin1 = new Vector2(uvMin.x, clipped.y);
                                uvMin1 = new Vector2(uvMin.x, uvMax.y);
                                //clipped1 = new Vector2(clipped.x, uvMin.y);
                                clipped1 = new Vector2(clipped.x, offsetY);
                            }
                            else if (i % 2 == 1)
                            {
                                float offsetX = 0;
                                if (x2e > xMax)
                                {
                                    offsetX = uvMax.x - (uvMax.x - uvMin.x) * (xMax - x1) / (x2e - x1);
                                }
                                uvMin1 = new Vector2(uvMax.x, uvMin.y);
                                //clipped1 = new Vector2(uvMin.x, clipped.y);
                                clipped1 = new Vector2(offsetX, clipped.y);
                            }
                            break;

                        default:
                            break;
                        }


                        AddQuad(toFill, new Vector2(x1, y1) + rect.position, new Vector2(x2, y2) + rect.position, color, uvMin1, clipped1);
                    }
                }
            }
            if (hasBorder)
            {
                clipped = uvMax;
                for (long j = 0; j < nTilesH; j++)
                {
                    float y1 = yMin + j * tileHeight;
                    float y2 = yMin + (j + 1) * 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 (long i = 0; i < nTilesW; i++)
                {
                    float x1 = xMin + i * tileWidth;
                    float x2 = xMin + (i + 1) * 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));
            }
        }
        else
        {
            // Texture has no border, is in repeat mode and not packed. Use texture tiling.
            Vector2 uvScale = new Vector2((xMax - xMin) / tileWidth, (yMax - yMin) / tileHeight);

            if (fillCenter)
            {
                AddQuad(toFill, new Vector2(xMin, yMin) + rect.position, new Vector2(xMax, yMax) + rect.position, color, Vector2.Scale(uvMin, uvScale), Vector2.Scale(uvMax, uvScale));
            }
        }
    }
Exemplo n.º 36
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            float outer = -rectTransform.pivot.x * rectTransform.rect.width;
            float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thickness;
     
            vh.Clear();
     
            Vector2 prevX = Vector2.zero;
            Vector2 prevY = Vector2.zero;
            Vector2 uv0 = new Vector2(0, 0);
            Vector2 uv1 = new Vector2(0, 1);
            Vector2 uv2 = new Vector2(1, 1);
            Vector2 uv3 = new Vector2(1, 0);
            Vector2 pos0;
            Vector2 pos1;
            Vector2 pos2;
            Vector2 pos3;

            if (FixedToSegments)
            {
                float f = (this.fillPercent / 100f);
                float degrees = 360f / segments;
                int fa = (int)((segments + 1) * f);


                for (int i = 0; i < fa; i++)
                {
                    float rad = Mathf.Deg2Rad * (i * degrees);
                    float c = Mathf.Cos(rad);
                    float s = Mathf.Sin(rad);

                    uv0 = new Vector2(0, 1);
                    uv1 = new Vector2(1, 1);
                    uv2 = new Vector2(1, 0);
                    uv3 = new Vector2(0, 0);

                    StepThroughPointsAndFill(outer, inner, ref prevX, ref prevY, out pos0, out pos1, out pos2, out pos3, c, s);

                    vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
                }
            }
            else
            {
                float tw = rectTransform.rect.width;
                float th = rectTransform.rect.height;

                float angleByStep = (fillPercent / 100f * (Mathf.PI * 2f)) / segments;
                float currentAngle = 0f;
                for (int i = 0; i < segments + 1; i++)
                {

                    float c = Mathf.Cos(currentAngle);
                    float s = Mathf.Sin(currentAngle);

                    StepThroughPointsAndFill(outer, inner, ref prevX, ref prevY, out pos0, out pos1, out pos2, out pos3, c, s);

                    uv0 = new Vector2(pos0.x / tw + 0.5f, pos0.y / th + 0.5f);
                    uv1 = new Vector2(pos1.x / tw + 0.5f, pos1.y / th + 0.5f);
                    uv2 = new Vector2(pos2.x / tw + 0.5f, pos2.y / th + 0.5f);
                    uv3 = new Vector2(pos3.x / tw + 0.5f, pos3.y / th + 0.5f);

                    vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));

                    currentAngle += angleByStep;
                }
            }
        }
Exemplo n.º 37
0
        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("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 * 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 (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];

                    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++;
			}
            vh.Clear();
            vh.AddUIVertexTriangleStream(verts);
        }
Exemplo n.º 38
0
 protected virtual void DrawTooltip(VertexHelper vh)
 {
 }
Exemplo n.º 39
0
        public virtual void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
            {
                return;
            }

            var gen       = richText.cachedTextGenerator;
            var charCount = gen.characterCount;

            if (charCount <= 1 || m_BeginIndex >= charCount - 1)
            {
                return;
            }

            if (m_ParameterDirty || richText.color.a != m_Alpha)
            {
                m_ParameterDirty = false;
                OnParameterRebuild();
            }

            var text       = richText.text;
            var lines      = gen.lines;
            var chars      = gen.characters;
            var endCharIdx = chars.Count - 2;

            for (int i = lines.Count - 1; i >= 0 && endCharIdx >= m_BeginIndex; i--)
            {
                var line         = lines[i];
                var startCharIdx = line.startCharIdx;
                if (startCharIdx <= m_EndIndex)
                {
                    endCharIdx   = Math.Min(endCharIdx, m_EndIndex);
                    startCharIdx = Math.Max(startCharIdx, m_BeginIndex);
                    //if (skipWhitespace) {
                    while (startCharIdx <= endCharIdx)
                    { // skip begin whitespaces
                        var info = chars[startCharIdx];
                        if (info.charWidth > 0 && !char.IsWhiteSpace(text, startCharIdx))
                        {
                            break;
                        }
                        ++startCharIdx;
                    }
                    while (endCharIdx >= startCharIdx)
                    { // skip end whitespaces
                        var info = chars[endCharIdx];
                        if (info.charWidth > 0 && !char.IsWhiteSpace(text, endCharIdx))
                        {
                            break;
                        }
                        --endCharIdx;
                    }
                    //}
                    if (startCharIdx <= endCharIdx)
                    {
                        ProcessCharactersAtLine(vh, i, startCharIdx, endCharIdx, lines, chars);
                    }
                }
                endCharIdx = line.startCharIdx - 1;
            }
        }
Exemplo n.º 40
0
        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:
                case Type.Vertical:
                    {
                        Rect bounds = GetBounds(_vertexList);
                        float min = bounds.xMin;
                        float w = bounds.width;
                        Func<UIVertex, float> GetPosition = v => v.position.x;

                        if (GradientType == Type.Vertical)
                        {
                            min = bounds.yMin;
                            w = bounds.height;
                            GetPosition = v => v.position.y;
                        }

                        float width = 1f / w / Zoom;
                        float zoomOffset = (1 - (1 / Zoom)) * 0.5f;
                        float offset = (Offset * (1 - zoomOffset)) - zoomOffset;

                        if (ModifyVertices)
                        {
                            SplitTrianglesAtGradientStops(_vertexList, bounds, zoomOffset, helper);
                        }

                        UIVertex vertex = new UIVertex();
                        for (int i = 0; i < helper.currentVertCount; i++)
                        {
                            helper.PopulateUIVertex(ref vertex, i);
                            float time = (GetPosition(vertex) - min) * width - offset;
                            if (!float.IsNaN(time))
                                vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(time));
                            helper.SetUIVertex(vertex, i);
                        }
                    }
                    break;

                case Type.Diamond:
                    {
                        Rect bounds = GetBounds(_vertexList);

                        float height = 1f / bounds.height / Zoom;
                        float radius = bounds.center.y / 2f;
                        Vector3 center = (Vector3.right + Vector3.up) * radius + Vector3.forward * _vertexList[0].position.z;

                        if (ModifyVertices)
                        {
                            helper.Clear();
                            for (int i = 0; i < nCount; i++) helper.AddVert(_vertexList[i]);

                            UIVertex centralVertex = new UIVertex();
                            centralVertex.position = center;
                            centralVertex.normal = _vertexList[0].normal;
                            centralVertex.uv0 = new Vector2(0.5f, 0.5f);
                            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, center) * height - Offset));

                            helper.SetUIVertex(vertex, i);
                        }
                    }
                    break;

                case Type.Radial:
                    {
                        Rect bounds = GetBounds(_vertexList);

                        float width = 1f / bounds.width / Zoom;
                        float height = 1f / bounds.height / Zoom;

                        if (ModifyVertices)
                        {
                            helper.Clear();

                            float radiusX = bounds.width / 2f;
                            float radiusY = bounds.height / 2f;
                            UIVertex centralVertex = new UIVertex();
                            centralVertex.position = Vector3.right * bounds.center.x + Vector3.up * bounds.center.y + Vector3.forward * _vertexList[0].position.z;
                            centralVertex.normal = _vertexList[0].normal;
                            centralVertex.uv0 = new Vector2(0.5f, 0.5f);
                            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 cosX = Mathf.Cos(Mathf.Deg2Rad * angle);
                                float cosY = Mathf.Sin(Mathf.Deg2Rad * angle);

                                curVertex.position = Vector3.right * cosX * radiusX + Vector3.up * cosY * radiusY + Vector3.forward * _vertexList[0].position.z;
                                curVertex.normal = _vertexList[0].normal;
                                curVertex.uv0 = new Vector2((cosX + 1) * 0.5f, (cosY + 1) * 0.5f);
                                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 - bounds.center.x) * width, 2f) +
                                    Mathf.Pow(Mathf.Abs(vertex.position.y - bounds.center.y) * height, 2f)) * 2f - Offset));

                            helper.SetUIVertex(vertex, i);
                        }
                    }
                    break;
            }
        }
Exemplo n.º 41
0
        protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
                                  float tickness, Vector3 pos, Color color, Color toColor, float gap)
        {
            var backgroundColor = m_ThemeInfo.backgroundColor;
            var smoothness      = m_Settings.cicleSmoothness;

            switch (type)
            {
            case SerieSymbolType.None:
                break;

            case SerieSymbolType.Circle:
                if (gap > 0)
                {
                    ChartDrawer.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, color, toColor, smoothness);
                }
                else
                {
                    ChartDrawer.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
                }
                break;

            case SerieSymbolType.EmptyCircle:
                if (gap > 0)
                {
                    ChartDrawer.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
                    ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness);
                }
                else
                {
                    ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, toColor, backgroundColor, smoothness);
                }
                break;

            case SerieSymbolType.Rect:
                if (gap > 0)
                {
                    ChartDrawer.DrawPolygon(vh, pos, symbolSize + gap, backgroundColor);
                    ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    ChartDrawer.DrawPolygon(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SerieSymbolType.Triangle:
                if (gap > 0)
                {
                    ChartDrawer.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
                    ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    ChartDrawer.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SerieSymbolType.Diamond:
                if (gap > 0)
                {
                    ChartDrawer.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
                    ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    ChartDrawer.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                break;
            }
        }
        /// <summary>
        /// Update the UI renderer mesh.
        /// </summary>
        protected override void OnPopulateMesh(Mesh toFill)
        {
            List<UIVertex> vbo = new List<UIVertex>();
            using (var helper = new VertexHelper(toFill))
            {
                helper.GetUIVertexStream(vbo);
            }

            switch (type)
            {
                case Type.Simple:
                    GenerateSimpleSprite(vbo, m_PreserveAspect);
                    break;
                case Type.Sliced:
                    GenerateSlicedSprite(vbo);
                    break;
                case Type.Tiled:
                    GenerateTiledSprite(vbo);
                    break;
                case Type.Filled:
                    GenerateFilledSprite(vbo, m_PreserveAspect);
                    break;
            }

            using (var helper = new VertexHelper())
            {
                helper.AddUIVertexTriangleStream(vbo);
                helper.FillMesh(toFill);
            }
        }
Exemplo n.º 43
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (m_TargetMin == Vector3.zero && m_TargetMax == Vector3.zero)
            {
                base.OnPopulateMesh(vh);
            }
            vh.Clear();

            //填充点点 顺时针填充顶点 法线看向摄像机 为 三角面的正面
            UIVertex vert = UIVertex.simpleVert;

            vert.color = color;

            Vector2 selfPiovt = rectTransform.pivot;
            Rect    selfRect  = rectTransform.rect;
            //外圈左值x
            float outerLx = -selfPiovt.x * selfRect.width;
            //外圈右值
            float outerRx = (1 - selfPiovt.x) * selfRect.width;
            //外圈顶值y
            float outerTy = (1 - selfPiovt.y) * selfRect.height;
            //外圈底值y
            float outerBy = -selfPiovt.y * selfRect.height;

            //外圈左上点
            Vector3 ltPos1 = new Vector3(outerLx, outerTy);

            vert.position = ltPos1;
            vh.AddVert(vert);
            //外圈右上点
            Vector3 rtPos1 = new Vector3(outerRx, outerTy);

            vert.position = rtPos1;
            vh.AddVert(vert);
            //外圈右下点
            Vector3 rbPos1 = new Vector3(outerRx, outerBy);

            vert.position = rbPos1;
            vh.AddVert(vert);
            //外圈左下点
            Vector3 lbPos1 = new Vector3(outerLx, outerBy);

            vert.position = lbPos1;
            vh.AddVert(vert);

            //内圈左上点
            Vector3 ltPos2 = new Vector3(m_TargetMin.x, m_TargetMax.y);

            vert.position = ltPos2;
            vh.AddVert(vert);
            //外圈右上点
            Vector3 rtPos2 = new Vector3(m_TargetMax.x, m_TargetMax.y);

            vert.position = rtPos2;
            vh.AddVert(vert);
            //外圈右下点
            Vector3 rbPos2 = new Vector3(m_TargetMax.x, m_TargetMin.y);

            vert.position = rbPos2;
            vh.AddVert(vert);
            //外圈左下点
            Vector3 lbPos2 = new Vector3(m_TargetMin.x, m_TargetMin.y);

            vert.position = lbPos2;
            vh.AddVert(vert);


            vh.AddTriangle(4, 0, 1);
            vh.AddTriangle(4, 1, 5);
            vh.AddTriangle(5, 1, 2);
            vh.AddTriangle(5, 2, 6);
            vh.AddTriangle(6, 2, 3);
            vh.AddTriangle(6, 3, 7);
            vh.AddTriangle(7, 3, 0);
            vh.AddTriangle(7, 0, 4);
        }
Exemplo n.º 44
0
 public override void ModifyMesh(VertexHelper vh)
 {
 }
Exemplo n.º 45
0
    private void GenerateSlicedSprite(VertexHelper toFill)
    {
        if (!hasBorder)
        {
            GenerateSimpleSprite(toFill, false);
            return;
        }

        Vector4 outer, inner, padding, border;

        if (sprite != null)
        {
            outer   = DataUtility.GetOuterUV(sprite);
            inner   = DataUtility.GetInnerUV(sprite);
            padding = DataUtility.GetPadding(sprite);
            border  = sprite.border;
        }
        else
        {
            outer   = Vector4.zero;
            inner   = Vector4.zero;
            padding = Vector4.zero;
            border  = Vector4.zero;
        }

        Rect rect = GetPixelAdjustedRect();

        Vector4 adjustedBorders = GetAdjustedBorders(border / pixelsPerUnit, rect);

        //Debug.Log($"outer:{outer},inner:{inner},padding:{padding},adjustedBorders:{adjustedBorders},border:{border}");
        padding = padding / pixelsPerUnit;
        //Debug.Log($"outer:{outer},inner:{inner},padding:{padding},border:{border}");
        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 = adjustedBorders.x;
        s_VertScratch[1].y = adjustedBorders.y;

        s_VertScratch[2].x = rect.width - adjustedBorders.z;
        s_VertScratch[2].y = rect.height - adjustedBorders.w;



        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);

        //Debug.Log($"vert1:{s_VertScratch[0]},{s_VertScratch[1]},{s_VertScratch[2]},{s_VertScratch[3]},");
        //Debug.Log($"uv1:{s_UVScratch[0]},{s_UVScratch[1]},{s_UVScratch[2]},{s_UVScratch[3]},");
        switch (mirrorType)
        {
        case MirrorType.Horizontal:
            s_VertScratch[2].x = rect.width - (s_VertScratch[1].x - s_VertScratch[0].x);
            s_VertScratch[2].y = rect.height - (s_VertScratch[1].y - s_VertScratch[0].y);
            s_UVScratch[2]     = new Vector2(inner.x, inner.w);
            s_UVScratch[3]     = new Vector2(outer.x, outer.w);
            break;

        case MirrorType.Vertical:
            s_VertScratch[2].x = rect.width - (s_VertScratch[1].x - s_VertScratch[0].x);
            s_VertScratch[2].y = rect.height - (s_VertScratch[1].y - s_VertScratch[0].y);
            s_UVScratch[2]     = new Vector2(inner.z, inner.y);
            s_UVScratch[3]     = new Vector2(outer.z, outer.y);
            break;

        case MirrorType.Quarter:
            s_VertScratch[2].x = rect.width - (s_VertScratch[1].x - s_VertScratch[0].x);
            s_VertScratch[2].y = rect.height - (s_VertScratch[1].y - s_VertScratch[0].y);
            s_UVScratch[2]     = new Vector2(inner.x, inner.y);
            s_UVScratch[3]     = new Vector2(outer.x, outer.y);
            break;

        default:
            break;
        }

        //Debug.Log($"uv2:{s_UVScratch[0]},{s_UVScratch[1]},{s_UVScratch[2]},{s_UVScratch[3]},");
        //Debug.Log($"vert2:{s_VertScratch[0]},{s_VertScratch[1]},{s_VertScratch[2]},{s_VertScratch[3]},");

        for (int i = 0; i < 4; ++i)
        {
            s_VertScratch[i].x += rect.x;
            s_VertScratch[i].y += rect.y;
        }
        toFill.Clear();

        for (int x = 0; x < 3; ++x)
        {
            int x2 = x + 1;

            for (int y = 0; y < 3; ++y)
            {
                if (!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));
            }
        }
    }
Exemplo n.º 46
0
 /// <summary>
 /// Auto UV handler within the assigned area
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="area"></param>
 /// <param name="color32"></param>
 /// <param name="vh"></param>
 private static int AddVert(float x, float y, Rect area, Color32 color32, VertexHelper vh) {
     var uv = new Vector2(
         Mathf.InverseLerp(area.xMin, area.xMax, x),
         Mathf.InverseLerp(area.yMin, area.yMax, y)
     );
     vh.AddVert(new Vector3(x, y), color32, uv);
     return vh.currentVertCount - 1;
 }
Exemplo n.º 47
0
 protected override void OnPopulateMesh(VertexHelper vh)
 {
     vh.Clear();
 }
Exemplo n.º 48
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            if (font == null)
                return;

            // We don't care if we the font Texture changes while we are doing our Update.
            // The end result of cachedTextGenerator will be valid for this instance.
            // Otherwise we can get issues like Case 619238.
            m_DisableFontTextureRebuiltCallback = true;

            Vector2 extents = rectTransform.rect.size;

            var settings = GetGenerationSettings(extents);
            cachedTextGenerator.Populate(text, settings);

            Rect inputRect = rectTransform.rect;

            // get the text alignment anchor point for the text in local space
            Vector2 textAnchorPivot = GetTextAnchorPivot(alignment);
            Vector2 refPoint = Vector2.zero;
            refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin);
            refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax);

            // Determine fraction of pixel to offset text mesh.
            Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint;

            // --- Changes ----

            // Not really good place to put it, need to find somewhere else.
            univTextGroup = new UnivTextGroup(m_Text);
            alignment = univTextGroup.IsGroupRTL ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft;
            cachedTextGenerator.Populate(univTextGroup.CorrectedString(), settings);

            // ---- End of changes ----

            // 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;
        }
Exemplo n.º 49
0
 public static void DrawTriangle(VertexHelper vh, Vector3 p1,
                                 Vector3 p2, Vector3 p3, Color32 color)
 {
     DrawTriangle(vh, p1, p2, p3, color, color, color);
 }
Exemplo n.º 50
0
        private static void AddSquare(Rect rect, Rect rectUV, Color32 color32, VertexHelper vh) {
            int v0 = AddVert(rect.xMin, rect.yMin, rectUV, color32, vh);
            int v1 = AddVert(rect.xMin, rect.yMax, rectUV, color32, vh);
            int v2 = AddVert(rect.xMax, rect.yMax, rectUV, color32, vh);
            int v3 = AddVert(rect.xMax, rect.yMin, rectUV, color32, vh);
 
            vh.AddTriangle(v0, v1, v2);
            vh.AddTriangle(v2, v3, v0);
        }
Exemplo n.º 51
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
#if UNITY_EDITOR
            if (!UnityEditor.EditorApplication.isPlaying)
            {
                toFill.Clear();
                return;
            }
#endif
            toFill.Clear();
            if (!ShowPreview())
            {
                return;
            }
            var map = GetBeatmap();
            if (map == null || map.Timings == null || map.Timings.Count == 0)
            {
                return;
            }
            float speedMuti = GetSpeedMuti();
            if (speedMuti <= 0.001f)
            {
                return;
            }
            var   timings      = map.Timings;
            int   count        = timings.Count;
            float musicTime    = GetMusicTime();
            float endTime      = musicTime + 1f / speedMuti;
            float firstMidTime = endTime;
            var   rect         = GetPixelAdjustedRect();
            CacheVertex[0].position.z = CacheVertex[1].position.z = CacheVertex[2].position.z = CacheVertex[3].position.z = 0f;

            // Mid
            for (int i = 0; i < count; i++)
            {
                var timing = timings[i];
                if (timing.Time >= musicTime && timing.Time < endTime)
                {
                    firstMidTime = Mathf.Min(firstMidTime, timing.Time);
                    int nextIndex = GetNextTiming(timing.Time);
                    if (nextIndex >= 0)
                    {
                        AddQuad(timing.Time, timings[nextIndex].Time, timing.Value);
                    }
                    else
                    {
                        AddQuad(timing.Time, float.MaxValue, timing.Value);
                    }
                }
            }

            // First
            int prevIndex = GetPrevTiming(musicTime);
            if (prevIndex >= 0)
            {
                var timing = timings[prevIndex];
                AddQuad(timing.Time, firstMidTime, timing.Value);
            }
            else
            {
                int   nextIndex = GetNextTiming(musicTime);
                float nextSpeed = 1f;
                if (nextIndex >= 0)
                {
                    nextSpeed = timings[nextIndex].Value;
                }
                AddQuad(0f, firstMidTime, nextSpeed);
            }

            // === Func ===
            int GetNextTiming(float time)
            {
                int   index    = -1;
                float nextTime = float.MaxValue;

                for (int i = 0; i < count; i++)
                {
                    var t = timings[i];
                    if (t.Time > time && t.Time < nextTime)
                    {
                        nextTime = t.Time;
                        index    = i;
                    }
                }
                return(index);
            }

            int GetPrevTiming(float time)
            {
                int   index    = -1;
                float prevTime = float.MinValue;

                for (int i = 0; i < count; i++)
                {
                    var t = timings[i];
                    if (t.Time < time && t.Time > prevTime)
                    {
                        prevTime = t.Time;
                        index    = i;
                    }
                }
                return(index);
            }

            void AddQuad(float time, float nextTime, float speed)
            {
                float y01     = Mathf.Clamp01(Util.RemapUnclamped(musicTime, endTime, 0f, 1f, time));
                float nextY01 = Mathf.Clamp01(Util.RemapUnclamped(musicTime, endTime, 0f, 1f, nextTime));

                // Y
                CacheVertex[0].position.y = CacheVertex[3].position.y = Mathf.Lerp(rect.yMin, rect.yMax, y01);
                CacheVertex[1].position.y = CacheVertex[2].position.y = Mathf.Lerp(rect.yMin, rect.yMax, nextY01);
                // X
                float x11 = Speed_to_UI(Mathf.Abs(speed));

                CacheVertex[0].position.x = CacheVertex[1].position.x = Mathf.LerpUnclamped(
                    rect.xMin, rect.xMax, 0f
                    );
                CacheVertex[2].position.x = CacheVertex[3].position.x = Mathf.LerpUnclamped(
                    rect.xMin, rect.xMax, x11
                    );
                // UV
                float UV_SCALE = 12f;

                CacheVertex[0].uv0 = new Vector2(0f, y01 * rect.height / UV_SCALE);
                CacheVertex[1].uv0 = new Vector2(0f, nextY01 * rect.height / UV_SCALE);
                CacheVertex[2].uv0 = new Vector2(x11 * rect.width / UV_SCALE, nextY01 * rect.height / UV_SCALE);
                CacheVertex[3].uv0 = new Vector2(x11 * rect.width / UV_SCALE, y01 * rect.height / UV_SCALE);
                // Tint
                CacheVertex[0].color = CacheVertex[1].color = CacheVertex[2].color = CacheVertex[3].color = (speed > 0f ? color : m_NegativeTint);
                // Add
                toFill.AddUIVertexQuad(CacheVertex);
            }

            float Speed_to_UI(float speed)
            {
                if (speed < 2f)
                {
                    return(speed);
                }
                else if (speed < 16f)
                {
                    return(Util.Remap(2f, 16f, 2f, 3f, speed));
                }
                else
                {
                    return(3f);
                }
            }
        }
Exemplo n.º 52
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (Points == null)
            {
                return;
            }

            var sizeX   = rectTransform.rect.width;
            var sizeY   = rectTransform.rect.height;
            var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
            var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;

            // don't want to scale based on the size of the rect, so this is switchable now
            if (!relativeSize)
            {
                sizeX = 1;
                sizeY = 1;
            }

            if (UseMargins)
            {
                sizeX   -= Margin.x;
                sizeY   -= Margin.y;
                offsetX += Margin.x / 2f;
                offsetY += Margin.y / 2f;
            }

            vh.Clear();

            // Generate the quads that make up the wide line
            var segments = new List <UIVertex[]>();

            if (LineList)
            {
                for (var i = 1; i < Points.Length; i += 2)
                {
                    var start = Points[i - 1];
                    var end   = Points[i];
                    start = new Vector2(start.x * sizeX + offsetX, start.y * sizeY + offsetY);
                    end   = new Vector2(end.x * sizeX + offsetX, end.y * sizeY + offsetY);

                    if (LineCaps)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.Start));
                    }

                    segments.Add(CreateLineSegment(start, end, SegmentType.Middle));

                    if (LineCaps)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.End));
                    }
                }
            }
            else
            {
                for (var i = 1; i < Points.Length; i++)
                {
                    var start = Points[i - 1];
                    var end   = Points[i];
                    start = new Vector2(start.x * sizeX + offsetX, start.y * sizeY + offsetY);
                    end   = new Vector2(end.x * sizeX + offsetX, end.y * sizeY + offsetY);

                    if (LineCaps && i == 1)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.Start));
                    }

                    segments.Add(CreateLineSegment(start, end, SegmentType.Middle));

                    if (LineCaps && i == Points.Length - 1)
                    {
                        segments.Add(CreateLineCap(start, end, SegmentType.End));
                    }
                }
            }

            // Add the line segments to the vertex helper, creating any joins as needed
            for (var i = 0; i < segments.Count; i++)
            {
                if (!LineList && i < segments.Count - 1)
                {
                    var vec1  = segments[i][1].position - segments[i][2].position;
                    var vec2  = segments[i + 1][2].position - segments[i + 1][1].position;
                    var angle = Vector2.Angle(vec1, vec2) * Mathf.Deg2Rad;

                    // Positive sign means the line is turning in a 'clockwise' direction
                    var sign = Mathf.Sign(Vector3.Cross(vec1.normalized, vec2.normalized).z);

                    // Calculate the miter point
                    var miterDistance = LineThickness / (2 * Mathf.Tan(angle / 2));
                    var miterPointA   = segments[i][2].position - vec1.normalized * miterDistance * sign;
                    var miterPointB   = segments[i][3].position + vec1.normalized * miterDistance * sign;

                    var joinType = LineJoins;
                    if (joinType == JoinType.Miter)
                    {
                        // Make sure we can make a miter join without too many artifacts.
                        if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_MITER_JOIN)
                        {
                            segments[i][2].position     = miterPointA;
                            segments[i][3].position     = miterPointB;
                            segments[i + 1][0].position = miterPointB;
                            segments[i + 1][1].position = miterPointA;
                        }
                        else
                        {
                            joinType = JoinType.Bevel;
                        }
                    }

                    if (joinType == JoinType.Bevel)
                    {
                        if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_BEVEL_NICE_JOIN)
                        {
                            if (sign < 0)
                            {
                                segments[i][2].position     = miterPointA;
                                segments[i + 1][1].position = miterPointA;
                            }
                            else
                            {
                                segments[i][3].position     = miterPointB;
                                segments[i + 1][0].position = miterPointB;
                            }
                        }

                        var join = new UIVertex[] { segments[i][2], segments[i][3], segments[i + 1][0], segments[i + 1][1] };
                        vh.AddUIVertexQuad(join);
                    }
                }
                vh.AddUIVertexQuad(segments[i]);
            }
        }
Exemplo n.º 53
0
    /// <summary>
    /// Generate vertices for a simple Image.
    /// </summary>
    void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
    {
        Vector4 v  = GetDrawingDimensions(lPreserveAspect);
        var     uv = (sprite != null) ? DataUtility.GetOuterUV(sprite) : Vector4.zero;
        Vector4 v1 = v;

        //Debug.Log("uv::::" + uv + "  v:" + v+ "  center:"+ rectTransform.rect.center+ "  rect:" + rectTransform.rect);

        switch (mirrorType)
        {
        case MirrorType.Horizontal:
            v.z = (v.z + v.x) / 2;
            break;

        case MirrorType.Vertical:
            v.w = (v.w + v.y) / 2;
            break;

        case MirrorType.Quarter:
            v.z = (v.z + v.x) / 2;
            v.w = (v.w + v.y) / 2;
            break;

        default:
            break;
        }


        //v.w = (v.w + v.y) / 2;
        //Debug.Log("uv::::" + uv + "  v:" + v + "  center:" + rectTransform.rect.center + "  rect:" + rectTransform.rect);
        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);

        switch (mirrorType)
        {
        /// 1,2,5
        /// 0,3,4
        case MirrorType.Horizontal:
            vh.AddVert(new Vector3(v1.z, v1.y), color32, new Vector2(uv.x, uv.y));
            vh.AddVert(new Vector3(v1.z, v1.w), color32, new Vector2(uv.x, uv.w));
            vh.AddTriangle(3, 2, 5);
            vh.AddTriangle(5, 4, 3);
            break;

        //4,5
        //1,2
        //0,3
        case MirrorType.Vertical:
            vh.AddVert(new Vector3(v1.x, v1.w), color32, new Vector2(uv.x, uv.y));
            vh.AddVert(new Vector3(v1.z, v1.w), color32, new Vector2(uv.z, uv.y));
            vh.AddTriangle(1, 4, 5);
            vh.AddTriangle(5, 2, 1);
            break;

        /// 8,7,6
        /// 1,2,5
        /// 0,3,4
        case MirrorType.Quarter:
            vh.AddVert(new Vector3(v1.z, v1.y), color32, new Vector2(uv.x, uv.y));
            vh.AddVert(new Vector3(v1.z, v.w), color32, new Vector2(uv.x, uv.w));
            vh.AddTriangle(3, 2, 5);
            vh.AddTriangle(5, 4, 3);
            vh.AddVert(new Vector3(v1.z, v1.w), color32, new Vector2(uv.x, uv.y));
            vh.AddVert(new Vector3(v.z, v1.w), color32, new Vector2(uv.z, uv.y));
            vh.AddVert(new Vector3(v1.x, v1.w), color32, new Vector2(uv.x, uv.y));
            vh.AddTriangle(6, 5, 2);
            vh.AddTriangle(2, 7, 6);
            vh.AddTriangle(7, 2, 1);
            vh.AddTriangle(1, 8, 7);
            break;

        default:
            break;
        }
    }
Exemplo n.º 54
0
 public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, float radius, Color32 color)
 {
     DrawPolygon(vh, p1, p2, radius, color, color);
 }
Exemplo n.º 55
0
 public static void DrawPolygon(VertexHelper vh, Vector3 p, float xRadius, float yRadius,
                                Color32 color, bool vertical = true)
 {
     DrawPolygon(vh, p, xRadius, yRadius, color, color, vertical);
 }
Exemplo n.º 56
0
        private static void AddSquare(Vector2 a, Vector2 b, Vector2 c, Vector2 d, Rect rectUV, Color32 color32, VertexHelper vh) {
            int v0 = AddVert(a.x, a.y, rectUV, color32, vh);
            int v1 = AddVert(b.x, b.y, rectUV, color32, vh);
            int v2 = AddVert(c.x, c.y, rectUV, color32, vh);
            int v3 = AddVert(d.x, d.y, rectUV, color32, vh);
 
            vh.AddTriangle(v0, v1, v2);
            vh.AddTriangle(v2, v3, v0);
        }
Exemplo n.º 57
0
 public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
                                Color32 color)
 {
     DrawPolygon(vh, p1, p2, p3, p4, color, color);
 }
Exemplo n.º 58
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            var rect = rectTransform.rect;
            var rectNew = rect;

            Color32 color32 = color;
            bool up = cutUL | cutUR;
            bool down = cutLL | cutLR;
            bool left = cutLL | cutUL;
            bool right = cutLR | cutUR;
            bool any = up | down;

            if (any && cornerSize.sqrMagnitude > 0)
            {

                //nibble off the sides
                vh.Clear();
                if (left)
                    rectNew.xMin += cornerSize.x;
                if (down)
                    rectNew.yMin += cornerSize.y;
                if (up)
                    rectNew.yMax -= cornerSize.y;
                if (right)
                    rectNew.xMax -= cornerSize.x;

                //add two squares to the main square
                Vector2 ul, ur, ll, lr;

                if (makeColumns)
                {
                    ul = new Vector2(rect.xMin, cutUL ? rectNew.yMax : rect.yMax);
                    ur = new Vector2(rect.xMax, cutUR ? rectNew.yMax : rect.yMax);
                    ll = new Vector2(rect.xMin, cutLL ? rectNew.yMin : rect.yMin);
                    lr = new Vector2(rect.xMax, cutLR ? rectNew.yMin : rect.yMin);

                    if (left)
                        AddSquare(
                            ll, ul,
                            new Vector2(rectNew.xMin, rect.yMax),
                            new Vector2(rectNew.xMin, rect.yMin),
                            rect, useColorUp ? colorUp : color32, vh);
                    if (right)
                        AddSquare(
                            ur, lr,
                            new Vector2(rectNew.xMax, rect.yMin),
                            new Vector2(rectNew.xMax, rect.yMax),
                            rect, useColorDown ? colorDown : color32, vh);
                }
                else
                {
                    ul = new Vector2(cutUL ? rectNew.xMin : rect.xMin, rect.yMax);
                    ur = new Vector2(cutUR ? rectNew.xMax : rect.xMax, rect.yMax);
                    ll = new Vector2(cutLL ? rectNew.xMin : rect.xMin, rect.yMin);
                    lr = new Vector2(cutLR ? rectNew.xMax : rect.xMax, rect.yMin);
                    if (down)
                        AddSquare(
                            lr, ll,
                            new Vector2(rect.xMin, rectNew.yMin),
                            new Vector2(rect.xMax, rectNew.yMin),
                            rect, useColorDown ? colorDown : color32, vh);
                    if (up)
                        AddSquare(
                            ul, ur,
                            new Vector2(rect.xMax, rectNew.yMax),
                            new Vector2(rect.xMin, rectNew.yMax),
                            rect, useColorUp ? colorUp : color32, vh);
                }

                //center
                if (makeColumns)
                    AddSquare(new Rect(rectNew.xMin, rect.yMin, rectNew.width, rect.height), rect, color32, vh);
                else
                    AddSquare(new Rect(rect.xMin, rectNew.yMin, rect.width, rectNew.height), rect, color32, vh);

            }
        }
Exemplo n.º 59
0
 public void ModifyMesh(VertexHelper vh)
 {
 }