AddVert() 공개 메소드

Add a single vertex to the stream.

public AddVert ( UIVertex v ) : void
v UnityEngine.UIVertex
리턴 void
예제 #1
0
 protected override void OnPopulateMesh(Mesh toFill)
 {
     Texture mainTexture = this.mainTexture;
     if (mainTexture != null)
     {
         Vector4 zero = Vector4.zero;
         int num = Mathf.RoundToInt(mainTexture.width * this.uvRect.width);
         int num2 = Mathf.RoundToInt(mainTexture.height * this.uvRect.height);
         float num3 = ((num & 1) != 0) ? ((float) (num + 1)) : ((float) num);
         float num4 = ((num2 & 1) != 0) ? ((float) (num2 + 1)) : ((float) num2);
         zero.x = 0f;
         zero.y = 0f;
         zero.z = ((float) num) / num3;
         zero.w = ((float) num2) / num4;
         zero.x -= base.rectTransform.pivot.x;
         zero.y -= base.rectTransform.pivot.y;
         zero.z -= base.rectTransform.pivot.x;
         zero.w -= base.rectTransform.pivot.y;
         zero.x *= base.rectTransform.rect.width;
         zero.y *= base.rectTransform.rect.height;
         zero.z *= base.rectTransform.rect.width;
         zero.w *= base.rectTransform.rect.height;
         using (VertexHelper helper = new VertexHelper())
         {
             Color color = base.color;
             helper.AddVert(new Vector3(zero.x, zero.y), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
             helper.AddVert(new Vector3(zero.x, zero.w), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
             helper.AddVert(new Vector3(zero.z, zero.w), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
             helper.AddVert(new Vector3(zero.z, zero.y), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
             helper.AddTriangle(0, 1, 2);
             helper.AddTriangle(2, 3, 0);
             helper.FillMesh(toFill);
         }
     }
 }
예제 #2
0
    static void AddQuad(UnityEngine.UI.VertexHelper vertexHelper, Vector2 posMin, Vector2 posMax, Color32 color)
    {
        int startIndex = vertexHelper.currentVertCount;

        var v = UnityEngine.UIVertex.simpleVert;

        v.position = new Vector3(posMin.x, posMin.y, 0);
        v.color    = color;
        vertexHelper.AddVert(v);

        v.position = new Vector3(posMin.x, posMax.y, 0);
        v.color    = color;
        vertexHelper.AddVert(v);

        v.position = new Vector3(posMax.x, posMax.y, 0);
        v.color    = color;
        vertexHelper.AddVert(v);

        v.position = new Vector3(posMax.x, posMin.y, 0);
        v.color    = color;
        vertexHelper.AddVert(v);

        vertexHelper.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
        vertexHelper.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
    }
예제 #3
0
    /// <summary>
    /// Create an inflated mesh at a specified color and width.
    /// </summary>
    /// <param name="vh">The VertexHelpter from OnPopulateMesh().</param>
    /// <param name="lst">The line strip.</param>
    /// <param name="inf">The unit-inflation amount form line strip.</param>
    /// <param name="amt">The radius of how much to inflate the line strip.</param>
    /// <param name="c">The color of the inflated line mesh.</param>
    public static void CreateInflatedMesh(UnityEngine.UI.VertexHelper vh, List <Vector2> lst, List <Vector2> inf, float amt, Color c)
    {
        int ct = vh.currentVertCount;

        // Add the positive and the negative side - this inflates the line on both
        // side and makes the inflation amount a radius that's half the actual width.
        for (int i = 0; i < lst.Count; ++i)
        {
            UIVertex vt = new UIVertex();
            vt.position = lst[i] + inf[i] * amt;
            vt.color    = c;

            UIVertex vb = new UIVertex();
            vb.position = lst[i] - inf[i] * amt;
            vb.color    = c;

            vh.AddVert(vt);
            vh.AddVert(vb);
        }

        // Triangulate the vertices as quads.
        for (int i = 0; i < lst.Count - 1; ++i)
        {
            int t0 = ct + i * 2 + 0;
            int t1 = ct + i * 2 + 1;
            int t2 = ct + i * 2 + 2;
            int t3 = ct + i * 2 + 3;

            vh.AddTriangle(t0, t1, t2);
            vh.AddTriangle(t1, t3, t2);
        }
    }
예제 #4
0
    void EditMesh(VertexHelper vh)
    {
        vh.Clear();
        int count = vertexInfoList.Count;
        if (count < 3)
            return;//3개서부터 보임 

        for (int n = 0; n < vertexInfoList.Count; n++)
        {
            vh.AddVert(getRadiusPosition(vertexInfoList[n], n), checkVertexColor(vertexInfoList[n].color) ,Vector2.zero);
        }

        if (!innerPolygon)
        {
            for (int n = 0; n < count - 2; n++)
            {
                vh.AddTriangle(0, n + 1, n + 2);
            }
        }
        else
        {
            for (int n = 0; n < count; n++)
            {
                vh.AddVert(getRadiusPosition(vertexInfoList[n], n, width), checkVertexColor(vertexInfoList[n].color), Vector2.zero);
            }
            for (int n = 0; n < count; n++)
            {
                vh.AddTriangle(n, (n + 1) % count, count + (1 + n) % count);
                vh.AddTriangle(n, n + count, count + (1 + n) % count);
            }
        }
    }
예제 #5
0
 private static void AddQuad(VertexHelper vh, Vector2 posMin, Vector2 posMax, Color32 color, Vector2 uvMin, Vector2 uvMax)
 {
     int currentVertCount = vh.currentVertCount;
     vh.AddVert(new Vector3(posMin.x, posMin.y, 0f), color, new Vector2(uvMin.x, uvMin.y));
     vh.AddVert(new Vector3(posMin.x, posMax.y, 0f), color, new Vector2(uvMin.x, uvMax.y));
     vh.AddVert(new Vector3(posMax.x, posMax.y, 0f), color, new Vector2(uvMax.x, uvMax.y));
     vh.AddVert(new Vector3(posMax.x, posMin.y, 0f), color, new Vector2(uvMax.x, uvMin.y));
     vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
     vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
 }
예제 #6
0
    protected override void OnPopulateMesh(Mesh m)
    {
        Vector2 corner1 = new Vector2(0f, 0f);
        Vector2 corner2 = new Vector2(1f, 1f);

        corner1.x -= rectTransform.pivot.x;
        corner1.y -= rectTransform.pivot.y;
        corner2.x -= rectTransform.pivot.x;
        corner2.y -= rectTransform.pivot.y;

        corner1.x *= rectTransform.rect.width;
        corner1.y *= rectTransform.rect.height;
        corner2.x *= rectTransform.rect.width;
        corner2.y *= rectTransform.rect.height;

        Vector2 dc=corner2-corner1;
        Vector4 uv = sprite == null ? Vector4.zero : DataUtility.GetOuterUV(sprite);
        Vector2 uvz=new Vector2(uv.x, uv.y);
        Vector2 duv=new Vector2(uv.z, uv.w)-uvz;
        using (var vh = new VertexHelper())
        {
            float dx=1.0f/(float)(numdef);
            int numer=0;
            for(int yy=0;yy<numdef;yy++)
            for(int xx=0;xx<numdef;xx++)
            {
                Vector2 c1 = corner1+new Vector2(xx*dc.x*dx, yy*dc.y*dx);
                Vector2 c2 = corner1+new Vector2((xx+1)*dc.x,(yy+1)*dc.y)*dx;

                float rx1=dx*xx;
                float rx2=dx*(xx+1);
                float ry1=dx*yy;
                float ry2=dx*(yy+1);
                rx1*=rx1;
                rx2*=rx2;
                ry1=Mathf.Sqrt(ry1);
                ry2=Mathf.Sqrt(ry2);
                Vector2 uv0 =uvz+new Vector2(rx1*duv.x,ry1*duv.y);
                Vector2 uv1 =uvz+new Vector2(rx2*duv.x,ry2*duv.y);
            vh.AddVert(new Vector3(c1.x, c1.y), color, uv0);
            vh.AddVert(new Vector3(c1.x, c2.y), color, new Vector2(uv0.x, uv1.y));
            vh.AddVert(new Vector3(c2.x, c2.y), color, uv1);
            vh.AddVert(new Vector3(c2.x, c1.y), color, new Vector2(uv1.x, uv0.y));
                vh.AddTriangle(0+numer*4, 1+numer*4, 2+numer*4);
                vh.AddTriangle(2+numer*4, 3+numer*4, 0+numer*4);
                numer++;
            }

            vh.FillMesh(m);
        }
    }
예제 #7
0
        /// <summary>
        /// Fill the vertex buffer data.
        /// </summary>
        protected virtual void OnPopulateMesh(VertexHelper vh)
        {
            var r = GetPixelAdjustedRect();
            var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

            Color32 color32 = color;

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

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
        /// <summary>
        /// Generate vertices for a simple Image.
        /// </summary>
        void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
        {
            Vector4 v  = GetDrawingDimensions(lPreserveAspect);
            var     uv = (activeSprite != null) ? Sprites.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);
        }
	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);

		}

	}
예제 #10
0
 static public int AddVert__VertexHelper__Vector3__Color32__Vector2__Vector2__Vector2__Vector2__Vector3__Vector4(IntPtr l)
 {
     try {
         UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
         UnityEngine.Vector3         a2;
         checkType(l, 2, out a2);
         UnityEngine.Color32 a3;
         checkValueType(l, 3, out a3);
         UnityEngine.Vector2 a4;
         checkType(l, 4, out a4);
         UnityEngine.Vector2 a5;
         checkType(l, 5, out a5);
         UnityEngine.Vector2 a6;
         checkType(l, 6, out a6);
         UnityEngine.Vector2 a7;
         checkType(l, 7, out a7);
         UnityEngine.Vector3 a8;
         checkType(l, 8, out a8);
         UnityEngine.Vector4 a9;
         checkType(l, 9, out a9);
         self.AddVert(a2, a3, a4, a5, a6, a7, a8, a9);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #11
0
        protected virtual void OnPopulateMesh(Mesh m)
        {
            Rect    pixelAdjustedRect = this.GetPixelAdjustedRect();
            Vector4 vector            = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
            Color32 color             = this.color;

            using (VertexHelper helper = new VertexHelper())
            {
                helper.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(0f, 0f));
                helper.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(0f, 1f));
                helper.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(1f, 1f));
                helper.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(1f, 0f));
                helper.AddTriangle(0, 1, 2);
                helper.AddTriangle(2, 3, 0);
                helper.FillMesh(m);
            }
        }
예제 #12
0
        private void GenerateSimpleSprite(Mesh toFill, bool lPreserveAspect)
        {
            Vector4 drawingDimensions = this.GetDrawingDimensions(lPreserveAspect);
            Vector4 vector2           = (this.overrideSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);
            Color   color             = base.color;

            using (VertexHelper helper = new VertexHelper())
            {
                helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), color, new Vector2(vector2.x, vector2.y));
                helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), color, new Vector2(vector2.x, vector2.w));
                helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), color, new Vector2(vector2.z, vector2.w));
                helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), color, new Vector2(vector2.z, vector2.y));
                helper.AddTriangle(0, 1, 2);
                helper.AddTriangle(2, 3, 0);
                helper.FillMesh(toFill);
            }
        }
예제 #13
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture mainTexture = this.mainTexture;

            vh.Clear();
            if (mainTexture != null)
            {
                Rect    pixelAdjustedRect = GetPixelAdjustedRect();
                Vector4 vector            = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
                Color   color             = base.color;
                vh.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(m_UVRect.xMin, m_UVRect.yMin));
                vh.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(m_UVRect.xMin, m_UVRect.yMax));
                vh.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(m_UVRect.xMax, m_UVRect.yMax));
                vh.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(m_UVRect.xMax, m_UVRect.yMin));
                vh.AddTriangle(0, 1, 2);
                vh.AddTriangle(2, 3, 0);
            }
        }
예제 #14
0
 private static void AddQuad(VertexHelper vh, Vector3[] quadPositions, Color32 color, Vector3[] quadUVs)
 {
     int currentVertCount = vh.currentVertCount;
     for (int i = 0; i < 4; i++)
     {
         vh.AddVert(quadPositions[i], color, quadUVs[i]);
     }
     vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
     vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
 }
예제 #15
0
 protected override void OnPopulateMesh(VertexHelper vh)
 {
     Texture mainTexture = this.mainTexture;
     vh.Clear();
     if (mainTexture != null)
     {
         Rect pixelAdjustedRect = base.GetPixelAdjustedRect();
         Vector4 vector = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
         float num = mainTexture.width * mainTexture.texelSize.x;
         float num2 = mainTexture.height * mainTexture.texelSize.y;
         Color color = this.color;
         vh.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(this.m_UVRect.xMin * num, this.m_UVRect.yMin * num2));
         vh.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(this.m_UVRect.xMin * num, this.m_UVRect.yMax * num2));
         vh.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(this.m_UVRect.xMax * num, this.m_UVRect.yMax * num2));
         vh.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(this.m_UVRect.xMax * num, this.m_UVRect.yMin * num2));
         vh.AddTriangle(0, 1, 2);
         vh.AddTriangle(2, 3, 0);
     }
 }
예제 #16
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture mainTexture = this.mainTexture;

            vh.Clear();
            if (mainTexture != null)
            {
                Rect    pixelAdjustedRect = base.GetPixelAdjustedRect();
                Vector4 vector            = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
                float   num   = (float)mainTexture.width * mainTexture.texelSize.x;
                float   num2  = (float)mainTexture.height * mainTexture.texelSize.y;
                Color   color = this.color;
                vh.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(this.m_UVRect.xMin * num, this.m_UVRect.yMin * num2));
                vh.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(this.m_UVRect.xMin * num, this.m_UVRect.yMax * num2));
                vh.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(this.m_UVRect.xMax * num, this.m_UVRect.yMax * num2));
                vh.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(this.m_UVRect.xMax * num, this.m_UVRect.yMin * num2));
                vh.AddTriangle(0, 1, 2);
                vh.AddTriangle(2, 3, 0);
            }
        }
예제 #17
0
        private static void AddQuad(VertexHelper vertexHelper, Vector3[] quadPositions, Color32 color, Vector3[] quadUVs)
        {
            int currentVertCount = vertexHelper.currentVertCount;

            for (int i = 0; i < 4; i++)
            {
                vertexHelper.AddVert(quadPositions[i], color, quadUVs[i]);
            }
            vertexHelper.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
            vertexHelper.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
        }
예제 #18
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture mainTexture = this.mainTexture;

            vh.Clear();
            if (!((Object)mainTexture != (Object)null))
            {
                return;
            }
            Rect    pixelAdjustedRect = this.GetPixelAdjustedRect();
            Vector4 vector4           = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
            Color   color             = this.color;

            vh.AddVert(new Vector3(vector4.x, vector4.y), (Color32)color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
            vh.AddVert(new Vector3(vector4.x, vector4.w), (Color32)color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
            vh.AddVert(new Vector3(vector4.z, vector4.w), (Color32)color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
            vh.AddVert(new Vector3(vector4.z, vector4.y), (Color32)color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
 static public int AddVert(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
             UnityEngine.UIVertex        a1;
             checkValueType(l, 2, out a1);
             self.AddVert(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
             UnityEngine.Vector3         a1;
             checkType(l, 2, out a1);
             UnityEngine.Color32 a2;
             checkValueType(l, 3, out a2);
             UnityEngine.Vector2 a3;
             checkType(l, 4, out a3);
             self.AddVert(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 7)
         {
             UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
             UnityEngine.Vector3         a1;
             checkType(l, 2, out a1);
             UnityEngine.Color32 a2;
             checkValueType(l, 3, out a2);
             UnityEngine.Vector2 a3;
             checkType(l, 4, out a3);
             UnityEngine.Vector2 a4;
             checkType(l, 5, out a4);
             UnityEngine.Vector3 a5;
             checkType(l, 6, out a5);
             UnityEngine.Vector4 a6;
             checkType(l, 7, out a6);
             self.AddVert(a1, a2, a3, a4, a5, a6);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #20
0
파일: Image.cs 프로젝트: Vin129/Unity_UGUI
        static void AddQuad(VertexHelper vertexHelper, Vector3[] quadPositions, Color32 color, Vector3[] quadUVs)
        {
            int startIndex = vertexHelper.currentVertCount;

            for (int i = 0; i < 4; ++i)
            {
                vertexHelper.AddVert(quadPositions[i], color, quadUVs[i]);
            }

            vertexHelper.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
            vertexHelper.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
        }
예제 #21
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;

            vh.Clear();
            if (tex != null)
            {
                var r = GetPixelAdjustedRect();
                var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

                {
                    var color32 = color;
                    vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(m_UVRect.xMin, m_UVRect.yMin));
                    vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(m_UVRect.xMin, m_UVRect.yMax));
                    vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(m_UVRect.xMax, m_UVRect.yMax));
                    vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(m_UVRect.xMax, m_UVRect.yMin));

                    vh.AddTriangle(0, 1, 2);
                    vh.AddTriangle(2, 3, 0);
                }
            }
        }
예제 #22
0
 static public int AddVert__UIVertex(IntPtr l)
 {
     try {
         UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
         UnityEngine.UIVertex        a1;
         checkValueType(l, 2, out a1);
         self.AddVert(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #23
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture mainTexture = this.mainTexture;

            if (mainTexture != null)
            {
                Vector4 zero = Vector4.zero;
                int     num  = Mathf.RoundToInt(mainTexture.width * this.uvRect.width);
                int     num2 = Mathf.RoundToInt(mainTexture.height * this.uvRect.height);
                float   num3 = ((num & 1) != 0) ? ((float)(num + 1)) : ((float)num);
                float   num4 = ((num2 & 1) != 0) ? ((float)(num2 + 1)) : ((float)num2);
                zero.x  = 0f;
                zero.y  = 0f;
                zero.z  = ((float)num) / num3;
                zero.w  = ((float)num2) / num4;
                zero.x -= base.rectTransform.pivot.x;
                zero.y -= base.rectTransform.pivot.y;
                zero.z -= base.rectTransform.pivot.x;
                zero.w -= base.rectTransform.pivot.y;
                zero.x *= base.rectTransform.rect.width;
                zero.y *= base.rectTransform.rect.height;
                zero.z *= base.rectTransform.rect.width;
                zero.w *= base.rectTransform.rect.height;
                using (VertexHelper helper = new VertexHelper())
                {
                    Color color = base.color;
                    helper.AddVert(new Vector3(zero.x, zero.y), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
                    helper.AddVert(new Vector3(zero.x, zero.w), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
                    helper.AddVert(new Vector3(zero.z, zero.w), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
                    helper.AddVert(new Vector3(zero.z, zero.y), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
                    helper.AddTriangle(0, 1, 2);
                    helper.AddTriangle(2, 3, 0);
                    helper.FillMesh(toFill);
                }
            }
        }
예제 #24
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();
            if (mVertices != null && mTriangles != null)
            {
                for (int i = 0; i < mVertices.Length; i++)
                {
                    vh.AddVert(mVertices[i], mColors[i], new Vector2(0, 0));
                }

                for (int i = 0; i < mTriangles.Length; i += 3)
                {
                    vh.AddTriangle(mTriangles[i], mTriangles[i + 1], mTriangles[i + 2]);
                }
            }
        }
예제 #25
0
 protected override void OnPopulateMesh(VertexHelper vh)
 {
     if ((this._targetMin == Vector3.zero) && (this._targetMax == Vector3.zero))
     {
         base.OnPopulateMesh(vh);
     }
     else
     {
         vh.Clear();
         UIVertex simpleVert = UIVertex.simpleVert;
         simpleVert.color = this.get_color();
         Vector2 pivot = base.get_rectTransform().pivot;
         Rect    rect  = base.get_rectTransform().rect;
         float   x     = -pivot.x * rect.width;
         float   y     = -pivot.y * rect.height;
         float   num3  = (1f - pivot.x) * rect.width;
         float   num4  = (1f - pivot.y) * rect.height;
         simpleVert.position = new Vector3(x, num4);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(num3, num4);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(num3, y);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(x, y);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(this._targetMin.x, this._targetMax.y);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(this._targetMax.x, this._targetMax.y);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(this._targetMax.x, this._targetMin.y);
         vh.AddVert(simpleVert);
         simpleVert.position = new Vector3(this._targetMin.x, this._targetMin.y);
         vh.AddVert(simpleVert);
         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);
     }
 }
예제 #26
0
 static public int AddVert__Vector3__Color32__Vector2(IntPtr l)
 {
     try {
         UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
         UnityEngine.Vector3         a1;
         checkType(l, 2, out a1);
         UnityEngine.Color32 a2;
         checkValueType(l, 3, out a2);
         UnityEngine.Vector2 a3;
         checkType(l, 4, out a3);
         self.AddVert(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #27
0
        void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
        {
            Vector4 v       = GetDrawingDimensions(lPreserveAspect);
            var     color32 = color;

            float width  = v.z - v.x;
            float height = v.w - v.y;

            //将sprite.pivot进行归一化
            Vector2 spritePivot = new Vector2(sprite.pivot.x / sprite.rect.width, sprite.pivot.y / sprite.rect.height);
            Vector2 pivotOffset = Vector2.Scale(spritePivot - rectTransform.pivot, new Vector2(width, height));

            Vector3 scale = new Vector3(1, 1, 1);

            scale.x = width / sprite.bounds.size.x;
            scale.y = height / sprite.bounds.size.y;
            Matrix4x4 trsMT = Matrix4x4.TRS(pivotOffset, Quaternion.identity, scale);

            vh.Clear();
            m_Polygon.Clear();
            for (int i = 0; i < sprite.vertices.Length; i++)
            {
                Vector2 vert = trsMT.MultiplyPoint3x4(sprite.vertices[i]);
                m_Polygon.Add(vert);
                if (i == 0)
                {
                    m_MeshBounds = new Bounds(vert, Vector3.zero);
                }
                else
                {
                    m_MeshBounds.Encapsulate(vert);
                }
                vh.AddVert(vert, color32, sprite.uv[i]);
            }

            for (int i = 0; i < sprite.triangles.Length; i += 3)
            {
                vh.AddTriangle(sprite.triangles[i], sprite.triangles[i + 1], sprite.triangles[i + 2]);
            }
        }
예제 #28
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();
            if (mesh == null)
            {
                return;
            }

            Vector3[] vertices  = mesh.vertices;
            int[]     triangles = mesh.triangles;
            Color[]   colors    = mesh.colors;
            Vector2[] uvs       = mesh.uv;

            for (int i = 0; i < vertices.Length; i++)
            {
                vh.AddVert(vertices[i], colors[i], uvs[i]);
            }
            for (int i = 0; i < triangles.Length; i += 3)
            {
                vh.AddTriangle(triangles[i], triangles[i + 1], triangles[i + 2]);
            }
        }
예제 #29
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;

            vh.Clear();
            if (tex != null)
            {
                Rect r = GetPixelAdjustedRect();
                Vector4 v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

                Vector2 radius = new Vector2((v.z - v.x), (v.w - v.y)) * 0.5f;
                Vector3 center = new Vector3(v.x + radius.x, v.y + radius.y);

                // Place center vertices
                float distance = 0;
                for (int sideIndex = 0; sideIndex < slider.Corners; sideIndex++)
                {
                    float angle = ((float)sideIndex / slider.Corners);
                    angle = (angle + ((float)(sideIndex + 1) / slider.Corners)) / 2f; // get center
                    vh.AddVert(center, GetColor(angle, distance), new Vector2(0.25f, 0.25f));
                }

                int previousCorner = 0;
                int currentCorner = slider.Corners;
                for (int depthIndex = 1; depthIndex < GetMinimum(ValueType2); depthIndex++)
                {
                    // Place Top vert (Triangle: 3, 7, 14, etc)
                    Vector2 rad = (radius / (GetMinimum(ValueType2) - 1)) * depthIndex;
                    distance = (float)depthIndex / (GetMinimum(ValueType2) - 1);
                    Vector3 t = new Vector3(0, 1, 0);
                    vh.AddVert(center + new Vector3(t.x * rad.x, t.y * rad.y), GetColor(0, distance), new Vector2(0.25f, 0.25f));

                    for (int sideIndex = 1; sideIndex <= slider.Corners; sideIndex++)
                    {
                        float prevAngle = ((float)(sideIndex - 1) / slider.Corners);
                        float angle = ((float)sideIndex / slider.Corners);
                        Vector3 t2 = (Quaternion.AngleAxis(prevAngle * 360f, Vector3.forward) * new Vector3(0, 1, 0));
                        Vector3 temp = (Quaternion.AngleAxis(angle * 360f, Vector3.forward) * new Vector3(0, 1, 0));
                        Vector3 prevVert = center + new Vector3(t2.x * rad.x, t2.y * rad.y);
                        Vector3 nextVert = center + new Vector3(temp.x * rad.x, temp.y * rad.y);

                        for (int vertIndex = 1; vertIndex < depthIndex; vertIndex++)
                        {
                            // Places one vert and 2 trianlges
                            float a = Mathf.Lerp(prevAngle, angle, (float)vertIndex / depthIndex);
                            vh.AddVert(Vector3.Lerp(prevVert, nextVert, (float)vertIndex / depthIndex), GetColor(a, distance), new Vector2(0.25f, 0.25f));

                            vh.AddTriangle(currentCorner + (depthIndex * (sideIndex - 1)) + (vertIndex - 1),
                                currentCorner + (depthIndex * (sideIndex - 1)) + vertIndex,
                                previousCorner + ((depthIndex - 1) * (sideIndex - 1)) + vertIndex - 1);
                            vh.AddTriangle(currentCorner + (depthIndex * (sideIndex - 1)) + vertIndex,
                                previousCorner + ((depthIndex - 1) * (sideIndex - 1)) + vertIndex,
                                previousCorner + ((depthIndex - 1) * (sideIndex - 1)) + vertIndex - 1);
                        }

                        // Place corner vert
                        vh.AddVert(nextVert, GetColor(angle, distance), new Vector2(0.25f, 0.25f));
                        vh.AddTriangle(currentCorner + (depthIndex * sideIndex) - 1, currentCorner + (depthIndex * sideIndex), previousCorner + ((depthIndex - 1) * sideIndex));
                        if (previousCorner < slider.Corners)
                            previousCorner++;
                    }
                    previousCorner = currentCorner;
                    currentCorner += (slider.Corners * depthIndex) + 1;
                }
            }
        }
예제 #30
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;

            vh.Clear();
            if (tex != null)
            {
                Rect r = GetPixelAdjustedRect();
                Vector4 v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

                Vector2 whiteUV = new Vector2(0.25f, 0.25f);

                Vector3 lb;
                Vector3 lt;
                Vector3 rt;
                Vector3 rb;

                int vert = 0;

                if (borderSize > 0)
                {
                    vh.AddVert(new Vector3(v.x, v.y), color, whiteUV);
                    vh.AddVert(new Vector3(v.x, v.w), color, whiteUV);
                    vh.AddVert(new Vector3(v.z, v.w), color, whiteUV);
                    vh.AddVert(new Vector3(v.z, v.y), color, whiteUV);
                    vh.AddTriangle(vert, vert + 1, vert + 2);
                    vh.AddTriangle(vert + 2, vert + 3, vert);
                    vert += 4;

                    v.x += borderSize;
                    v.y += borderSize;
                    v.w -= borderSize;
                    v.z -= borderSize;
                }

                switch (direction)
                {
                    case Slider.Direction.BottomToTop:
                        lb = new Vector3(v.z, v.y);
                        lt = new Vector3(v.x, v.y);
                        rt = new Vector3(v.x, v.w);
                        rb = new Vector3(v.z, v.w);
                        break;
                    case Slider.Direction.LeftToRight:
                        lb = new Vector3(v.x, v.y);
                        lt = new Vector3(v.x, v.w);
                        rt = new Vector3(v.z, v.w);
                        rb = new Vector3(v.z, v.y);
                        break;
                    case Slider.Direction.RightToLeft:
                        lb = new Vector3(v.z, v.y);
                        lt = new Vector3(v.z, v.w);
                        rt = new Vector3(v.x, v.w);
                        rb = new Vector3(v.x, v.y);
                        break;
                    case Slider.Direction.TopToBottom:
                        lb = new Vector3(v.x, v.w);
                        lt = new Vector3(v.z, v.w);
                        rt = new Vector3(v.z, v.y);
                        rb = new Vector3(v.x, v.y);
                        break;
                    default:
                        throw new System.NotImplementedException(direction.ToString());
                }

                // Draw checkboard background if required
                if (displayCheckboard)
                {
                    switch (direction)
                    {
                        case Slider.Direction.BottomToTop:
                        case Slider.Direction.TopToBottom:
                            Vector2 tempSize = rectTransform.rect.size / 8;
                            r = new Rect(Vector2.zero, new Vector2(tempSize.y, tempSize.x));
                            break;
                        case Slider.Direction.LeftToRight:
                        case Slider.Direction.RightToLeft:
                            r = new Rect(Vector2.zero, rectTransform.rect.size / 8);
                            break;
                        default:
                            throw new System.NotImplementedException(direction.ToString());
                    }
                    r.max = r.max / checkBoardSize;

                    vh.AddVert(lb, new Color32(255, 255, 255, 255), new Vector2(r.xMin, r.yMin));
                    vh.AddVert(lt, new Color32(255, 255, 255, 255), new Vector2(r.xMin, r.yMax));
                    vh.AddVert(rt, new Color32(255, 255, 255, 255), new Vector2(r.xMax, r.yMax));
                    vh.AddVert(rb, new Color32(255, 255, 255, 255), new Vector2(r.xMax, r.yMin));
                    vh.AddTriangle(vert, vert + 1, vert + 2);
                    vh.AddTriangle(vert + 2, vert + 3, vert);
                    vert += 4;
                }

                for (int i = 0; i < colors.Length - 1; i++)
                {
                    // custom left bot and top
                    Vector3 clb = lb + ((rb - lb) * ((float)i / (colors.Length - 1)));
                    Vector3 clt = lt + ((rt - lt) * ((float)i / (colors.Length - 1)));

                    // custom right bot and top
                    Vector3 crb = lb + ((rb - lb) * ((float)(i + 1) / (colors.Length - 1)));
                    Vector3 crt = lt + ((rt - lt) * ((float)(i + 1) / (colors.Length - 1)));

                    // custom center bot and top
                    Vector3 ccb = clb + ((crb - clb) * centerPos);
                    Vector3 cct = clt + ((crt - clt) * centerPos);

                    if (gradient)
                    {
                        Color32 cColor = Color32.Lerp(colors[i].Color, colors[i + 1].Color, 0.5f);

                        vh.AddVert(clb, colors[i].Color, whiteUV);
                        vh.AddVert(clt, colors[i].Color, whiteUV);

                        vh.AddVert(ccb, cColor, whiteUV);
                        vh.AddVert(cct, cColor, whiteUV);

                        vh.AddVert(crb, colors[i + 1].Color, whiteUV);
                        vh.AddVert(crt, colors[i + 1].Color, whiteUV);

                        vh.AddTriangle(vert, vert + 1, vert + 3);
                        vh.AddTriangle(vert + 3, vert + 2, vert);
                        vh.AddTriangle(vert + 2, vert + 3, vert + 5);
                        vh.AddTriangle(vert + 5, vert + 4, vert + 2);
                        vert += 6;
                    }
                    else
                    {
                        vh.AddVert(clb, colors[i].Color, whiteUV);
                        vh.AddVert(clt, colors[i].Color, whiteUV);

                        vh.AddVert(ccb, colors[i].Color, whiteUV);
                        vh.AddVert(cct, colors[i].Color, whiteUV);

                        vh.AddVert(ccb, colors[i + 1].Color, whiteUV);
                        vh.AddVert(cct, colors[i + 1].Color, whiteUV);

                        vh.AddVert(crb, colors[i + 1].Color, whiteUV);
                        vh.AddVert(crt, colors[i + 1].Color, whiteUV);

                        vh.AddTriangle(vert, vert + 1, vert + 3);
                        vh.AddTriangle(vert + 3, vert + 2, vert);
                        vh.AddTriangle(vert + 4, vert + 5, vert + 7);
                        vh.AddTriangle(vert + 7, vert + 6, vert + 4);
                        vert += 8;
                    }

                }
            }
        }
예제 #31
0
 protected virtual void OnPopulateMesh(Mesh m)
 {
     Rect pixelAdjustedRect = this.GetPixelAdjustedRect();
     Vector4 vector = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
     Color32 color = this.color;
     using (VertexHelper helper = new VertexHelper())
     {
         helper.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(0f, 0f));
         helper.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(0f, 1f));
         helper.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(1f, 1f));
         helper.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(1f, 0f));
         helper.AddTriangle(0, 1, 2);
         helper.AddTriangle(2, 3, 0);
         helper.FillMesh(m);
     }
 }
예제 #32
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;

            vh.Clear();
            if (tex != null)
            {
                Rect r = GetPixelAdjustedRect();
                Vector4 v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);
                if (InverseX)
                {
                    float x = v.x;
                    v.x = v.z;
                    v.z = x;
                }
                if (InverseY)
                {
                    float y = v.y;
                    v.y = v.w;
                    v.w = y;
                }

                // Add vertices
                float xStep = (v.z - v.x) / (xSize - 1);
                float yStep = (v.w - v.y) / (ySize - 1);
                Vector3 pos = new Vector3(v.x, v.y);
                for (int x = 0; x < xSize; x++)
                {
                    for (int y = 0; y < ySize; y++)
                    {
                        for (int index = 0; index < colors.Length; index++)
                        {
                            vh.AddVert(pos, colors[index][y + (x * ySize)], new Vector2(0.25f, 0.25f));
                        }
                        pos.y += yStep;
                    }
                    pos.x += xStep;
                    pos.y = v.y;
                }

                // Add triangles
                for (int y = 0; y < ySize - 1; y++)
                {
                    for (int x = 0; x < xSize - 1; x++)
                    {
                        for (int index = 0; index < colors.Length; index++)
                        {
                            int pos1 = index + ((y + (x * ySize)) * colors.Length);
                            int pos2 = index + (((y + 1) + (x * ySize)) * colors.Length);
                            int pos3 = index + (((y + 1) + ((x + 1) * ySize)) * colors.Length);
                            int pos4 = index + ((y + ((x + 1) * ySize)) * colors.Length);

                            vh.AddTriangle(pos1, pos2, pos3);
                            vh.AddTriangle(pos3, pos4, pos1);
                        }
                    }
                }
            }
        }
예제 #33
0
        protected override void OnPopulateMesh(VertexHelper helper)
        {
            Ready();

            helper.Clear();

            step = 4; float value = 0;

            helper.AddVert(GetUIVertex(centre[0]));

            helper.AddVert(GetUIVertex(centre[1]));

            helper.AddVert(GetUIVertex(centre[2]));

            helper.AddVert(GetUIVertex(centre[3]));

            #region ¾ØÐÎ
            if (space.x - right > left)
            {
                helper.AddVert(GetUIVertex(new Vector2(left, 0) - offset));

                helper.AddVert(GetUIVertex(new Vector2(space.x - right, 0) - offset));

                helper.AddVert(GetUIVertex(new Vector2(space.x - right, space.y) - offset));

                helper.AddVert(GetUIVertex(new Vector2(left, space.y) - offset));

                helper.AddTriangle(step + 1, step, step + 2);

                helper.AddTriangle(step + 2, step, step + 3);

                step += 4;
            }

            if (space.y - top > bottom)
            {
                helper.AddVert(GetUIVertex(new Vector2(0, bottom) - offset));

                helper.AddVert(GetUIVertex(new Vector2(space.x, bottom) - offset));

                helper.AddVert(GetUIVertex(new Vector2(space.x, space.y - top) - offset));

                helper.AddVert(GetUIVertex(new Vector2(0, space.y - top) - offset));

                helper.AddTriangle(step + 1, step, step + 2);

                helper.AddTriangle(step + 2, step, step + 3);

                step += 4;
            }
            #endregion

            #region ËĽǰëÔ²
            AddSemiangle(helper, 0, right, top, ref value);

            AddSemiangle(helper, 1, left, top, ref value);

            AddSemiangle(helper, 2, left, bottom, ref value);

            AddSemiangle(helper, 3, right, bottom, ref value);
            #endregion
        }
예제 #34
0
파일: Image.cs 프로젝트: gdzzzyyy/UGUIlok
        static void AddQuad(VertexHelper vertexHelper, Vector2 posMin, Vector2 posMax, Color32 color, Vector2 uvMin, Vector2 uvMax)
        {
            int startIndex = vertexHelper.currentVertCount;

            vertexHelper.AddVert(new Vector3(posMin.x, posMin.y, 0), color, new Vector2(uvMin.x, uvMin.y));
            vertexHelper.AddVert(new Vector3(posMin.x, posMax.y, 0), color, new Vector2(uvMin.x, uvMax.y));
            vertexHelper.AddVert(new Vector3(posMax.x, posMax.y, 0), color, new Vector2(uvMax.x, uvMax.y));
            vertexHelper.AddVert(new Vector3(posMax.x, posMin.y, 0), color, new Vector2(uvMax.x, uvMin.y));

            vertexHelper.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
            vertexHelper.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
        }
예제 #35
0
파일: Image.cs 프로젝트: gdzzzyyy/UGUIlok
        /// <summary>
        /// Generate vertices for a simple Image.
        /// </summary>
        void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
        {
            Vector4 v = GetDrawingDimensions(lPreserveAspect);
            var uv = (overrideSprite != null) ? Sprites.DataUtility.GetOuterUV(overrideSprite) : Vector4.zero;

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

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
예제 #36
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();

            innerVertices.Clear();
            outterVertices.Clear();

            float degreeDelta  = (float)(2 * Mathf.PI / segements);
            int   curSegements = (int)(segements * fillPercent);

            float tw          = rectTransform.rect.width;
            float th          = rectTransform.rect.height;
            float outerRadius = rectTransform.pivot.x * tw;
            float innerRadius = rectTransform.pivot.x * tw - thickness;

            Vector4 uv = overrideSprite != null?DataUtility.GetOuterUV(overrideSprite) : Vector4.zero;

            float uvCenterX = (uv.x + uv.z) * 0.5f;
            float uvCenterY = (uv.y + uv.w) * 0.5f;
            float uvScaleX  = (uv.z - uv.x) / tw;
            float uvScaleY  = (uv.w - uv.y) / th;

            float    curDegree = 0;
            UIVertex uiVertex;
            int      verticeCount;
            int      triangleCount;
            Vector2  curVertice;

            if (fill) //圆形
            {
                curVertice        = Vector2.zero;
                verticeCount      = curSegements + 1;
                uiVertex          = new UIVertex();
                uiVertex.color    = color;
                uiVertex.position = curVertice;
                uiVertex.uv0      = new Vector2(curVertice.x * uvScaleX + uvCenterX, curVertice.y * uvScaleY + uvCenterY);
                vh.AddVert(uiVertex);

                for (int i = 1; i < verticeCount; i++)
                {
                    float cosA = Mathf.Cos(curDegree);
                    float sinA = Mathf.Sin(curDegree);
                    curVertice = new Vector2(cosA * outerRadius, sinA * outerRadius);
                    curDegree += degreeDelta;

                    uiVertex          = new UIVertex();
                    uiVertex.color    = color;
                    uiVertex.position = curVertice;
                    uiVertex.uv0      = new Vector2(curVertice.x * uvScaleX + uvCenterX, curVertice.y * uvScaleY + uvCenterY);
                    vh.AddVert(uiVertex);

                    outterVertices.Add(curVertice);
                }

                triangleCount = curSegements * 3;
                for (int i = 0, vIdx = 1; i < triangleCount - 3; i += 3, vIdx++)
                {
                    vh.AddTriangle(vIdx, 0, vIdx + 1);
                }
                if (fillPercent == 1)
                {
                    //首尾顶点相连
                    vh.AddTriangle(verticeCount - 1, 0, 1);
                }
            }
            else//圆环
            {
                verticeCount = curSegements * 2;
                for (int i = 0; i < verticeCount; i += 2)
                {
                    float cosA = Mathf.Cos(curDegree);
                    float sinA = Mathf.Sin(curDegree);
                    curDegree += degreeDelta;

                    curVertice        = new Vector3(cosA * innerRadius, sinA * innerRadius);
                    uiVertex          = new UIVertex();
                    uiVertex.color    = color;
                    uiVertex.position = curVertice;
                    uiVertex.uv0      = new Vector2(curVertice.x * uvScaleX + uvCenterX, curVertice.y * uvScaleY + uvCenterY);
                    vh.AddVert(uiVertex);
                    innerVertices.Add(curVertice);

                    curVertice        = new Vector3(cosA * outerRadius, sinA * outerRadius);
                    uiVertex          = new UIVertex();
                    uiVertex.color    = color;
                    uiVertex.position = curVertice;
                    uiVertex.uv0      = new Vector2(curVertice.x * uvScaleX + uvCenterX, curVertice.y * uvScaleY + uvCenterY);
                    vh.AddVert(uiVertex);
                    outterVertices.Add(curVertice);
                }

                triangleCount = curSegements * 3 * 2;
                for (int i = 0, vIdx = 0; i < triangleCount - 6; i += 6, vIdx += 2)
                {
                    vh.AddTriangle(vIdx + 1, vIdx, vIdx + 3);
                    vh.AddTriangle(vIdx, vIdx + 2, vIdx + 3);
                }
                if (fillPercent == 1)
                {
                    //首尾顶点相连
                    vh.AddTriangle(verticeCount - 1, verticeCount - 2, 1);
                    vh.AddTriangle(verticeCount - 2, 0, 1);
                }
            }
        }
예제 #37
0
 private void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
 {
     Vector4 drawingDimensions = this.GetDrawingDimensions(lPreserveAspect);
     Vector4 vector2 = (this.activeSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.activeSprite);
     Color color = this.color;
     vh.Clear();
     vh.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), color, new Vector2(vector2.x, vector2.y));
     vh.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), color, new Vector2(vector2.x, vector2.w));
     vh.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), color, new Vector2(vector2.z, vector2.w));
     vh.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), color, new Vector2(vector2.z, vector2.y));
     vh.AddTriangle(0, 1, 2);
     vh.AddTriangle(2, 3, 0);
 }
예제 #38
0
 private void GenerateSimpleSprite(VertexHelper vh, bool lPreserveAspect)
 {
   Vector4 drawingDimensions = this.GetDrawingDimensions(lPreserveAspect);
   Vector4 vector4 = !((UnityEngine.Object) this.overrideSprite != (UnityEngine.Object) null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);
   Color color = this.color;
   vh.Clear();
   vh.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), (Color32) color, new Vector2(vector4.x, vector4.y));
   vh.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), (Color32) color, new Vector2(vector4.x, vector4.w));
   vh.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), (Color32) color, new Vector2(vector4.z, vector4.w));
   vh.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), (Color32) color, new Vector2(vector4.z, vector4.y));
   vh.AddTriangle(0, 1, 2);
   vh.AddTriangle(2, 3, 0);
 }
        private void ModifyVertices(VertexHelper vh)
        {
			List<UIVertex> verts = new List<UIVertex>(vh.currentVertCount);
			vh.GetUIVertexStream(verts);
			vh.Clear();

            int step = 6;

			for (int i = 0; i < verts.Count; i += step) {
				//6 point
				var tl = multiplyColor(verts[i+0], colorTop);
				var tr = multiplyColor (verts [i+1], colorTop);
				var bl = multiplyColor (verts [i+4], colorBottom);
				var br = multiplyColor (verts [i + 3], colorBottom);
				var cl = calcCenterVertex(verts[i+0], verts [i+4]);
				var cr = calcCenterVertex (verts [i+1], verts [i+2]);

				vh.AddVert (tl);
				vh.AddVert (tr);
				vh.AddVert (cr);
				vh.AddVert (cr);
				vh.AddVert (cl);
				vh.AddVert (tl);

				vh.AddVert (cl);
				vh.AddVert (cr);
				vh.AddVert (br);
				vh.AddVert (br);
				vh.AddVert (bl);
				vh.AddVert (cl);
			}

			for (int i = 0; i < vh.currentVertCount; i += 12) {
				vh.AddTriangle (i + 0, i + 1, i + 2);
				vh.AddTriangle (i + 3, i + 4, i + 5);
				vh.AddTriangle (i + 6, i + 7, i + 8);
				vh.AddTriangle (i + 9, i + 10, i + 11);
			}
        }
예제 #40
0
파일: Graphic.cs 프로젝트: gdzzzyyy/UGUIlok
        /// <summary>
        /// Fill the vertex buffer data.
        /// </summary>
        protected virtual void OnPopulateMesh(VertexHelper vh)
        {
            var r = GetPixelAdjustedRect();
            var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

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

            vh.AddTriangle(0, 1, 2);
            vh.AddTriangle(2, 3, 0);
        }
예제 #41
0
 private static void AddQuad(VertexHelper vertexHelper, Vector3[] quadPositions, Color32 color, Vector3[] quadUVs)
 {
   int currentVertCount = vertexHelper.currentVertCount;
   for (int index = 0; index < 4; ++index)
     vertexHelper.AddVert(quadPositions[index], color, (Vector2) quadUVs[index]);
   vertexHelper.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
   vertexHelper.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
 }
예제 #42
0
 private void GenerateSimpleSprite(Mesh toFill, bool lPreserveAspect)
 {
     Vector4 drawingDimensions = this.GetDrawingDimensions(lPreserveAspect);
     Vector4 vector2 = (this.overrideSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);
     Color color = base.color;
     using (VertexHelper helper = new VertexHelper())
     {
         helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), color, new Vector2(vector2.x, vector2.y));
         helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), color, new Vector2(vector2.x, vector2.w));
         helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), color, new Vector2(vector2.z, vector2.w));
         helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), color, new Vector2(vector2.z, vector2.y));
         helper.AddTriangle(0, 1, 2);
         helper.AddTriangle(2, 3, 0);
         helper.FillMesh(toFill);
     }
 }
예제 #43
0
 static public int AddVert(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
             UnityEngine.UIVertex        a1;
             checkValueType(l, 2, out a1);
             self.AddVert(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
             UnityEngine.Vector3         a1;
             checkType(l, 2, out a1);
             UnityEngine.Color32 a2;
             checkValueType(l, 3, out a2);
             UnityEngine.Vector2 a3;
             checkType(l, 4, out a3);
             self.AddVert(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 7)
         {
             UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
             UnityEngine.Vector3         a1;
             checkType(l, 2, out a1);
             UnityEngine.Color32 a2;
             checkValueType(l, 3, out a2);
             UnityEngine.Vector2 a3;
             checkType(l, 4, out a3);
             UnityEngine.Vector2 a4;
             checkType(l, 5, out a4);
             UnityEngine.Vector3 a5;
             checkType(l, 6, out a5);
             UnityEngine.Vector4 a6;
             checkType(l, 7, out a6);
             self.AddVert(a1, a2, a3, a4, a5, a6);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function AddVert to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
예제 #44
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;
            vh.Clear();
            if (tex != null)
            {
                var r = GetPixelAdjustedRect();
                var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

                {
                    var color32 = color;
                    vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(m_UVRect.xMin, m_UVRect.yMin));
                    vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(m_UVRect.xMin, m_UVRect.yMax));
                    vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(m_UVRect.xMax, m_UVRect.yMax));
                    vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(m_UVRect.xMax, m_UVRect.yMin));

                    vh.AddTriangle(0, 1, 2);
                    vh.AddTriangle(2, 3, 0);
                }
            }
        }
예제 #45
0
파일: Image.cs 프로젝트: gdzzzyyy/UGUIlok
        static void AddQuad(VertexHelper vertexHelper, Vector3[] quadPositions, Color32 color, Vector3[] quadUVs)
        {
            int startIndex = vertexHelper.currentVertCount;

            for (int i = 0; i < 4; ++i)
                vertexHelper.AddVert(quadPositions[i], color, quadUVs[i]);

            vertexHelper.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
            vertexHelper.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
        }
예제 #46
0
 /// <summary>
 ///   <para>Callback function when a UI element needs to generate vertices.</para>
 /// </summary>
 /// <param name="m">Mesh to populate with UI data.</param>
 /// <param name="vh"></param>
 protected virtual void OnPopulateMesh(VertexHelper vh)
 {
   Rect pixelAdjustedRect = this.GetPixelAdjustedRect();
   Vector4 vector4 = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
   Color32 color = (Color32) this.color;
   vh.Clear();
   vh.AddVert(new Vector3(vector4.x, vector4.y), color, new Vector2(0.0f, 0.0f));
   vh.AddVert(new Vector3(vector4.x, vector4.w), color, new Vector2(0.0f, 1f));
   vh.AddVert(new Vector3(vector4.z, vector4.w), color, new Vector2(1f, 1f));
   vh.AddVert(new Vector3(vector4.z, vector4.y), color, new Vector2(1f, 0.0f));
   vh.AddTriangle(0, 1, 2);
   vh.AddTriangle(2, 3, 0);
 }
예제 #47
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                Vector4 v = Vector4.zero;
                Rect uvRect = new Rect(Vector2.zero, rectTransform.rect.size);
                uvRect.width = Mathf.Ceil(uvRect.width);
                uvRect.height = Mathf.Ceil(uvRect.height);

                int w = Mathf.RoundToInt(tex.width * uvRect.width);
                int h = Mathf.RoundToInt(tex.height * uvRect.height);

                float paddedW = ((w & 1) == 0) ? w : w + 1;
                float paddedH = ((h & 1) == 0) ? h : h + 1;

                v.x = 0f;
                v.y = 0f;
                v.z = w / paddedW;
                v.w = h / paddedH;

                v.x -= rectTransform.pivot.x;
                v.y -= rectTransform.pivot.y;
                v.z -= rectTransform.pivot.x;
                v.w -= rectTransform.pivot.y;

                v.x *= rectTransform.rect.width;
                v.y *= rectTransform.rect.height;
                v.z *= rectTransform.rect.width;
                v.w *= rectTransform.rect.height;

                using (var vh = new VertexHelper())
                {
                    // Add vertices
                    float xStep = (v.z - v.x) / (xSize - 1);
                    float yStep = (v.w - v.y) / (ySize - 1);
                    Vector3 pos = new Vector3(v.x, v.y);
                    for (int x = 0; x < xSize; x++)
                    {
                        for (int y = 0; y < ySize; y++)
                        {
                            for (int index = 0; index < colors.Length; index++)
                            {
                                vh.AddVert(pos, colors[index][y + (x * ySize)], new Vector2(0.25f, 0.25f));
                            }
                            pos.y += yStep;
                        }
                        pos.x += xStep;
                        pos.y = v.y;
                    }

                    // Add triangles
                    for (int y = 0; y < ySize - 1; y++)
                    {
                        for (int x = 0; x < xSize - 1; x++)
                        {
                            for (int index = 0; index < colors.Length; index++)
                            {
                                int pos1 = index + ((y + (x * ySize)) * colors.Length);
                                int pos2 = index + (((y + 1) + (x * ySize)) * colors.Length);
                                int pos3 = index + (((y + 1) + ((x + 1) * ySize)) * colors.Length);
                                int pos4 = index + ((y + ((x + 1) * ySize)) * colors.Length);

                                vh.AddTriangle(pos1, pos2, pos3);
                                vh.AddTriangle(pos3, pos4, pos1);
                            }
                        }
                    }

                    vh.FillMesh(toFill);
                }
            }
        }
예제 #48
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (sharedMesh == null) { base.OnPopulateMesh(vh); return; }
            vh.Clear();
        #endif

            Bounds bounds = sharedMesh.bounds;
            if(m_UsePivot)
            {             
                bounds.center += new Vector3((-0.5f + _vectorGraphics.pivotPoint.x) * bounds.size.x, (0.5f - _vectorGraphics.pivotPoint.y) * bounds.size.y, 0f);
            }

            Mesh mesh = sharedMesh;
            Vector3[] vertices = mesh.vertices;
            int[] triangles = mesh.triangles;
            Vector2[] uv = mesh.uv;
            Vector2[] uv2 = mesh.uv2;
            Color32[] colors = mesh.colors32;
            Vector3[] normals = mesh.normals;
            Vector4[] tangents = mesh.tangents;

            int tempVBOLength = mesh.vertexCount;
            UIVertex vertex = new UIVertex();

            if(m_Type == Type.Simple)
            {
                Vector4 v = GetDrawingDimensions(preserveAspect);

                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertex.position.x = v.x + InverseLerp(bounds.min.x, bounds.max.x, vertices[i].x) * v.z;
                    vertex.position.y = v.y + InverseLerp(bounds.min.y, bounds.max.y, vertices[i].y) * v.w;
                    vertex.color = colors[i] * color;
                    if(uv != null && i < uv.Length) { vertex.uv0 = uv[i]; }
                    if(uv2 != null && i < uv2.Length) { vertex.uv1 = uv2[i]; }
                    if(normals != null && i < normals.Length) { vertex.normal = normals[i]; }
                    if(tangents != null && i < tangents.Length) { vertex.tangent = tangents[i]; }

                    vh.AddVert(vertex);
                }
            } else {
                
                Vector4 v = GetDrawingDimensions(false);
                Vector2 normalizedPosition;
                
                // LEFT, BOTTOM, RIGHT, TOP
                Vector4 border = _vectorGraphics.border;
                
                Vector4 borderCalc = new Vector4(border.x + epsilon, border.y + epsilon, 1f - border.z - epsilon, 1f - border.w - epsilon);
                
                float left = v.x;
                float top = v.y;
                float right = v.x + v.z;
                float bottom = v.y + v.w;
                float size = canvas.referencePixelsPerUnit * vectorGraphics.scale * 100f;
                
                float minWidth = (border.x + border.z) * size;
                float minHeight = (border.y + border.w) * size;
                float scaleX = 0f; if(minWidth != 0f) scaleX = Mathf.Clamp01(v.z / minWidth);
                float scaleY = 0f; if(minHeight != 0f) scaleY = Mathf.Clamp01(v.w / minHeight);
                
                for(int i = 0; i < tempVBOLength; i++)
                {
                    normalizedPosition.x = InverseLerp(bounds.min.x, bounds.max.x, vertices[i].x);
                    normalizedPosition.y = InverseLerp(bounds.min.y, bounds.max.y, vertices[i].y);
                    
                    if(normalizedPosition.x <= borderCalc.x && border.x != 0f)
                    {
                        vertex.position.x = left + normalizedPosition.x * size * scaleX;
                    } else if(normalizedPosition.x >= borderCalc.z && border.z != 0f)
                    {
                        vertex.position.x = right - (1f - normalizedPosition.x) * size * scaleX;
                    } else {
                        vertex.position.x = v.x + normalizedPosition.x * v.z;
                    }
                    
                    if(normalizedPosition.y >= borderCalc.w && border.w != 0f)
                    {
                        vertex.position.y = bottom - (1f - normalizedPosition.y) * size * scaleY;
                    } else if(normalizedPosition.y <= borderCalc.y && border.y != 0f)
                    {
                        vertex.position.y = top + normalizedPosition.y * size * scaleY;
                    } else {
                        vertex.position.y = v.y + normalizedPosition.y * v.w;
                    }

                    vertex.color = colors[i] * color;
                    if(uv != null && i < uv.Length) { vertex.uv0 = uv[i]; }
                    if(uv2 != null && i < uv2.Length) { vertex.uv1 = uv2[i]; }
                    if(normals != null && i < normals.Length) { vertex.normal = normals[i]; }
                    if(tangents != null && i < tangents.Length) { vertex.tangent = tangents[i]; }

                    vh.AddVert(vertex);
                }
            }

            int triangleLength = triangles.Length;
            for(int i = 0; i < triangleLength; i +=3 )
            {
                vh.AddTriangle(triangles[i], triangles[i + 1], triangles[i + 2]);
            }

            #if UNITY_5_2_0 || UNITY_5_2_1
                vh.FillMesh(toFill);
            }
예제 #49
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:
            {
                float left  = _vertexList[0].position.x;
                float right = _vertexList[0].position.x;
                float x     = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    x = _vertexList[i].position.x;

                    if (x > right)
                    {
                        right = x;
                    }
                    else if (x < left)
                    {
                        left = x;
                    }
                }

                float    width  = 1f / (right - left);
                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.x - left) * width - Offset));

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

            case Type.Vertical:
            {
                float bottom = _vertexList[0].position.y;
                float top    = _vertexList[0].position.y;
                float y      = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    y = _vertexList[i].position.y;

                    if (y > top)
                    {
                        top = y;
                    }
                    else if (y < bottom)
                    {
                        bottom = y;
                    }
                }

                float    height = 1f / (top - bottom);
                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - bottom) * height - Offset));

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

            case Type.Diamond:
            {
                float bottom = _vertexList[0].position.y;
                float top    = _vertexList[0].position.y;
                float y      = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    y = _vertexList[i].position.y;

                    if (y > top)
                    {
                        top = y;
                    }
                    else if (y < bottom)
                    {
                        bottom = y;
                    }
                }

                float height = 1f / (top - bottom);

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

                float    center        = (bottom + top) / 2f;
                UIVertex centralVertex = new UIVertex();
                centralVertex.position = (Vector3.right + Vector3.up) * center + Vector3.forward * _vertexList[0].position.z;
                centralVertex.normal   = _vertexList[0].normal;
                centralVertex.color    = Color.white;
                helper.AddVert(centralVertex);

                for (int i = 1; i < nCount; i++)
                {
                    helper.AddTriangle(i - 1, i, nCount);
                }
                helper.AddTriangle(0, nCount - 1, nCount);

                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                  Vector3.Distance(vertex.position, centralVertex.position) * height - Offset));

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

            case Type.Radial:
            {
                float left   = _vertexList[0].position.x;
                float right  = _vertexList[0].position.x;
                float bottom = _vertexList[0].position.y;
                float top    = _vertexList[0].position.y;

                float x = 0f;
                float y = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    x = _vertexList[i].position.x;

                    if (x > right)
                    {
                        right = x;
                    }
                    else if (x < left)
                    {
                        left = x;
                    }

                    y = _vertexList[i].position.y;

                    if (y > top)
                    {
                        top = y;
                    }
                    else if (y < bottom)
                    {
                        bottom = y;
                    }
                }

                float width  = 1f / (right - left);
                float height = 1f / (top - bottom);

                helper.Clear();

                float    centerX       = (right + left) / 2f;
                float    centerY       = (bottom + top) / 2f;
                float    radiusX       = (right - left) / 2f;
                float    radiusY       = (top - bottom) / 2f;
                UIVertex centralVertex = new UIVertex();
                centralVertex.position = Vector3.right * centerX + Vector3.up * centerY + Vector3.forward * _vertexList[0].position.z;
                centralVertex.normal   = _vertexList[0].normal;
                centralVertex.color    = Color.white;

                int steps = 64;
                for (int i = 0; i < steps; i++)
                {
                    UIVertex curVertex = new UIVertex();
                    float    angle     = (float)i * 360f / (float)steps;
                    float    curX      = Mathf.Cos(Mathf.Deg2Rad * angle) * radiusX;
                    float    curY      = Mathf.Sin(Mathf.Deg2Rad * angle) * radiusY;

                    curVertex.position = Vector3.right * curX + Vector3.up * curY + Vector3.forward * _vertexList[0].position.z;
                    curVertex.normal   = _vertexList[0].normal;
                    curVertex.color    = Color.white;
                    helper.AddVert(curVertex);
                }

                helper.AddVert(centralVertex);

                for (int i = 1; i < steps; i++)
                {
                    helper.AddTriangle(i - 1, i, steps);
                }
                helper.AddTriangle(0, steps - 1, steps);

                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                  Mathf.Sqrt(
                                                      Mathf.Pow(Mathf.Abs(vertex.position.x - centerX) * width, 2f) +
                                                      Mathf.Pow(Mathf.Abs(vertex.position.y - centerY) * height, 2f)) * 2f - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;
            }
        }
예제 #50
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;

            vh.Clear();
            if (tex != null)
            {
                Rect r = GetPixelAdjustedRect();
                Vector4 v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

                Vector2 whiteUV = Vector2.zero;

                Vector3 lb = new Vector3(v.x, v.y);
                Vector3 lt = new Vector3(v.x, v.w);
                Vector3 rt = new Vector3(v.z, v.w);
                Vector3 rb = new Vector3(v.z, v.y);

                int vert = 0;

                vh.AddVert(lb, color, whiteUV);
                vh.AddVert(lt, color, whiteUV);
                vh.AddVert(rt, color, whiteUV);
                vh.AddVert(rb, color, whiteUV);

                vh.AddTriangle(0, 1, 2);
                vh.AddTriangle(2, 3, 0);
                vert += 4;

                float width = rb.x - lb.x;
                float height = lt.y - lb.y;

                Vector3 center = Vector3.Lerp(lb, rt, 0.5f);
                Rect rect = new Rect(lb, new Vector2(width, height));
                bool sizeIsCorrect = pixelsToDisplay.Length == (1 + (Mathf.CeilToInt(horizontalPixels) * 2)) * (1 + (Mathf.CeilToInt(verticalPixels) * 2));

                UIVertex[] vertices = new UIVertex[4];
                vertices[0].uv0 = whiteUV;
                vertices[1].uv0 = whiteUV;
                vertices[2].uv0 = whiteUV;
                vertices[3].uv0 = whiteUV;

                if (ExpectedVertices >= 65000)
                {
                    Debug.LogWarning("to many vertices, currently " + ExpectedVertices + "/64999. make sure the ColorEyedropperPreview displays less pixels. You can achiee this by either editing it's settings in the inspector or resizing the component", this);
                }
                else
                {
                    for (int radius = 1; radius <= Mathf.Ceil(horizontalPixels) || radius <= Mathf.Ceil(verticalPixels); radius++)
                    {
                        float offset = radius * (pixelSize + borderSize);

                        // Top side
                        for (int top = 0; top < radius * 2; top++)
                        {
                            float extraOffset = top * (pixelSize + borderSize);
                            Vector3 pos = center + new Vector3(-offset, offset) + new Vector3(extraOffset, 0);

                            if (SetQuadPositions(vertices, pos, rect))
                            {
                                Color32 c;
                                if (sizeIsCorrect && activated)
                                    c = pixelsToDisplay[(pixelsToDisplay.Length / 2) + (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * radius) - (radius - top)];
                                else
                                    c = InactiveColor;
                                SetQuadColors(vertices, c);
                                vh.AddUIVertexQuad(vertices);
                            }
                        }

                        // Right side
                        for (int right = 0; right < radius * 2; right++)
                        {
                            float extraOffset = right * (pixelSize + borderSize);
                            Vector3 pos = center + new Vector3(offset, offset) + new Vector3(0, -extraOffset);

                            if (SetQuadPositions(vertices, pos, rect))
                            {
                                Color32 c;
                                if (sizeIsCorrect && activated)
                                    c = pixelsToDisplay[(pixelsToDisplay.Length / 2) + radius + (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * (radius - right))];
                                else
                                    c = InactiveColor;
                                SetQuadColors(vertices, c);
                                vh.AddUIVertexQuad(vertices);
                            }
                        }

                        // Bot side
                        for (int bot = 0; bot < radius * 2; bot++)
                        {
                            float extraOffset = bot * (pixelSize + borderSize);
                            Vector3 pos = center + new Vector3(offset, -offset) + new Vector3(-extraOffset, 0);

                            if (SetQuadPositions(vertices, pos, rect))
                            {
                                Color32 c;
                                if (sizeIsCorrect && activated)
                                    c = pixelsToDisplay[(pixelsToDisplay.Length / 2) - (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * radius) + (radius - bot)];
                                else
                                    c = InactiveColor;
                                SetQuadColors(vertices, c);
                                vh.AddUIVertexQuad(vertices);
                            }
                        }

                        // Left side
                        for (int left = 0; left < radius * 2; left++)
                        {
                            float extraOffset = left * (pixelSize + borderSize);
                            Vector3 pos = center + new Vector3(-offset, -offset) + new Vector3(0, extraOffset);

                            if (SetQuadPositions(vertices, pos, rect))
                            {
                                Color32 c;
                                if (sizeIsCorrect && activated)
                                    c = pixelsToDisplay[(pixelsToDisplay.Length / 2) - radius - (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * (radius - left))];
                                else
                                    c = InactiveColor;
                                SetQuadColors(vertices, c);
                                vh.AddUIVertexQuad(vertices);
                            }
                        }
                    }
                }

                // Selectionbox
                if (SetQuadPositions(vertices, center, rect, borderSize + 1f))
                {
                    SetQuadColors(vertices, selectionBoxColor);
                    vh.AddUIVertexQuad(vertices);
                }

                // Center piece
                if (SetQuadPositions(vertices, center, rect))
                {
                    Color32 co;
                    if (sizeIsCorrect && activated)
                        co = pixelsToDisplay[pixelsToDisplay.Length / 2];
                    else
                        co = InactiveColor;
                    SetQuadColors(vertices, co);
                    vh.AddUIVertexQuad(vertices);
                }
            }
        }
예제 #51
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
            {
                return;
            }

            if (mesh == null)
            {
                mesh = new Mesh()
                {
                    name = "QShadow_Cached_Mesh"
                };
            }

            vh.FillMesh(mesh);
            Vector3[] vertices = mesh.vertices;
            Color[]   colors   = mesh.colors;
            Vector2[] uv0s     = mesh.uv;
            Vector2[] uv1s     = mesh.uv2;
            Vector2[] uv2s     = mesh.uv3;
            Vector2[] uv3s     = mesh.uv4;
            Vector3[] normals  = mesh.normals;
            Vector4[] tangents = mesh.tangents;
            Int32[]   triangls = mesh.triangles;

            if (!IsNumsEqual(vertices.Length, colors.Length, uv0s.Length, uv1s.Length, uv2s.Length, uv3s.Length, normals.Length, tangents.Length))
            {
                // Debug.LogWarning("It's a little odd that these length are not equal");
                return;
            }

            vh.Clear();

            Vector3[] newVertices = GetArrayCopies(vertices, 2);
            Color[]   newColors   = GetArrayCopies(colors, 2);
            Vector2[] newUv0s     = GetArrayCopies(uv0s, 2);
            Vector2[] newUv1s     = GetArrayCopies(uv1s, 2);
            Vector2[] newUv2s     = GetArrayCopies(uv2s, 2);
            Vector2[] newUv3s     = GetArrayCopies(uv3s, 2);
            Vector3[] newNormals  = GetArrayCopies(normals, 2);
            Vector4[] newTangents = GetArrayCopies(tangents, 2);

            for (int i = 0; i < vertices.Length; i++)
            {
                newVertices[i] = vertices[i] + new Vector3(effectDistance.x, effectDistance.y);
                newColors[i]   = effectColor;
                if (useGraphicAlpha)
                {
                    newColors[i].a = effectColor.a * colors[i].a;
                }
            }

            int[] newTriangles = new int[triangls.Length * 2];
            for (var i = 0; i < triangls.Length; i++)
            {
                newTriangles[i] = triangls[i];
                newTriangles[i + triangls.Length] = triangls[i] + vertices.Length;
            }

            for (var i = 0; i < newVertices.Length; i++)
            {
                vh.AddVert(newVertices[i], newColors[i], newUv0s[i], newUv1s[i], newUv2s[i], newUv3s[i], newNormals[i], newTangents[i]);
            }

            for (var i = 0; i < newTriangles.Length / 3; i++)
            {
                vh.AddTriangle(newTriangles[i * 3], newTriangles[i * 3 + 1], newTriangles[i * 3 + 2]);
            }
        }
예제 #52
0
    void FillJoint( VertexHelper vh, UIVertex vp0, UIVertex vp1, UIVertex[] prvLineVert, Color color)
    {
        Vector3 forwardWidthVector = vp1.position - vp0.position;
        Vector3 prvWidthVector = prvLineVert[1].position - prvLineVert[0].position;

        Vector3 prvVector = Vector3.Cross(prvWidthVector, new Vector3(0, 0, 1));
        
        Vector3 p0;
        Vector3 p1;
        Vector3 center = (vp0.position + vp1.position) / 2f;
                               
        if(Vector3.Dot(prvVector, forwardWidthVector) > 0)
        {
            p0 = vp1.position;
            p1 = prvLineVert[1].position;
        }
        else
        {
            p0 = vp0.position;
            p1 = prvLineVert[0].position;
        }

        Vector3 cp0 = (p0 + p1- center*2).normalized * width *0.5f + center;

        float angle = Vector3.Angle(p0 - center, p1 - center);

        int currentVert = vh.currentVertCount;
        int divideCount = (int)(angle / fillDivideAngle);
        if(divideCount == 0) { divideCount = 1; }

        float unit = 1f / divideCount;

        vh.AddVert(center, color, Vector2.zero);
        vh.AddVert(p0, color, Vector2.zero);
        for (int n = 0; n < divideCount; n++)
        {
            vh.AddVert(Curve.CalculateBezier(p0, p1, cp0, unit *(n+1)), color, Vector2.zero);
            vh.AddTriangle(currentVert, currentVert + 1 + n, currentVert + 2 + n);
        } 
    }
예제 #53
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            float dx = 0;

            float dy = 0;

            float width = rectTransform.rect.width / 2;

            float height = rectTransform.rect.height / 2;

            if (squircleType == Type.Classic)
            {
                a = width;
                b = height;
            }
            else
            {
                a = Mathf.Min(width, height, radius);
                b = a;

                dx = width - a;
                dy = height - a;
            }

            float x = 0, y = 1;

            vert.Clear();

            vert.Add(new Vector2(0, height));

            while (x < y)
            {
                y = SquircleFunc(x, true);
                vert.Add(new Vector2(dx + x, dy + y));
                x += delta;
            }

            if (float.IsNaN(vert.Last().y))
            {
                vert.RemoveAt(vert.Count - 1);
            }

            while (y > 0)
            {
                x = SquircleFunc(y, false);
                vert.Add(new Vector2(dx + x, dy + y));
                y -= delta;
            }

            vert.Add(new Vector2(width, 0));

            for (int i = 1; i < vert.Count - 1; i++)
            {
                if (vert[i].x < vert[i].y)
                {
                    if (vert[i - 1].y - vert[i].y < quality)
                    {
                        vert.RemoveAt(i);
                        i -= 1;
                    }
                }
                else
                {
                    if (vert[i].x - vert[i - 1].x < quality)
                    {
                        vert.RemoveAt(i);
                        i -= 1;
                    }
                }
            }

            vert.AddRange(vert.AsEnumerable().Reverse().Select(t => new Vector2(t.x, -t.y)));
            vert.AddRange(vert.AsEnumerable().Reverse().Select(t => new Vector2(-t.x, t.y)));

            vh.Clear();

            for (int i = 0; i < vert.Count - 1; i++)
            {
                vh.AddVert(vert[i], color, Vector2.zero);

                vh.AddVert(vert[i + 1], color, Vector2.zero);

                vh.AddVert(Vector2.zero, color, Vector2.zero);

                vh.AddTriangle(i * 3, i * 3 + 1, i * 3 + 2);
            }
        }
예제 #54
0
    /// <summary>
    /// 해당 index가 차지하고 있는 
    /// length 비율
    /// </summary>
    public void DrawRoundEdge(VertexHelper vh, Vector2 p0, Vector2 p1, Color color)
    {
        Vector2 widthVector = Vector3.Cross(p0 - p1, new Vector3(0, 0, 1));
        widthVector.Normalize();
        widthVector = widthVector * width / 2f;
        Vector2 lineVector = (p0 - p1).normalized * width / 2f;

        int count = roundEdgePolygonCount;
        int current = vh.currentVertCount;
        float angleUnit = Mathf.PI / (count-1);

        vh.AddVert(p0, color, Vector2.zero);
        vh.AddVert(p0 + widthVector, color, Vector2.zero);
        
        for (int n = 0; n< count; n++)
        {
            vh.AddVert(p0 + Mathf.Cos(angleUnit * n) * widthVector + Mathf.Sin(angleUnit * n) * lineVector, color, Vector2.zero);
            vh.AddTriangle(current, current + 1 + n, current + 2 + n);
        }
    }
예제 #55
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                Vector4 v = Vector4.zero;
                Rect uvRect = new Rect(0, 0, Mathf.Ceil(Mathf.Max(1, rectTransform.rect.width)), Mathf.Ceil(Mathf.Max(1, rectTransform.rect.height)));

                int w = Mathf.RoundToInt(tex.width * uvRect.width);
                int h = Mathf.RoundToInt(tex.height * uvRect.height);

                float paddedW = ((w & 1) == 0) ? w : w + 1;
                float paddedH = ((h & 1) == 0) ? h : h + 1;

                v.x = 0f;
                v.y = 0f;
                v.z = w / paddedW;
                v.w = h / paddedH;

                v.x -= rectTransform.pivot.x;
                v.y -= rectTransform.pivot.y;
                v.z -= rectTransform.pivot.x;
                v.w -= rectTransform.pivot.y;

                v.x *= rectTransform.rect.width;
                v.y *= rectTransform.rect.height;
                v.z *= rectTransform.rect.width;
                v.w *= rectTransform.rect.height;

                using (var vh = new VertexHelper())
                {
                    Vector2 whiteUV = new Vector2(0.25f, 0.25f);

                    Vector3 lb;
                    Vector3 lt;
                    Vector3 rt;
                    Vector3 rb;

                    int vert = 0;

                    if (borderSize > 0)
                    {
                        vh.AddVert(new Vector3(v.x, v.y), color, whiteUV);
                        vh.AddVert(new Vector3(v.x, v.w), color, whiteUV);
                        vh.AddVert(new Vector3(v.z, v.w), color, whiteUV);
                        vh.AddVert(new Vector3(v.z, v.y), color, whiteUV);
                        vh.AddTriangle(vert, vert + 1, vert + 2);
                        vh.AddTriangle(vert + 2, vert + 3, vert);
                        vert += 4;

                        v.x += borderSize;
                        v.y += borderSize;
                        v.w -= borderSize;
                        v.z -= borderSize;
                    }

                    switch (direction)
                    {
                        case Slider.Direction.BottomToTop:
                            lb = new Vector3(v.z, v.y);
                            lt = new Vector3(v.x, v.y);
                            rt = new Vector3(v.x, v.w);
                            rb = new Vector3(v.z, v.w);
                            break;
                        case Slider.Direction.LeftToRight:
                            lb = new Vector3(v.x, v.y);
                            lt = new Vector3(v.x, v.w);
                            rt = new Vector3(v.z, v.w);
                            rb = new Vector3(v.z, v.y);
                            break;
                        case Slider.Direction.RightToLeft:
                            lb = new Vector3(v.z, v.y);
                            lt = new Vector3(v.z, v.w);
                            rt = new Vector3(v.x, v.w);
                            rb = new Vector3(v.x, v.y);
                            break;
                        case Slider.Direction.TopToBottom:
                            lb = new Vector3(v.x, v.w);
                            lt = new Vector3(v.z, v.w);
                            rt = new Vector3(v.z, v.y);
                            rb = new Vector3(v.x, v.y);
                            break;
                        default:
                            throw new System.NotImplementedException(direction.ToString());
                    }

                    // Draw checkboard background if required
                    if (displayCheckboard)
                    {
                        switch (direction)
                        {
                            case Slider.Direction.BottomToTop:
                            case Slider.Direction.TopToBottom:
                                Vector2 tempSize = rectTransform.rect.size / 8;
                                uvRect = new Rect(Vector2.zero, new Vector2(tempSize.y, tempSize.x));
                                break;
                            case Slider.Direction.LeftToRight:
                            case Slider.Direction.RightToLeft:
                                uvRect = new Rect(Vector2.zero, rectTransform.rect.size / 8);
                                break;
                            default:
                                throw new System.NotImplementedException(direction.ToString());
                        }
                        uvRect.max = uvRect.max / checkBoardSize;

                        vh.AddVert(lb, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMin, uvRect.yMin));
                        vh.AddVert(lt, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMin, uvRect.yMax));
                        vh.AddVert(rt, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMax, uvRect.yMax));
                        vh.AddVert(rb, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMax, uvRect.yMin));
                        vh.AddTriangle(vert, vert + 1, vert + 2);
                        vh.AddTriangle(vert + 2, vert + 3, vert);
                        vert += 4;
                    }

                    for (int i = 0; i < colors.Length - 1; i++)
                    {
                        // custom left bot and top
                        Vector3 clb = lb + ((rb - lb) * ((float)i / (colors.Length - 1)));
                        Vector3 clt = lt + ((rt - lt) * ((float)i / (colors.Length - 1)));

                        // custom right bot and top
                        Vector3 crb = lb + ((rb - lb) * ((float)(i + 1) / (colors.Length - 1)));
                        Vector3 crt = lt + ((rt - lt) * ((float)(i + 1) / (colors.Length - 1)));

                        // custom center bot and top
                        Vector3 ccb = clb + ((crb - clb) * centerPos);
                        Vector3 cct = clt + ((crt - clt) * centerPos);

                        if (gradient)
                        {
                            Color32 cColor = Color32.Lerp(colors[i].Color, colors[i + 1].Color, 0.5f);

                            vh.AddVert(clb, colors[i].Color, whiteUV);
                            vh.AddVert(clt, colors[i].Color, whiteUV);

                            vh.AddVert(ccb, cColor, whiteUV);
                            vh.AddVert(cct, cColor, whiteUV);

                            vh.AddVert(crb, colors[i + 1].Color, whiteUV);
                            vh.AddVert(crt, colors[i + 1].Color, whiteUV);

                            vh.AddTriangle(vert, vert + 1, vert + 3);
                            vh.AddTriangle(vert + 3, vert + 2, vert);
                            vh.AddTriangle(vert + 2, vert + 3, vert + 5);
                            vh.AddTriangle(vert + 5, vert + 4, vert + 2);
                            vert += 6;
                        }
                        else
                        {
                            vh.AddVert(clb, colors[i].Color, whiteUV);
                            vh.AddVert(clt, colors[i].Color, whiteUV);

                            vh.AddVert(ccb, colors[i].Color, whiteUV);
                            vh.AddVert(cct, colors[i].Color, whiteUV);

                            vh.AddVert(ccb, colors[i + 1].Color, whiteUV);
                            vh.AddVert(cct, colors[i + 1].Color, whiteUV);

                            vh.AddVert(crb, colors[i + 1].Color, whiteUV);
                            vh.AddVert(crt, colors[i + 1].Color, whiteUV);

                            vh.AddTriangle(vert, vert + 1, vert + 3);
                            vh.AddTriangle(vert + 3, vert + 2, vert);
                            vh.AddTriangle(vert + 4, vert + 5, vert + 7);
                            vh.AddTriangle(vert + 7, vert + 6, vert + 4);
                            vert += 8;
                        }

                    }

                    vh.FillMesh(toFill);
                }
            }
        }
예제 #56
0
 protected override void OnPopulateMesh(VertexHelper vh)
 {
   Texture mainTexture = this.mainTexture;
   vh.Clear();
   if (!((Object) mainTexture != (Object) null))
     return;
   Rect pixelAdjustedRect = this.GetPixelAdjustedRect();
   Vector4 vector4 = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
   Color color = this.color;
   vh.AddVert(new Vector3(vector4.x, vector4.y), (Color32) color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
   vh.AddVert(new Vector3(vector4.x, vector4.w), (Color32) color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
   vh.AddVert(new Vector3(vector4.z, vector4.w), (Color32) color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
   vh.AddVert(new Vector3(vector4.z, vector4.y), (Color32) color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
   vh.AddTriangle(0, 1, 2);
   vh.AddTriangle(2, 3, 0);
 }
예제 #57
0
    protected override void OnPopulateMesh(Mesh m)
    {
        var Points = new List<Vector2>();

        if (Decay < 0.0f)
            Decay = 0.0f;
        if (Decay > 1.0f)
            Decay = 1.0f;

        if (Gamma < 0.1f)
            Gamma = 0.1f;
        if (Gamma > 10.0f)
            Gamma = 10.0f;
        
        for (int i = 0; i < CurveResolution; i++)
        {
            float zeroOne = (float) i/(float) (CurveResolution - 1);
            float v = Mathf.Pow(zeroOne, Gamma) * Decay;
            Points.Add(new Vector2((float) i / (float) (CurveResolution - 1), 1.0f - v));
        }
        
        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;

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

        var vh = new VertexHelper();

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

            var normal = new Vector3(cur.x - prev.x, cur.y - prev.y);
            var perp_vector = Vector3.Cross(normal, Vector3.forward).normalized;

            var halfThikness = LineThikness/2;

            var v1 = prev + new Vector2(perp_vector.x * -halfThikness, perp_vector.y * -halfThikness);
            var v2 = prev + new Vector2(perp_vector.x * halfThikness, perp_vector.y * halfThikness);
            var v3 = cur + new Vector2(perp_vector.x * halfThikness, perp_vector.y * halfThikness);
            var v4 = cur + new Vector2(perp_vector.x * -halfThikness, perp_vector.y * -halfThikness);

            vh.AddVert(v1, color, new Vector2(0f, 0f));
            vh.AddVert(v2, color, new Vector2(0f, 1f));
            vh.AddVert(v3, color, new Vector2(1f, 1f));
            vh.AddVert(v4, color, new Vector2(1f, 0f));

            vh.AddTriangle(0 + i*4, 1 + i * 4, 2 + i * 4);
            vh.AddTriangle(2 + i * 4, 3 + i * 4, 0 + i * 4);
            
        }

        vh.FillMesh(m);
    }
예제 #58
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();
            innerVertices.Clear();
            outterVertices.Clear();

            Vector4 uv = overrideSprite != null?DataUtility.GetOuterUV(overrideSprite) : Vector4.zero;

            Rect  pixelAdjustedRect = GetPixelAdjustedRect();
            float w = pixelAdjustedRect.width;
            float h = pixelAdjustedRect.height;

            float ASPECT_X = w > h ? h / w : 1;
            float ASPECT_Y = h > w ? w / h : 1;

            #region 圆角矩形

            #region 左下角
            for (int i = 0; i < segements + 1; i++)
            {
                uivertex       = new UIVertex();
                uivertex.color = color;
                if (i == 0)
                {
                    //半径*
                    uivertex.uv0 = new Vector2(uv.x + (round * ASPECT_X / 2) * (uv.z - uv.x) * (1 - Mathf.Sin(i * 90 / segements)), uv.y + (round * ASPECT_Y / 2) * (uv.w - uv.y) * (1 - Mathf.Cos(i * 90 / segements)));
                    u            = new Vector2((round * ASPECT_X / 2) * (1 - Mathf.Sin(i * 90 / segements)), (round * ASPECT_Y / 2) * (1 - Mathf.Cos(i * 90 / segements)));
                }
                else
                {
                    uivertex.uv0 = new Vector2(uv.x + (round * ASPECT_X / 2) * (uv.z - uv.x) * (1 - Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements)))), uv.y + (round * ASPECT_Y / 2) * (uv.w - uv.y) * (1 - Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements)))));
                    u            = new Vector2((round * ASPECT_X / 2) * (1 - Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements)))), (round * ASPECT_Y / 2) * (1 - Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements)))));
                }
                uivertex.position = new Vector3(w * u.x - w / 2, h * u.y - h / 2);
                vh.AddVert(uivertex);
                outterVertices.Add(new Vector3(w * u.x - w / 2, h * u.y - h / 2));
            }
            #endregion

            #region 左上角
            //2
            for (int i = 0; i < segements + 1; i++)
            {
                uivertex       = new UIVertex();
                uivertex.color = color;
                if (i == 0)
                {
                    uivertex.uv0 = new Vector2(uv.x + (uv.z - uv.x) * (round * ASPECT_X / 2) * (1 - Mathf.Cos(i * 90 / segements)), uv.y + (uv.w - uv.y) * ((1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Sin(i * 90 / segements)));
                    u            = new Vector2((round * ASPECT_X / 2) - (round * ASPECT_X / 2) * Mathf.Cos(i * 90 / segements), (1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Sin(i * 90 / segements));
                }
                else
                {
                    uivertex.uv0 = new Vector2(uv.x + (uv.z - uv.x) * (round * ASPECT_X / 2) * (1 - Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements)))), uv.y + (uv.w - uv.y) * ((1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements)))));
                    u            = new Vector2((round * ASPECT_X / 2) * (1 - Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements)))), (1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements))));
                }
                uivertex.position = new Vector3(w * u.x - w / 2, h * u.y - h / 2);
                vh.AddVert(uivertex);
                outterVertices.Add(new Vector3(w * u.x - w / 2, h * u.y - h / 2));
            }
            #endregion

            #region 右上角
            //3
            for (int i = 0; i < segements + 1; i++)
            {
                uivertex       = new UIVertex();
                uivertex.color = color;
                if (i == 0)
                {
                    uivertex.uv0 = new Vector2(uv.x + (uv.z - uv.x) * ((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Sin(i * 90 / segements)), uv.y + (uv.w - uv.y) * ((1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Cos(i * 90 / segements)));
                    u            = new Vector2((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Sin(i * 90 / segements), (1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Cos(i * 90 / segements));
                }
                else
                {
                    uivertex.uv0 = new Vector2(uv.x + (uv.z - uv.x) * ((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements)))), uv.y + (uv.w - uv.y) * ((1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements)))));
                    u            = new Vector2((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements))), (1 - round * ASPECT_Y / 2) + (round * ASPECT_Y / 2) * Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements))));
                }
                uivertex.position = new Vector3(w * u.x - w / 2, h * u.y - h / 2);
                vh.AddVert(uivertex);
                outterVertices.Add(new Vector3(w * u.x - w / 2, h * u.y - h / 2));
            }
            #endregion

            #region 右下角
            //4
            for (int i = 0; i < segements + 1; i++)
            {
                uivertex       = new UIVertex();
                uivertex.color = color;
                if (i == 0)
                {
                    uivertex.uv0 = new Vector2(uv.x + (uv.z - uv.x) * ((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Cos(i * 90 / segements)), uv.y + (uv.w - uv.y) * ((round * ASPECT_Y / 2) - (round * ASPECT_Y / 2) * Mathf.Sin(i * 90 / segements)));
                    u            = new Vector2((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Cos(i * 90 / segements), (round * ASPECT_Y / 2) - (round * ASPECT_Y / 2) * Mathf.Sin(i * 90 / segements));
                }
                else
                {
                    uivertex.uv0 = new Vector2(uv.x + (uv.z - uv.x) * ((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements)))), uv.y + (uv.w - uv.y) * ((round * ASPECT_Y / 2) - (round * ASPECT_Y / 2) * Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements)))));
                    u            = new Vector2((1 - round * ASPECT_X / 2) + (round * ASPECT_X / 2) * Mathf.Cos(Mathf.PI / (180f / (i * 90 / segements))), (round * ASPECT_Y / 2) - (round * ASPECT_Y / 2) * Mathf.Sin(Mathf.PI / (180f / (i * 90 / segements))));
                }
                uivertex.position = new Vector3(w * u.x - w / 2, h * u.y - h / 2);
                vh.AddVert(uivertex);
                outterVertices.Add(new Vector3(w * u.x - w / 2, h * u.y - h / 2));
            }
            #endregion

            //((点*4+8个点-3)条弦+1)个三角形
            for (int i = 0; i < ((segements - 1) * 4 + 8 - 3 + 1); i++)
            {
                vh.AddTriangle(0, i + 1, i + 2);
            }
            #endregion
        }