Esempio n. 1
0
        static void AddRoundedRingIndices(
            ref VertexHelper vh,
            RoundedCornerUnitPositionData cornerUnitPositions
            )
        {
            int totalResolution =
                cornerUnitPositions.TLUnitPositions.Length +
                cornerUnitPositions.TRUnitPositions.Length +
                cornerUnitPositions.BRUnitPositions.Length +
                cornerUnitPositions.BLUnitPositions.Length;

            int numNewVertices = totalResolution + 1;

            int innerStartIndex = vh.currentVertCount - numNewVertices - numNewVertices - 1;
            int outerStartIndex = vh.currentVertCount - numNewVertices;

            for (int i = 0; i < totalResolution; i++)
            {
                vh.AddTriangle(innerStartIndex + i + 1, outerStartIndex + i, outerStartIndex + i + 1);
                vh.AddTriangle(innerStartIndex + i + 1, outerStartIndex + i + 1, innerStartIndex + i + 2);
            }

            vh.AddTriangle(innerStartIndex + 1, outerStartIndex + totalResolution, outerStartIndex);
            vh.AddTriangle(innerStartIndex + 1, outerStartIndex - 1, outerStartIndex + totalResolution);
        }
Esempio n. 2
0
 static void SetCornerUnitPositions(
     RoundedProperties roundedProperties,
     ref RoundedCornerUnitPositionData cornerUnitPositions
     )
 {
     SetUnitPosition(ref cornerUnitPositions.TLUnitPositions, roundedProperties.TLResolution.AdjustedResolution, GeoUtils.HalfPI + Mathf.PI, roundedProperties.TLResolution.MakeSharpCorner);
     SetUnitPosition(ref cornerUnitPositions.TRUnitPositions, roundedProperties.TRResolution.AdjustedResolution, 0.0f, roundedProperties.TRResolution.MakeSharpCorner);
     SetUnitPosition(ref cornerUnitPositions.BRUnitPositions, roundedProperties.BRResolution.AdjustedResolution, GeoUtils.HalfPI, roundedProperties.BRResolution.MakeSharpCorner);
     SetUnitPosition(ref cornerUnitPositions.BLUnitPositions, roundedProperties.BLResolution.AdjustedResolution, Mathf.PI, roundedProperties.BLResolution.MakeSharpCorner);
 }
Esempio n. 3
0
        static void AddRoundedRectVerticesRing(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            float fullWidth,
            float fullHeight,
            float tlRadius,
            float tlOuterRadius,
            float trRadius,
            float trOuterRadius,
            float brRadius,
            float brOuterRadius,
            float blRadius,
            float blOuterRadius,
            RoundedCornerUnitPositionData cornerUnitPositions,
            Color32 color,
            Vector2 uv,
            bool addIndices
            )
        {
            float xMin = center.x - width * 0.5f;
            float yMin = center.y - height * 0.5f;

            float xMax = center.x + width * 0.5f;
            float yMax = center.y + height * 0.5f;

            float xMinUV = center.x - fullWidth * 0.5f;
            float yMinUV = center.y - fullHeight * 0.5f;

            // TR
            tmpV3.x = xMax - trRadius;
            tmpV3.y = yMax - trRadius;

            if (trOuterRadius < 0.0f)
            {
                tmpV3.x += trOuterRadius;
                tmpV3.y += trOuterRadius;

                trOuterRadius = 0.0f;
            }

            for (int i = 0; i < cornerUnitPositions.TRUnitPositions.Length; i++)
            {
                tmpPos.x = tmpV3.x + cornerUnitPositions.TRUnitPositions[i].x * trOuterRadius;
                tmpPos.y = tmpV3.y + cornerUnitPositions.TRUnitPositions[i].y * trOuterRadius;
                tmpPos.z = tmpV3.z;

                tmpUV.x = (tmpPos.x - xMinUV) / fullWidth;
                tmpUV.y = (tmpPos.y - yMinUV) / fullHeight;

                vh.AddVert(tmpPos, color, tmpUV, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.GeoUtils.UITangent);
            }

            // BR
            tmpV3.x = xMax - brRadius;
            tmpV3.y = yMin + brRadius;

            if (brOuterRadius < 0.0f)
            {
                tmpV3.x += brOuterRadius;
                tmpV3.y -= brOuterRadius;

                brOuterRadius = 0.0f;
            }

            for (int i = 0; i < cornerUnitPositions.BRUnitPositions.Length; i++)
            {
                tmpPos.x = tmpV3.x + cornerUnitPositions.BRUnitPositions[i].x * brOuterRadius;
                tmpPos.y = tmpV3.y + cornerUnitPositions.BRUnitPositions[i].y * brOuterRadius;
                tmpPos.z = tmpV3.z;

                tmpUV.x = (tmpPos.x - xMinUV) / fullWidth;
                tmpUV.y = (tmpPos.y - yMinUV) / fullHeight;

                vh.AddVert(tmpPos, color, tmpUV, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.GeoUtils.UITangent);
            }

            // BL
            tmpV3.x = xMin + blRadius;
            tmpV3.y = yMin + blRadius;

            if (blOuterRadius < 0.0f)
            {
                tmpV3.x -= blOuterRadius;
                tmpV3.y -= blOuterRadius;

                blOuterRadius = 0.0f;
            }

            for (int i = 0; i < cornerUnitPositions.BLUnitPositions.Length; i++)
            {
                tmpPos.x = tmpV3.x + cornerUnitPositions.BLUnitPositions[i].x * blOuterRadius;
                tmpPos.y = tmpV3.y + cornerUnitPositions.BLUnitPositions[i].y * blOuterRadius;
                tmpPos.z = tmpV3.z;

                tmpUV.x = (tmpPos.x - xMinUV) / fullWidth;
                tmpUV.y = (tmpPos.y - yMinUV) / fullHeight;

                vh.AddVert(tmpPos, color, tmpUV, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.GeoUtils.UITangent);
            }

            // TL
            tmpV3.x = xMin + tlRadius;
            tmpV3.y = yMax - tlRadius;

            if (tlOuterRadius < 0.0f)
            {
                tmpV3.x -= tlOuterRadius;
                tmpV3.y += tlOuterRadius;

                tlOuterRadius = 0.0f;
            }

            for (int i = 0; i < cornerUnitPositions.TLUnitPositions.Length; i++)
            {
                tmpPos.x = tmpV3.x + cornerUnitPositions.TLUnitPositions[i].x * tlOuterRadius;
                tmpPos.y = tmpV3.y + cornerUnitPositions.TLUnitPositions[i].y * tlOuterRadius;
                tmpPos.z = tmpV3.z;

                tmpUV.x = (tmpPos.x - xMinUV) / fullWidth;
                tmpUV.y = (tmpPos.y - yMinUV) / fullHeight;

                vh.AddVert(tmpPos, color, tmpUV, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.GeoUtils.UITangent);
            }


            // add last circle vertex
            tmpPos.x = tmpV3.x + cornerUnitPositions.TRUnitPositions[0].x * tlOuterRadius;
            tmpPos.y = tmpV3.y + cornerUnitPositions.TRUnitPositions[0].y * tlOuterRadius;
            tmpPos.z = tmpV3.z;

            tmpUV.x = (tmpPos.x - xMinUV) / fullWidth;
            tmpUV.y = (tmpPos.y - yMinUV) / fullHeight;

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


            if (addIndices)
            {
                AddRoundedRingIndices(
                    ref vh,
                    cornerUnitPositions
                    );
            }
        }
Esempio n. 4
0
        public static void AddRoundedRectLine(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            UI.GeoUtils.OutlineProperties outlineProperties,
            RoundedProperties roundedProperties,
            Color32 color,
            Vector2 uv,
            ref RoundedCornerUnitPositionData cornerUnitPositions,
            UI.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
                    );
            }
        }
Esempio n. 5
0
        public static void AddRoundedRect(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            RoundedProperties roundedProperties,
            Color32 color,
            Vector2 uv,
            ref RoundedCornerUnitPositionData cornerUnitPositions,
            UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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
                    );
            }
        }