Ejemplo n.º 1
0
        public static void AddRoundedRectLine(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            GeoUtils.OutlineProperties outlineProperties,
            RoundedProperties roundedProperties,
            Color32 color,
            Vector2 uv,
            ref RoundedCornerUnitPositionData cornerUnitPositions,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            float fullWidth  = width + outlineProperties.GetOuterDistace() * 2.0f;
            float fullHeight = height + outlineProperties.GetOuterDistace() * 2.0f;

            if (roundedProperties.Type == RoundedProperties.RoundedType.None)
            {
                Rects.AddRectRing(
                    ref vh,
                    outlineProperties,
                    center,
                    width,
                    height,
                    color,
                    uv,
                    edgeGradientData
                    );

                return;
            }

            SetCornerUnitPositions(
                roundedProperties,
                ref cornerUnitPositions
                );

            float outerRadiusMod;

            byte alpha = color.a;

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                outerRadiusMod =
                    outlineProperties.GetCenterDistace() - outlineProperties.HalfLineWeight - edgeGradientData.ShadowOffset;
                outerRadiusMod -= edgeGradientData.SizeAdd;

                AddRoundedRectVerticesRing(
                    ref vh,
                    center,
                    width,
                    height,
                    fullWidth,
                    fullHeight,
                    roundedProperties.AdjustedTLRadius,
                    roundedProperties.AdjustedTLRadius + outerRadiusMod,
                    roundedProperties.AdjustedTRRadius,
                    roundedProperties.AdjustedTRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBRRadius,
                    roundedProperties.AdjustedBRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBLRadius,
                    roundedProperties.AdjustedBLRadius + outerRadiusMod,
                    cornerUnitPositions,
                    color,
                    uv,
                    false
                    );

                color.a = alpha;
            }

            outerRadiusMod =
                Mathf.LerpUnclamped(
                    outlineProperties.GetCenterDistace(),
                    outlineProperties.GetCenterDistace() - outlineProperties.HalfLineWeight - edgeGradientData.ShadowOffset,
                    edgeGradientData.InnerScale);

            AddRoundedRectVerticesRing(
                ref vh,
                center,
                width,
                height,
                fullWidth,
                fullHeight,
                roundedProperties.AdjustedTLRadius,
                roundedProperties.AdjustedTLRadius + outerRadiusMod,
                roundedProperties.AdjustedTRRadius,
                roundedProperties.AdjustedTRRadius + outerRadiusMod,
                roundedProperties.AdjustedBRRadius,
                roundedProperties.AdjustedBRRadius + outerRadiusMod,
                roundedProperties.AdjustedBLRadius,
                roundedProperties.AdjustedBLRadius + outerRadiusMod,
                cornerUnitPositions,
                color,
                uv,
                edgeGradientData.IsActive
                );

            outerRadiusMod =
                outlineProperties.GetCenterDistace() +
                (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            AddRoundedRectVerticesRing(
                ref vh,
                center,
                width,
                height,
                fullWidth,
                fullHeight,
                roundedProperties.AdjustedTLRadius,
                roundedProperties.AdjustedTLRadius + outerRadiusMod,
                roundedProperties.AdjustedTRRadius,
                roundedProperties.AdjustedTRRadius + outerRadiusMod,
                roundedProperties.AdjustedBRRadius,
                roundedProperties.AdjustedBRRadius + outerRadiusMod,
                roundedProperties.AdjustedBLRadius,
                roundedProperties.AdjustedBLRadius + outerRadiusMod,
                cornerUnitPositions,
                color,
                uv,
                true
                );

            if (edgeGradientData.IsActive)
            {
                outerRadiusMod =
                    outlineProperties.GetCenterDistace() +
                    outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset;
                outerRadiusMod += edgeGradientData.SizeAdd;

                color.a = 0;

                AddRoundedRectVerticesRing(
                    ref vh,
                    center,
                    width,
                    height,
                    fullWidth,
                    fullHeight,
                    roundedProperties.AdjustedTLRadius,
                    roundedProperties.AdjustedTLRadius + outerRadiusMod,
                    roundedProperties.AdjustedTRRadius,
                    roundedProperties.AdjustedTRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBRRadius,
                    roundedProperties.AdjustedBRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBLRadius,
                    roundedProperties.AdjustedBLRadius + outerRadiusMod,
                    cornerUnitPositions,
                    color,
                    uv,
                    true
                    );
            }
        }
Ejemplo n.º 2
0
        public static void AddRoundedRect(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            RoundedProperties roundedProperties,
            Color32 color,
            Vector2 uv,
            ref RoundedCornerUnitPositionData cornerUnitPositions,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            if (roundedProperties.Type == RoundedProperties.RoundedType.None)
            {
                Rects.AddRect(
                    ref vh,
                    center,
                    width,
                    height,
                    color,
                    edgeGradientData
                    );

                return;
            }


            SetCornerUnitPositions(
                roundedProperties,
                ref cornerUnitPositions
                );

            int numVertices = vh.currentVertCount;

            tmpUV.x = 0.5f;
            tmpUV.y = 0.5f;

            vh.AddVert(center, color, tmpUV, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            float sizeSub = Mathf.Min(height, width);

            sizeSub *= 1.0f - edgeGradientData.InnerScale;

            AddRoundedRectVerticesRing(
                ref vh,
                center,
                width - sizeSub,
                height - sizeSub,
                width - sizeSub,
                height - sizeSub,
                roundedProperties.AdjustedTLRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedTLRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                roundedProperties.AdjustedTRRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedTRRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                roundedProperties.AdjustedBRRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedBRRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                roundedProperties.AdjustedBLRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedBLRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                cornerUnitPositions,
                color,
                uv,
                false
                );


            // set indices
            int numNewVertices = vh.currentVertCount - numVertices;

            for (int i = 0; i < numNewVertices - 1; i++)
            {
                vh.AddTriangle(numVertices, numVertices + i, numVertices + i + 1);
            }

            // set last triangle
            vh.AddTriangle(numVertices, vh.currentVertCount - 1, numVertices + 1);


            if (edgeGradientData.IsActive)
            {
                float outerRadiusMod = 0.0f;                // = roundedProperties.AdjustedRadius;
                outerRadiusMod += edgeGradientData.ShadowOffset;
                outerRadiusMod += edgeGradientData.SizeAdd;

                color.a = 0;

                AddRoundedRectVerticesRing(
                    ref vh,
                    center,
                    width,
                    height,
                    width,
                    height,
                    roundedProperties.AdjustedTLRadius,
                    roundedProperties.AdjustedTLRadius + outerRadiusMod,
                    roundedProperties.AdjustedTRRadius,
                    roundedProperties.AdjustedTRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBRRadius,
                    roundedProperties.AdjustedBRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBLRadius,
                    roundedProperties.AdjustedBLRadius + outerRadiusMod,
                    cornerUnitPositions,
                    color,
                    uv,
                    true
                    );
            }
        }