コード例 #1
0
        public static void AddRectRing(
            ref VertexHelper vh,
            GeoUtils.OutlineProperties OutlineProperties,
            Vector2 center,
            float width,
            float height,
            Color32 color,
            Vector2 uv,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            byte alpha = color.a;

            float fullWidth  = width + OutlineProperties.GetOuterDistace() * 2.0f;
            float fullHeight = height + OutlineProperties.GetOuterDistace() * 2.0f;

            width  += OutlineProperties.GetCenterDistace() * 2.0f;
            height += OutlineProperties.GetCenterDistace() * 2.0f;

            float halfLineWeightOffset      = OutlineProperties.HalfLineWeight * 2.0f + edgeGradientData.ShadowOffset;
            float halfLineWeightInnerOffset = halfLineWeightOffset * edgeGradientData.InnerScale;

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

                AddRectVertRing(
                    ref vh,
                    center,
                    width - halfLineWeightOffset - edgeGradientData.SizeAdd,
                    height - halfLineWeightOffset - edgeGradientData.SizeAdd,
                    color,
                    fullWidth,
                    fullHeight
                    );

                color.a = alpha;
            }



            AddRectVertRing(
                ref vh,
                center,
                width - halfLineWeightInnerOffset,
                height - halfLineWeightInnerOffset,
                color,
                fullWidth,
                fullHeight,
                edgeGradientData.IsActive
                );

            AddRectVertRing(
                ref vh,
                center,
                width + halfLineWeightInnerOffset,
                height + halfLineWeightInnerOffset,
                color,
                fullWidth,
                fullHeight,
                true
                );

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

                AddRectVertRing(
                    ref vh,
                    center,
                    width + halfLineWeightOffset + edgeGradientData.SizeAdd,
                    height + halfLineWeightOffset + edgeGradientData.SizeAdd,
                    color,
                    fullWidth,
                    fullHeight,
                    true
                    );
            }
        }
コード例 #2
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();

            Rect pixelRect = RectTransformUtility.PixelAdjustRect(rectTransform, canvas);

            OutlineProperties.UpdateAdjusted();
            ShadowProperties.UpdateAdjusted();

            UIShapesKit.Ellipses.SetRadius(
                ref radius,
                pixelRect.width,
                pixelRect.height,
                EllipseProperties
                );

            PointListProperties.GeneratorData.Width  = radius.x * 2.0f;
            PointListProperties.GeneratorData.Height = radius.y * 2.0f;

            EllipseProperties.UpdateAdjusted(radius, OutlineProperties.GetOuterDistace());
            ArcProperties.UpdateAdjusted(EllipseProperties.AdjustedResolution, EllipseProperties.BaseAngle);
            AntiAliasingProperties.UpdateAdjusted(canvas);

            PointListProperties.GeneratorData.Resolution = EllipseProperties.AdjustedResolution * 2;
            PointListProperties.GeneratorData.Length     = ArcProperties.Length;

            switch (ArcProperties.Direction)
            {
            case UIShapesKit.Arcs.ArcProperties.ArcDirection.Forward:
                PointListProperties.GeneratorData.Direction        = 1.0f;
                PointListProperties.GeneratorData.FloatStartOffset = EllipseProperties.BaseAngle * 0.5f;
                break;

            case UIShapesKit.Arcs.ArcProperties.ArcDirection.Centered:
                PointListProperties.GeneratorData.Direction        = -1.0f;
                PointListProperties.GeneratorData.FloatStartOffset = EllipseProperties.BaseAngle * 0.5f + (ArcProperties.Length * 0.5f);
                break;

            case UIShapesKit.Arcs.ArcProperties.ArcDirection.Backward:
                PointListProperties.GeneratorData.Direction        = -1.0f;
                PointListProperties.GeneratorData.FloatStartOffset = EllipseProperties.BaseAngle * 0.5f;
                break;
            }

            // shadows
            if (ShadowProperties.ShadowsEnabled)
            {
                if (AntiAliasingProperties.Adjusted > 0.0f)
                {
                    edgeGradientData.SetActiveData(
                        1.0f,
                        0.0f,
                        AntiAliasingProperties.Adjusted
                        );
                }
                else
                {
                    edgeGradientData.Reset();
                }

                // use segment if LineWeight is overshooting the center
                if (
                    (
                        OutlineProperties.Type == GeoUtils.OutlineProperties.LineType.Center ||
                        OutlineProperties.Type == GeoUtils.OutlineProperties.LineType.Inner
                    ) &&
                    (
                        radius.x + OutlineProperties.GetInnerDistace() < 0.0f ||
                        radius.y + OutlineProperties.GetInnerDistace() < 0.0f
                    )
                    )
                {
                    if (OutlineProperties.Type == GeoUtils.OutlineProperties.LineType.Center)
                    {
                        radius *= 2.0f;
                    }

                    for (int i = 0; i < ShadowProperties.Shadows.Length; i++)
                    {
                        edgeGradientData.SetActiveData(
                            1.0f - ShadowProperties.Shadows[i].Softness,
                            ShadowProperties.Shadows[i].Size,
                            AntiAliasingProperties.Adjusted
                            );

                        UIShapesKit.Arcs.AddSegment(
                            ref vh,
                            ShadowProperties.GetCenterOffset(pixelRect.center, i),
                            radius,
                            EllipseProperties,
                            ArcProperties,
                            ShadowProperties.Shadows[i].Color,
                            GeoUtils.ZeroV2,
                            ref unitPositionData,
                            edgeGradientData
                            );
                    }
                }
                else
                {
                    for (int i = 0; i < ShadowProperties.Shadows.Length; i++)
                    {
                        edgeGradientData.SetActiveData(
                            1.0f - ShadowProperties.Shadows[i].Softness,
                            ShadowProperties.Shadows[i].Size,
                            AntiAliasingProperties.Adjusted
                            );

                        if (LineProperties.LineCap == UIShapesKit.Lines.LineProperties.LineCapTypes.Close)
                        {
                            UIShapesKit.Arcs.AddArcRing(
                                ref vh,
                                ShadowProperties.GetCenterOffset(pixelRect.center, i),
                                radius,
                                EllipseProperties,
                                ArcProperties,
                                OutlineProperties,
                                ShadowProperties.Shadows[i].Color,
                                GeoUtils.ZeroV2,
                                ref unitPositionData,
                                edgeGradientData
                                );
                        }
                        else
                        {
                            UIShapesKit.Lines.AddLine(
                                ref vh,
                                LineProperties,
                                PointListProperties,
                                ShadowProperties.GetCenterOffset(pixelRect.center, i),
                                OutlineProperties,
                                ShadowProperties.Shadows[i].Color,
                                GeoUtils.ZeroV2,
                                ref PointsData,
                                edgeGradientData
                                );
                        }
                    }
                }
            }

            // fill
            if (ShadowProperties.ShowShape)
            {
                if (AntiAliasingProperties.Adjusted > 0.0f)
                {
                    edgeGradientData.SetActiveData(
                        1.0f,
                        0.0f,
                        AntiAliasingProperties.Adjusted
                        );
                }
                else
                {
                    edgeGradientData.Reset();
                }

                // use segment if LineWeight is overshooting the center
                if (
                    (
                        OutlineProperties.Type == GeoUtils.OutlineProperties.LineType.Center ||
                        OutlineProperties.Type == GeoUtils.OutlineProperties.LineType.Inner
                    ) &&
                    (
                        radius.x + OutlineProperties.GetInnerDistace() < 0.0f ||
                        radius.y + OutlineProperties.GetInnerDistace() < 0.0f
                    )

                    )
                {
                    if (OutlineProperties.Type == GeoUtils.OutlineProperties.LineType.Center)
                    {
                        radius.x *= 2.0f;
                        radius.y *= 2.0f;
                    }

                    UIShapesKit.Arcs.AddSegment(
                        ref vh,
                        pixelRect.center,
                        radius,
                        EllipseProperties,
                        ArcProperties,
                        ShapeProperties.FillColor,
                        GeoUtils.ZeroV2,
                        ref unitPositionData,
                        edgeGradientData
                        );
                }
                else
                {
                    if (LineProperties.LineCap == UIShapesKit.Lines.LineProperties.LineCapTypes.Close)
                    {
                        UIShapesKit.Arcs.AddArcRing(
                            ref vh,
                            pixelRect.center,
                            radius,
                            EllipseProperties,
                            ArcProperties,
                            OutlineProperties,
                            ShapeProperties.FillColor,
                            GeoUtils.ZeroV2,
                            ref unitPositionData,
                            edgeGradientData
                            );
                    }
                    else
                    {
                        UIShapesKit.Lines.AddLine(
                            ref vh,
                            LineProperties,
                            PointListProperties,
                            pixelRect.center,
                            OutlineProperties,
                            ShapeProperties.FillColor,
                            GeoUtils.ZeroV2,
                            ref PointsData,
                            edgeGradientData
                            );
                    }
                }
            }
        }
コード例 #3
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
                    );
            }
        }