예제 #1
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (color.a * 256f < 5)
            {
                vh.Clear();
                return; // dont draw anything if transparent
            }


            base.OnPopulateMesh(vh);

            if (Mirror == MirrorType.None &&
                m_rotate <= 0 &&
                m_skew == Vector2.zero &&
                gradientDirection == Vector2.zero)      // condition of shape changes
            {
                return;
            }

//            var vs = new List<UIVertex>();
//            var vsNew = new List<UIVertex>(vs.Count);
//            vh.GetUIVertexStream(vs);
//            vh.Clear();
            var rect = GetPixelAdjustedRect();

            Easing gradientEaseCurve = null;
            var    gradientDir       = Vector2.zero;
            var    gradientStart     = 0f;
            var    gradientDistance  = 1f;

            if (gradientDirection != Vector2.zero)
            {
                gradientEaseCurve = StandardEase.Get(gradientEase);
                gradientDir       = gradientDirection.normalized;
                var gradientSegment = rect.ProjectionTo(gradientDir);
                gradientStart    = gradientSegment.x;
                gradientDistance = gradientSegment.y - gradientSegment.x;
            }

            var vCur = new UIVertex();

            for (var i = 0; i < vh.currentVertCount; i++)
            {
                vh.PopulateUIVertex(ref vCur, i);
                var retX   = vCur.position.x;
                var retY   = vCur.position.y;
                var center = rect.center;
                if (Mirror != MirrorType.None)
                {
                    retX = ((int)Mirror % 2 == 1) ? center.x * 2 - vCur.position.x : vCur.position.x;
                    retY = ((int)Mirror > 1) ? center.y * 2 - vCur.position.y : vCur.position.y;
                }

                if (m_rotate > 0)
                {
                    var offX = retX - center.x;
                    var offY = retY - center.y;
                    switch (m_rotate)
                    {
                    case 1:
                        retX = center.x + offY * rect.width / rect.height;
                        retY = center.y - offX * rect.height / rect.width;
                        break;

                    case 2:
                        retX = center.x - offX;
                        retY = center.y - offY;
                        break;

                    case 3:
                        retX = center.x - offY * rect.width / rect.height;
                        retY = center.y + offX * rect.height / rect.width;
                        break;
                    }
                }

                if (m_skew != Vector2.zero)
                {
                    var offX = retX - rect.xMin;
                    var offY = retY - rect.yMin;
                    retX += Mathf.Lerp(-m_skew.x, m_skew.x, offY / rect.height);
                    retY += Mathf.Lerp(-m_skew.y, m_skew.y, offX / rect.width);
                }

                if (gradientDir != Vector2.zero && gradientEaseCurve != null)
                {
                    var projectionPos = Vector2.Dot(vCur.position, gradientDir) - gradientStart;
                    var scaledPos     = projectionPos / gradientDistance;
                    var ratio         = gradientEaseCurve.Convert(scaledPos);
                    vCur.color = Color.Lerp(color, gradientColor, ratio);
                }

                vCur.position.x = retX;
                vCur.position.y = retY;


                vh.SetUIVertex(vCur, i);
            }


//            vh.AddUIVertexTriangleStream(vsNew);
        }