Beispiel #1
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);
        }
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        if (_sprite == null)
        {
            return;
        }
        var spriteRect = _sprite.rect;
        var sizeDelta  = rectTransform.sizeDelta;
        var scale      = new Vector2(
            _sprite.pixelsPerUnit * sizeDelta.x / spriteRect.width,
            _sprite.pixelsPerUnit * sizeDelta.y / spriteRect.height);
        var offset = new Vector2(
            sizeDelta.x * (0.5f - rectTransform.pivot.x),
            sizeDelta.y * (0.5f - rectTransform.pivot.y));

        for (int i = 0; i < _sprite.vertices.Length; i++)
        {
            var v = new Vector2(
                _sprite.vertices[i].x * scale.x,
                _sprite.vertices[i].y * scale.y);
            v += offset;
            vh.AddVert(v, this.color, _sprite.uv[i]);
        }

        for (int i = 0; i < _sprite.triangles.Length; i += 3)
        {
            vh.AddTriangle(_sprite.triangles[i + 0], _sprite.triangles[i + 1], _sprite.triangles[i + 2]);
        }
    }
Beispiel #3
0
        protected virtual void AddDot(VertexHelper vh, Vector3 pt, float radius, Color32 color)
        {
            if (radius <= 0)
            {
                return;
            }
            vh.AddVert(new Vector3(pt.x, pt.y - radius, -pt.z), color, Vector2.zero);
            vh.AddVert(new Vector3(pt.x - radius, pt.y, -pt.z), color, Vector2.zero);
            vh.AddVert(new Vector3(pt.x, pt.y + radius, -pt.z), color, Vector2.zero);
            vh.AddVert(new Vector3(pt.x + radius, pt.y, -pt.z), color, Vector2.zero);

            var vertId = vh.currentVertCount - 1;

            vh.AddTriangle(vertId - 3, vertId - 2, vertId - 1);
            vh.AddTriangle(vertId - 1, vertId, vertId - 3);
        }
Beispiel #4
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        UIVertex[] quad = new UIVertex[4];

        var hyp = Vector2.Distance(P1, P2);

        var cos = (P1.x - P2.x) / hyp;
        var sin = (P1.y - P2.y) / hyp;

        var dx = LineWidth / 2 * sin;
        var dy = LineWidth / 2 * cos;

        quad[0].position = new Vector3(P1.x - dx, P1.y + dy, 0);
        quad[1].position = new Vector3(P1.x + dx, P1.y - dy, 0);
        quad[2].position = new Vector3(P2.x - dx, P2.y + dy, 0);
        quad[3].position = new Vector3(P2.x + dx, P2.y - dy, 0);

        quad[0].color = color;
        quad[1].color = color;
        quad[2].color = color;
        quad[3].color = color;

        quad[0].uv0 = new Vector2(0, 0);
        quad[1].uv0 = new Vector2(1, 0);
        quad[2].uv0 = new Vector2(1, 1);
        quad[3].uv0 = new Vector2(0, 1);

        for (int i = 0; i < 4; i++)
        {
            vh.AddVert(quad[i]);
        }
        vh.AddTriangle(0, 1, 2);
        vh.AddTriangle(1, 2, 3);
    }
    /// <summary>
    /// Callback function when a UI element needs to generate vertices.
    /// </summary>
    /// <param name="vh">VertexHelper utility.</param>
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        if (Mesh == null)
        {
            return;
        }
        // Get data from mesh
        var uvs = Mesh.uv;

        if (uvs.Length < Mesh.vertices.Length)
        {
            uvs = new Vector2[Mesh.vertices.Length];
        }
        // Get mesh bounds parameters
        Vector2 meshMin  = Mesh.bounds.min;
        Vector2 meshSize = Mesh.bounds.size;

        // Add scaled vertices
        for (int ii = 0; ii < Mesh.vertices.Length; ii++)
        {
            Vector2 v = Mesh.vertices[ii];
            v.x = (v.x - meshMin.x) / meshSize.x;
            v.y = (v.y - meshMin.y) / meshSize.y;
            v   = Vector2.Scale(v - rectTransform.pivot, rectTransform.rect.size);
            vh.AddVert(v, color, uvs[ii]);
        }
        // Add triangles
        var tris = Mesh.triangles;

        for (int ii = 0; ii < tris.Length; ii += 3)
        {
            vh.AddTriangle(tris[ii], tris[ii + 1], tris[ii + 2]);
        }
    }
Beispiel #6
0
    private void createLine(Vector3 start, Vector3 end, float thickness, Color32 color, VertexHelper vh)
    {
        Vector3 border = Vector3.one * thickness;

        border.y = 0;
        border.z = 0;

        vh.AddVert(start + border, color, Vector2.zero);
        vh.AddVert(start - border, color, Vector2.zero);
        vh.AddVert(end + border, color, Vector2.zero);
        vh.AddVert(end - border, color, Vector2.zero);

        vh.AddTriangle(m_lineIndex, m_lineIndex + 1, m_lineIndex + 2);
        vh.AddTriangle(m_lineIndex + 2, m_lineIndex + 3, m_lineIndex + 1);
        m_lineIndex += 4;
    }
        // Start is called before the first frame update
        // void Start()
        // {
        // }

        // Update is called once per frame
        // void Update()
        // {
        // }

        // TODO Noise texture?
        // public override Texture mainTexture {
        //     get {
        //         if (texture == null) {
        //             if (material != null && material.mainTexture != null) {
        //                 return material.mainTexture;
        //             }
        //             return s_WhiteTexture;
        //         }
        //         return texture;
        //     }
        // }

        protected override void OnPopulateMesh(VertexHelper vh)
        {
            var   rect = GetPixelAdjustedRect();
            float xmin = rect.xMin + margin.left;
            float xmax = rect.xMax - margin.right;
            float ymin = rect.yMin + margin.bottom;
            float ymax = rect.yMax - margin.top;
            float w    = (xmax - xmin);
            float h    = (ymax - ymin);

            Vector2[] verts =
            {
                new Vector2(xmin, ymin),
                new Vector2(xmin, ymax),
                new Vector2(xmax, ymax),
                new Vector2(xmax, ymin)
            };

            vh.Clear();

            UIVertex uiv = UIVertex.simpleVert;

            foreach (var v in verts)
            {
                uiv.position = new Vector2(v.x, v.y);
                uiv.uv0      = new Vector2((v.x - xmin) / w, (v.y - ymin) / h);
                uiv.uv1      = new Vector2(w, h);
                uiv.color    = color;
                vh.AddVert(uiv);
            }

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
Beispiel #8
0
        public static void AddTriangle(
            Vector2 p1,
            Vector2 p2,
            Vector2 p3,
            VertexHelper vh,
            Color vertexColor = default(Color),
            Vector2 uv        = default(Vector2))
        {
            uv = new Vector2(0.5f, 0.5f);
            int vertIdx = vh.currentVertCount;

            vh.AddVert(p1, vertexColor, uv);
            vh.AddVert(p2, vertexColor, uv);
            vh.AddVert(p3, vertexColor, uv);
            vh.AddTriangle(vertIdx, vertIdx + 1, vertIdx + 2);
        }
        private void FillOutside(VertexHelper vh, Vector3 initialPoint, int quarterIndex, int detail, ref int triangleIndex)
        {
            int startIndex = quarterIndex * detail;
            int endIndex   = (quarterIndex + 1) * detail;

            vh.AddVert(initialPoint, color32, uv);
            triangleIndex++;

            for (int i = startIndex + 1; i <= endIndex; i++, triangleIndex++)
            {
                float radians = i * deltaRadians;

                vh.AddVert(new Vector3(Mathf.Cos(radians) * width + deltaWidth, Mathf.Sin(radians) * height + deltaHeight, 0f), color32, uv);
                vh.AddTriangle(quarterIndex, triangleIndex - 1, triangleIndex);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Generate vertices for a simple Image.
        /// </summary>
        void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
        {
            Vector4 v  = GetDrawingDimensions(lPreserveAspect);
            var     uv = (activeSprite != null) ? DataUtility.GetOuterUV(activeSprite) : Vector4.zero;

            var color32 = color;

            vh.Clear();
            vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(uv.x, uv.y));
            vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(uv.x, uv.w));
            vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(uv.z, uv.w));
            vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(uv.z, uv.y));

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
Beispiel #11
0
        public static void AddRect(
            Bounds b,
            VertexHelper vh,
            Color vertexColor = default(Color),
            Vector2 uv        = default(Vector2))
        {
            uv = new Vector2(0.5f, 0.5f);
            int vertIdx = vh.currentVertCount;

            vh.AddVert(b.BottomLeft(), vertexColor, uv);
            vh.AddVert(b.TopLeft(), vertexColor, uv);
            vh.AddVert(b.BottomRight(), vertexColor, uv);
            vh.AddVert(b.TopRight(), vertexColor, uv);
            vh.AddTriangle(vertIdx, vertIdx + 1, vertIdx + 2);
            vh.AddTriangle(vertIdx + 2, vertIdx + 1, vertIdx + 3);
        }
Beispiel #12
0
        /// <summary>
        /// Adds two vertices that represent the given point to the vertex helper.
        /// </summary>
        /// <param name="point">The point we want to add to the line.</param>
        /// <param name="vh">The vertex helper utility that renders the line.</param>
        /// <param name="angle">The angle between this point and the next point. Prevents flat sections of the line.</param>
        private void DrawVerticesForPoint(Vector2 point, int index, VertexHelper vh, float angle)
        {
            // Initialize vertex object
            UIVertex vertex = UIVertex.simpleVert;

            vertex.color = GetColorAtVertex(index);

            // Create two vertices so that our line has the desired thickness
            // NOTE: A rotation is applied via Quaternion in order to prevent flat sections of the line from appearing
            vertex.position  = Quaternion.Euler(0, 0, angle) * new Vector3(-thickness / 2, 0);
            vertex.position += new Vector3(UnitWidth * point.x, UnitHeight * point.y);
            vh.AddVert(vertex);
            vertex.position  = Quaternion.Euler(0, 0, angle) * new Vector3(thickness / 2, 0);
            vertex.position += new Vector3(UnitWidth * point.x, UnitHeight * point.y);
            vh.AddVert(vertex);
        }
    private void DrawVerticesForPoint(Vector2 point, VertexHelper helper, float angle)
    {
        UIVertex vertex = UIVertex.simpleVert;

        vertex.color = color;

        vertex.position  = Quaternion.Euler(0, 0, angle) * new Vector3(-thickness / 2, 0);
        vertex.position += new Vector3(point.x, point.y);

        helper.AddVert(vertex);

        vertex.position  = Quaternion.Euler(0, 0, angle) * new Vector3(thickness / 2, 0);
        vertex.position += new Vector3(point.x, point.y);

        helper.AddVert(vertex);
    }
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        if (this.mesh == null)
        {
            return;
        }

        var color32 = this.color;

        vh.Clear();

        var vs = this.mesh.vertices;

        for (int i = 0; i < vs.Length; ++i)
        {
            var v = vs[i];
            vh.AddVert(new Vector3(v.x, v.y), color32, Vector2.zero);
        }

        var ts = this.mesh.triangles;

        for (int i = 0; i < ts.Length; i += 3)
        {
            var t1 = ts[i];
            var t2 = ts[i + 1];
            var t3 = ts[i + 2];

            vh.AddTriangle(t1, t2, t3);
        }
    }
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        Init();
        vh.Clear(); // これが無いと正常に描画されない。

        // 頂点の順番
        for (int i = 0; i < triangleList.Count / 3; i++)
        {
            int t0 = triangleList[i * 3 + 0];
            int t1 = triangleList[i * 3 + 1];
            int t2 = triangleList[i * 3 + 2];
            vh.AddTriangle(t0, t1, t2);
        }

        // UIVertex:各頂点の情報
        for (int i = 0; i < pointList.Count; i++)
        {
            var v = new UIVertex();
            v.position = pointList[i];
            v.uv0      = uvList[i];
            v.normal   = normalList[i];
            v.color    = colorList[i] * this.color;

            vh.AddVert(v);
        }
    }
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        Vector2[] points = null;
        Mesh      mesh   = new Mesh();

        var rect = rectTransform.rect;

        Collider2dPointsGetter.GetCircleCoordinates(rect.center, CalcRadius(), ref points, Proximity);
        //Collider2dPointsGetter.GetCircleCoordinates(rectTransform.anchoredPosition, 1f, ref points, Proximity);

        float ppu = (Camera.main.orthographicSize * 2) / Screen.height * 300;

        PolygonTriangulator.TriangulateAsLine(points, mesh, ppu, true);

        vh.Clear();

        for (int i = 0; i < mesh.vertices.Length; i++)
        {
            vh.AddVert(mesh.vertices[i], new Color32(1, 1, 1, 1), new Vector2(0.5f, 0.5f));
        }

        for (int i = 0; i < mesh.triangles.Length; i += 3)
        {
            vh.AddTriangle(mesh.triangles[i], mesh.triangles[i + 1], mesh.triangles[i + 2]);
        }
    }
Beispiel #17
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();

        if (points == null)
        {
            points = new Vector2[vertexCount];
        }

        var rect = GetPixelAdjustedRect();

        for (var i = 0; i < vertexCount; i++)
        {
            var t = i / (float)vertexCount;
            var p = spline.GetPoint(t);
            points[i] = p;

            vh.AddVert(
                new Vector3(rect.xMin + p.x * rect.width, rect.yMin + p.y * rect.height),
                Color.white,
                p);
        }

        var partitions = partitioning.Calculate(points);

        foreach (var convex in partitions)
        {
            var triangulations = triangulation.Calculate(convex);
            foreach (var(a, b, c) in triangulations)
            {
                vh.AddTriangle(a.Id, b.Id, c.Id);
            }
        }
    }
Beispiel #18
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        if (_targetMin == Vector3.zero && _targetMax == Vector3.zero)
        {
            base.OnPopulateMesh(vh);
            return;
        }
        vh.Clear();

        // 填充顶点
        UIVertex vert = UIVertex.simpleVert;

        vert.color = color;

        Vector2 selfPiovt = rectTransform.pivot;
        Rect    selfRect  = rectTransform.rect;
        float   outerLx   = -selfPiovt.x * selfRect.width;
        float   outerBy   = -selfPiovt.y * selfRect.height;
        float   outerRx   = (1 - selfPiovt.x) * selfRect.width;
        float   outerTy   = (1 - selfPiovt.y) * selfRect.height;

        // 0 - Outer:LT
        vert.position = new Vector3(outerLx, outerTy);
        vh.AddVert(vert);
        // 1 - Outer:RT
        vert.position = new Vector3(outerRx, outerTy);
        vh.AddVert(vert);
        // 2 - Outer:RB
        vert.position = new Vector3(outerRx, outerBy);
        vh.AddVert(vert);
        // 3 - Outer:LB
        vert.position = new Vector3(outerLx, outerBy);
        vh.AddVert(vert);

        // 4 - Inner:LT
        vert.position = new Vector3(_targetMin.x, _targetMax.y);
        vh.AddVert(vert);
        // 5 - Inner:RT
        vert.position = new Vector3(_targetMax.x, _targetMax.y);
        vh.AddVert(vert);
        // 6 - Inner:RB
        vert.position = new Vector3(_targetMax.x, _targetMin.y);
        vh.AddVert(vert);
        // 7 - Inner:LB
        vert.position = new Vector3(_targetMin.x, _targetMin.y);
        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);
    }
 public override void RebuildVertex(VertexHelper vh)
 {
     if (this.fadePatternData != null)
     {
         vh.Clear();
         Rect        pixelAdjustedRect = this.Target.GetPixelAdjustedRect();
         Color       color             = this.Target.get_color();
         DicingImage target            = this.Target as DicingImage;
         float       num  = pixelAdjustedRect.get_width() / ((float)this.fadePatternData.Width);
         float       num2 = pixelAdjustedRect.get_height() / ((float)this.fadePatternData.Height);
         int         num3 = 0;
         List <DicingTextureData.QuadVerts> list  = target.GetVerts(target.PatternData);
         List <DicingTextureData.QuadVerts> list2 = target.GetVerts(this.fadePatternData);
         int count = list.Count;
         if (count != list2.Count)
         {
             count = Mathf.Min(count, list2.Count);
             Debug.LogError(string.Format("Not equal texture size {0} and {1}", target.PatternData.Name, this.fadePatternData.Name));
         }
         for (int i = 0; i < count; i++)
         {
             DicingTextureData.QuadVerts verts  = list[i];
             DicingTextureData.QuadVerts verts2 = list2[i];
             if ((!target.SkipTransParentCell || !verts.isAllTransparent) || !verts2.isAllTransparent)
             {
                 Vector4 vector       = new Vector4(pixelAdjustedRect.get_x() + (num * verts.v.x), pixelAdjustedRect.get_y() + (num2 * verts.v.y), pixelAdjustedRect.get_x() + (num * verts.v.z), pixelAdjustedRect.get_y() + (num2 * verts.v.w));
                 Rect    uvRect       = verts.uvRect;
                 Rect    rect3        = verts2.uvRect;
                 float   introduced15 = uvRect.get_xMin();
                 float   introduced16 = rect3.get_xMin();
                 vh.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(introduced15, uvRect.get_yMin()), new Vector2(introduced16, rect3.get_yMin()), Vector3.get_zero(), Vector4.get_zero());
                 float introduced17 = uvRect.get_xMin();
                 float introduced18 = rect3.get_xMin();
                 vh.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(introduced17, uvRect.get_yMax()), new Vector2(introduced18, rect3.get_yMax()), Vector3.get_zero(), Vector4.get_zero());
                 float introduced19 = uvRect.get_xMax();
                 float introduced20 = rect3.get_xMax();
                 vh.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(introduced19, uvRect.get_yMax()), new Vector2(introduced20, rect3.get_yMax()), Vector3.get_zero(), Vector4.get_zero());
                 float introduced21 = uvRect.get_xMax();
                 float introduced22 = rect3.get_xMax();
                 vh.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(introduced21, uvRect.get_yMin()), new Vector2(introduced22, rect3.get_yMin()), Vector3.get_zero(), Vector4.get_zero());
                 vh.AddTriangle(num3, num3 + 1, num3 + 2);
                 vh.AddTriangle(num3 + 2, num3 + 3, num3);
                 num3 += 4;
             }
         }
     }
 }
Beispiel #20
0
 private static void AddVertexOfPositions(VertexHelper vh, UIVertex vert, params Vector2[] positions)
 {
     foreach (Vector2 pos in positions)
     {
         vert.position = pos;
         vh.AddVert(vert);
     }
 }
Beispiel #21
0
    void Start()
    {
        m = GetComponent <Mesh>();
        Color32 color32 = Color.red;

        using (var vh = new VertexHelper())
        {
            vh.AddVert(new Vector3(0, 0), color32, new Vector2(0f, 0f));
            vh.AddVert(new Vector3(0, 100), color32, new Vector2(0f, 1f));
            vh.AddVert(new Vector3(100, 100), color32, new Vector2(1f, 1f));
            vh.AddVert(new Vector3(100, 0), color32, new Vector2(1f, 0f));

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
            vh.FillMesh(m);
        }
    }
    void DrawVerticesForPoint(Vector2 point, VertexHelper vh, float angle)
    {
        UIVertex vertex = UIVertex.simpleVert;

        vertex.color = color;

        vertex.position  = Quaternion.Euler(0, 0, angle) * (new Vector3(0, -lineWidth / 2));
        vertex.position += new Vector3(unitWidth * point.x, unitHeight * point.y);

        vh.AddVert(vertex);
        myVertices.Add(new IntPoint((int)(vertex.position.x * clipperPrecision), (int)(vertex.position.y * clipperPrecision)));

        vertex.position  = Quaternion.Euler(0, 0, angle) * (new Vector3(0, lineWidth / 2));
        vertex.position += new Vector3(unitWidth * point.x, unitHeight * point.y);
        vh.AddVert(vertex);
        myVertices.Add(new IntPoint((int)(vertex.position.x * clipperPrecision), (int)(vertex.position.y * clipperPrecision)));
    }
Beispiel #23
0
        /// <summary>
        /// Generates the Verticies needed.
        /// </summary>
        /// <param name="vh">vertex helper</param>
        void GenerateSimpleSprite(VertexHelper vh)
        {
            var   r       = GetPixelAdjustedRect();
            var   v       = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);
            var   uv      = new Vector4(0, 0, 1, 1);
            float aa      = falloffDistance / 2f;
            var   color32 = this.color;

            vh.Clear();
            vh.AddVert(new Vector3(v.x - aa, v.y - aa), color32, new Vector2(uv.x, uv.y));
            vh.AddVert(new Vector3(v.x - aa, v.w + aa), color32, new Vector2(uv.x, uv.w));
            vh.AddVert(new Vector3(v.z + aa, v.w + aa), color32, new Vector2(uv.z, uv.w));
            vh.AddVert(new Vector3(v.z + aa, v.y - aa), color32, new Vector2(uv.z, uv.y));

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
Beispiel #24
0
    //绘制五边形
    private void DrawPentagon(VertexHelper vh)
    {
        Vector2 outVec;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, ScreenA, null, out outVec);

        Rect    pixelAdjustedRect = this.GetPixelAdjustedRect();
        Color32 color             = (Color32)this.color;

        vh.Clear();
        Vector2 top = new Vector2(pixelAdjustedRect.x, pixelAdjustedRect.y);
        float   dx  = pixelAdjustedRect.width / (maxStep * 2);
        float   dy  = pixelAdjustedRect.height / (maxStep * 2);

        //Vector2 top = new Vector2(outVec.x, outVec.y);
        //float dx = (ScreenB.x - ScreenA.x) / (maxStep * 2);
        //float dy = (ScreenB.y - ScreenA.y) / (maxStep * 2);



        float f = 1.0f / (2 * maxStep);

        for (int i = 0; i <= maxStep; i++)
        {
            if (i * 2 < maxStep)
            {
                float xdis = RunXDistance(i);
                float dis  = RunYDistance(i);
                vh.AddVert(new Vector3(top.x + xdis * dx, top.y + dis * dy), color, new Vector2(0, dis * f));
                vh.AddVert(new Vector3(top.x + (2 * maxStep - xdis) * dx, top.y + dis * dy), color, new Vector2(1, dis * f));
            }
            else
            {
                float dis  = 2 * maxStep - RunYDistance(maxStep - i);
                float xdis = RunXDistance(maxStep - i);
                vh.AddVert(new Vector3(top.x + (maxStep - i) * dx, top.y + dis * dy), color, new Vector2(0, dis * f));
                vh.AddVert(new Vector3(top.x + (2 * maxStep - xdis) * dx, top.y + dis * dy), color, new Vector2(1, dis * f));
            }
        }

        for (int i = 0; i < maxStep; i++)
        {
            vh.AddTriangle(2 * i, 2 * i + 1, 2 * (i + 1));
            vh.AddTriangle(2 * (i + 1), 2 * i + 1, 2 * (i + 1) + 1);
        }
    }
Beispiel #25
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();

            var r = GetPixelAdjustedRect();
            var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

            Color32 color32 = color;

            vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(0f, 0f));
            vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(0f, 1f));
            vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(1f, 1f));
            vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(1f, 0f));

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
Beispiel #26
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        RectTransform = GetComponent <RectTransform>();
        Renderer      = GetComponent <CanvasRenderer>();
        var rect  = RectTransform.rect;
        int width = (int)(rect.width / Resolution);

        vh.Clear();
        var   per           = 1f / ((float)width - 1);
        var   x             = 0f;
        float centerUVWidth = (1f - SideUV * 2);
        float sideWidth     = (SideWidth) / rect.width;

        if (SideWidth * 2 > rect.width)
        {
            sideWidth = 0.5f;
        }
        float centerWidth = (1f - sideWidth);
        float angle       = Angle * 100 / rect.width;

        for (int i = 0; i < width; i++)
        {
            var   quat = Quaternion.AngleAxis((x - 0.5f) * angle, new Vector3(0f, 0f, -1f));
            float uvX  = x;
            if (uvX < sideWidth)
            {
                uvX = uvX / sideWidth * SideUV;
            }
            else if (uvX < 1 - sideWidth)
            {
                uvX = SideUV + ((uvX - sideWidth) / centerWidth) * centerUVWidth;
            }
            else
            {
                uvX = (1f - SideUV) + ((uvX - (1f - sideWidth))) / sideWidth * SideUV;
            }
            vh.AddVert(quat * new Vector3(rect.xMin + x * rect.width, rect.yMin + 0f, 0f), this.color, new Vector2(uvX, 0f));
            vh.AddVert(quat * new Vector3(rect.xMin + x * rect.width, rect.yMin + rect.height, 0f), this.color, new Vector2(uvX, 1f));
            x += per;
            if (i < width - 1)
            {
                vh.AddTriangle(i * 2 + 1, i * 2 + 2, i * 2 + 0);
                vh.AddTriangle(i * 2 + 2, i * 2 + 1, i * 2 + 3);
            }
        }
    }
        private void FillInside(VertexHelper vh)
        {
            vh.AddVert(new Vector3(deltaWidth, deltaHeight, 0f), color32, uv);
            vh.AddVert(new Vector3(width + deltaWidth, deltaHeight, 0f), color32, uv);

            int triangleIndex = 2;

            for (int i = 1; i < detail; i++, triangleIndex++)
            {
                float radians = i * deltaRadians;

                vh.AddVert(new Vector3(Mathf.Cos(radians) * width + deltaWidth, Mathf.Sin(radians) * height + deltaHeight, 0f), color32, uv);
                vh.AddTriangle(triangleIndex, triangleIndex - 1, 0);
            }

            vh.AddTriangle(1, triangleIndex - 1, 0);
        }
Beispiel #28
0
 protected override void OnPopulateMesh(VertexHelper vh)
 {
     if (_vertices == null)
     {
         return;
     }
     vh.Clear();
     for (int i = 0; i < _vertices.Count; i += 4)
     {
         vh.AddVert(_vertices[i]);
         vh.AddVert(_vertices[i + 1]);
         vh.AddVert(_vertices[i + 2]);
         vh.AddVert(_vertices[i + 3]);
         vh.AddTriangle(i, i + 1, i + 2);
         vh.AddTriangle(i + 2, i + 3, i);
     }
 }
Beispiel #29
0
    private void CreateAndAdd(ref VertexHelper vertexHelper, float x, float y)
    {
        UIVertex vertex = UIVertex.simpleVert;

        vertex.color    = color;
        vertex.position = new Vector3(x, y);
        vertexHelper.AddVert(vertex);
    }
Beispiel #30
0
    private void AddVert(VertexHelper vh, Vector2 pos)
    {
        var vert = UIVertex.simpleVert;

        vert.position = pos;
        vert.color    = color;
        vh.AddVert(vert);
    }
Beispiel #31
0
    private void DrawCell(VertexHelper vh, int x, int y, int index)
    {
        float xPos = cellWidth * x;
        float yPos = cellHeight * y;

        UIVertex vertex = UIVertex.simpleVert;

        vertex.color = color;

        vertex.position = new Vector3(xPos, yPos);
        vh.AddVert(vertex);

        vertex.position = new Vector3(xPos, yPos + cellHeight);
        vh.AddVert(vertex);

        vertex.position = new Vector3(xPos + cellWidth, yPos + cellHeight);
        vh.AddVert(vertex);

        vertex.position = new Vector3(xPos + cellWidth, yPos);
        vh.AddVert(vertex);

        float widthSquared    = thickness * thickness;
        float distanceSquared = widthSquared / 2;
        float distance        = Mathf.Sqrt(distanceSquared);

        vertex.position = new Vector3(xPos + distance, yPos + distance);
        vh.AddVert(vertex);

        vertex.position = new Vector3(xPos + distance, yPos + cellHeight - distance);
        vh.AddVert(vertex);

        vertex.position = new Vector3(xPos + cellWidth - distance, yPos + cellHeight - distance);
        vh.AddVert(vertex);

        vertex.position = new Vector3(xPos + cellWidth - distance, yPos + distance);
        vh.AddVert(vertex);

        int offset = index * 8;

        // Left Edge
        vh.AddTriangle(offset + 0, offset + 1, offset + 5);
        vh.AddTriangle(offset + 5, offset + 4, offset + 0);

        // Top Edge
        vh.AddTriangle(offset + 1, offset + 2, offset + 6);
        vh.AddTriangle(offset + 6, offset + 5, offset + 1);

        // Right Edge
        vh.AddTriangle(offset + 2, offset + 3, offset + 7);
        vh.AddTriangle(offset + 7, offset + 6, offset + 2);

        // Bottom Edge
        vh.AddTriangle(offset + 3, offset + 0, offset + 4);
        vh.AddTriangle(offset + 4, offset + 7, offset + 3);
    }
        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);
        }
Beispiel #33
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;
 }