Example #1
0
        private void ModifyVertices(VertexHelper vh)
        {
            tempVertexTriangleStream.Clear();
            vh.GetUIVertexStream(tempVertexTriangleStream);
            vh.Clear();

            float[] result = ChartUntils.GetKeyArrayMaxxAndMaxy(keyPos);
            float   maxx = result[0], maxy = result[1];

            for (int i = 0; i < keyPos.Count - 1; i++)
            {
                drawAttribute.SetPosition(
                    CacheUnit.SetVector(keyPos[i].x, keyPos[i].y),
                    CacheUnit.SetVector(keyPos[i + 1].x, keyPos[i + 1].y),
                    CacheUnit.SetVector(keyPos[i + 1].x, 0),
                    CacheUnit.SetVector(keyPos[i].x, 0));
                drawAttribute.SetColor(//平滑插值颜色
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, Color.Lerp(buttomBorderColor, upBorderColor, keyPos[i].y / height)),
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, Color.Lerp(buttomBorderColor, upBorderColor, keyPos[i + 1].y / height)),
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, Color.Lerp(buttomBorderColor, upBorderColor, 0 / height)),
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, Color.Lerp(buttomBorderColor, upBorderColor, 0 / height))
                    );
                drawAttribute.SetUV(
                    CacheUnit.SetVector(keyPos[i].x / maxx, keyPos[i].y / maxy),
                    CacheUnit.SetVector(keyPos[i + 1].x / maxx, keyPos[i + 1].y / maxy),
                    CacheUnit.SetVector(keyPos[i + 1].x / maxx, 0),
                    CacheUnit.SetVector(keyPos[i].x / maxx, 0)
                    );
                DrawSimpleQuad(vh, drawAttribute);
            }
        }
Example #2
0
        private void ModifyVertices(List <UIVertex> vertices)
        {
            if (parametersCount == 0)
            {
                return;
            }

            if (ChartUntils.NeedsToUpdateCaches(parametersCount, startAngleDegree))
            {
                ChartUntils.CacheSinesAndCosines(StartAngleDegree);
            }

            //1 get center point
            Vector3 centerPosition = (vertices[0].position + vertices[2].position) / 2f;

            //2 set xUnit and yUnit
            Vector3 xUnit = (centerPosition.x - vertices[0].position.x) * Vector3.right;
            Vector3 yUnit = (centerPosition.y - vertices[0].position.y) * Vector3.up;

            //3 set uv
            Vector2 centerUv = (vertices[0].uv0 + vertices[2].uv0) / 2f;
            Vector2 uUnit    = (centerUv.x - vertices[0].uv0.x) * Vector3.right;
            Vector2 vUnit    = (centerUv.y - vertices[0].uv0.y) * Vector3.up;

            UIVertex startVertex = vertices[0];

            vertices.Clear();
            for (int j = 0; j < cricleCount; j++)
            {
                for (int i = 0; i < parametersCount; i++)
                {
                    float parmeter = 1f;
                    float cosine   = ChartUntils.cacheCosines[i];
                    float sine     = ChartUntils.cacheSines[i];

                    UIVertex outertmp      = startVertex;
                    float    outerParmeter = parmeter * (defaultCurde - j * cricleDisInterval * 0.15f);
                    outertmp.position = centerPosition + (xUnit * cosine + yUnit * sine) * outerParmeter;
                    outertmp.uv0      = centerUv + (uUnit * cosine + vUnit * sine) * outerParmeter;
                    tempOuterVertices.Add(outertmp);

                    UIVertex innertmp      = startVertex;
                    float    innerParmeter = parmeter * ((defaultCurde - lineCurde * 0.1f) - j * cricleDisInterval * 0.15f);
                    innertmp.position = centerPosition + (xUnit * cosine + yUnit * sine) * innerParmeter;
                    innertmp.uv0      = centerUv + (uUnit * cosine + vUnit * sine) * innerParmeter;
                    tempInnerVertices.Add(innertmp);
                }

                if (parametersCount > 0)
                {
                    tempOuterVertices.Add(tempOuterVertices[0]);
                    tempInnerVertices.Add(tempInnerVertices[0]);
                }

                if (defaultCurde != 0f)
                {
                    for (int i = 0; i < parametersCount; i++)
                    {
                        vertices.Add(tempInnerVertices[i]);
                        vertices.Add(tempOuterVertices[i]);
                        vertices.Add(tempOuterVertices[i + 1]);
                    }
                }
                if ((defaultCurde - lineCurde * 0.1f) != 0f)
                {
                    for (int i = 0; i < parametersCount; i++)
                    {
                        vertices.Add(tempOuterVertices[i + 1]);
                        vertices.Add(tempInnerVertices[i + 1]);
                        vertices.Add(tempInnerVertices[i]);
                    }
                }
                tempOuterVertices.Clear();
                tempInnerVertices.Clear();
            }
        }
Example #3
0
        private void ModifyVertices(List <UIVertex> vertices)
        {
            //print(vertices.Count);
            if (parameters == null)
            {
                return;
            }

            if (ChartUntils.NeedsToUpdateCaches(parameters.Length, startAngleDegree))
            {
                ChartUntils.CacheSinesAndCosines(StartAngleDegree);
            }

            //1 get center point
            Vector3 centerPosition = (vertices[0].position + vertices[2].position) / 2f;

            //2 set xUnit and yUnit
            Vector3 xUnit = (centerPosition.x - vertices[0].position.x) * Vector3.right;
            Vector3 yUnit = (centerPosition.y - vertices[0].position.y) * Vector3.up;

            //3 set uv
            Vector2 centerUv = (vertices[0].uv0 + vertices[2].uv0) / 2f;
            Vector2 uUnit    = (centerUv.x - vertices[0].uv0.x) * Vector3.right;
            Vector2 vUnit    = (centerUv.y - vertices[0].uv0.y) * Vector3.up;

            //3 set color gradual change(any vertex,the result is same)
            Color outerMultipliedColor = ChartUntils.GetMultipliedColor(vertices[0].color, outerColor);
            Color innerMultipledColor  = ChartUntils.GetMultipliedColor(vertices[0].color, innerColor);

            for (int i = 0; i < parameters.Length; i++)
            {
                float parmeter = parameters[i];
                float cosine   = ChartUntils.cacheCosines[i];
                float sine     = ChartUntils.cacheSines[i];

                UIVertex outertmp      = vertices[0];
                float    outerParmeter = parmeter * outerRatio;
                outertmp.position = centerPosition + (xUnit * cosine + yUnit * sine) * outerParmeter;
                outertmp.uv0      = centerUv + (uUnit * cosine + vUnit * sine) * outerParmeter;
                outertmp.color    = outerMultipliedColor;
                tempOuterVertices.Add(outertmp);



                UIVertex innertmp      = vertices[0];
                float    innerParmeter = parmeter * innerRatio;
                innertmp.position = centerPosition + (xUnit * cosine + yUnit * sine) * innerParmeter;
                innertmp.uv0      = centerUv + (uUnit * cosine + vUnit * sine) * innerParmeter;
                innertmp.color    = innerMultipledColor;
                tempInnerVertices.Add(innertmp);
            }

            if (parameters.Length > 0)
            {
                tempOuterVertices.Add(tempOuterVertices[0]);
                tempInnerVertices.Add(tempInnerVertices[0]);
            }

            vertices.Clear();
            if (outerRatio != 0f)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    vertices.Add(tempInnerVertices[i]);
                    vertices.Add(tempOuterVertices[i]);
                    vertices.Add(tempOuterVertices[i + 1]);
                }
            }
            if (innerRatio != 0f)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    vertices.Add(tempOuterVertices[i + 1]);
                    vertices.Add(tempInnerVertices[i + 1]);
                    vertices.Add(tempInnerVertices[i]);
                }
            }
            tempOuterVertices.Clear();
            tempInnerVertices.Clear();
        }
Example #4
0
        private void ModifyVertices(VertexHelper vh)
        {
            tempVertexTriangleStream.Clear();
            vh.GetUIVertexStream(tempVertexTriangleStream);
            vh.Clear();

            float len = 0;

            for (int i = 0; i < keyPos.Count - 1; i++)
            {
                drawAttribute.SetPosition(
                    CacheUnit.SetVector(keyPos[i].x, keyPos[i].y),
                    CacheUnit.SetVector(keyPos[i + 1].x, keyPos[i + 1].y),
                    CacheUnit.SetVector(keyPos[i + 1].x, keyPos[i + 1].y - LineWidth),
                    CacheUnit.SetVector(keyPos[i].x, keyPos[i].y - LineWidth));
                drawAttribute.SetColor(
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, LineColor),
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, LineColor),
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, LineColor),
                    ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, LineColor));
                DrawSimpleQuad(vh, drawAttribute);
            }

            switch (ItemMode)
            {
            case PointItemMode.Square:
                len = lineWidth;
                //画点
                for (int i = 0; i < keyPos.Count; i++)
                {
                    drawAttribute.SetPosition(
                        CacheUnit.SetVector(-len, +len) + keyPos[i],
                        CacheUnit.SetVector(+len, +len) + keyPos[i],
                        CacheUnit.SetVector(+len, -len) + keyPos[i],
                        CacheUnit.SetVector(-len, -len) + keyPos[i]
                        );
                    drawAttribute.SetColor(
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor));
                    DrawSimpleQuad(vh, drawAttribute);
                }
                break;

            case PointItemMode.Triangle:
                len = lineWidth * 3;
                for (int i = 0; i < keyPos.Count; i++)
                {
                    //模拟一个等边三角形
                    drawAttribute.SetPosition(
                        CacheUnit.SetVector(0, (1.732f - 1) * len * 0.5f) + keyPos[i],
                        CacheUnit.SetVector(0, (1.732f - 1) * len * 0.5f) + keyPos[i],
                        CacheUnit.SetVector(len / 2, (-1.732f + 1) * len * 0.5f) + keyPos[i],
                        CacheUnit.SetVector(-len / 2, (-1.732f + 1) * len * 0.5f) + keyPos[i]
                        );
                    drawAttribute.SetColor(
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor));
                    DrawSimpleQuad(vh, drawAttribute);
                }
                break;

            case PointItemMode.Diamond:
                len = lineWidth * 1.5f;
                for (int i = 0; i < keyPos.Count; i++)
                {
                    drawAttribute.SetPosition(
                        CacheUnit.SetVector(len, 0) + keyPos[i],
                        CacheUnit.SetVector(0, -len) + keyPos[i],
                        CacheUnit.SetVector(-len, 0) + keyPos[i],
                        CacheUnit.SetVector(0, len) + keyPos[i]
                        );
                    drawAttribute.SetColor(
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor));
                    DrawSimpleQuad(vh, drawAttribute);
                }
                break;

            case PointItemMode.Star:
                len = lineWidth * 2f;
                float width        = len * Mathf.Cos(54 * Mathf.Deg2Rad);
                float y            = width * Mathf.Tan(36 * Mathf.Deg2Rad);
                float buttomHeight = len * Mathf.Sin(54 * Mathf.Deg2Rad);
                for (int i = 0; i < keyPos.Count; i++)
                {
                    drawAttribute.SetPosition(
                        CacheUnit.SetVector(len * Mathf.Cos(90 * Mathf.Deg2Rad), len * Mathf.Sin(90 * Mathf.Deg2Rad)) + keyPos[i],
                        CacheUnit.SetVector(len * Mathf.Cos(306 * Mathf.Deg2Rad), len * Mathf.Sin(306 * Mathf.Deg2Rad)) + keyPos[i],
                        CacheUnit.SetVector(0, -(buttomHeight - y)) + keyPos[i],
                        CacheUnit.SetVector(len * Mathf.Cos(234 * Mathf.Deg2Rad), len * Mathf.Sin(234 * Mathf.Deg2Rad)) + keyPos[i]
                        );
                    drawAttribute.SetColor(
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor));
                    DrawSimpleQuad(vh, drawAttribute);

                    drawAttribute.SetPosition(
                        CacheUnit.SetVector(len * Mathf.Cos(18 * Mathf.Deg2Rad), len * Mathf.Sin(18 * Mathf.Deg2Rad)) + keyPos[i],
                        CacheUnit.SetVector(0, -(buttomHeight - y)) + keyPos[i],
                        CacheUnit.SetVector(0, -(buttomHeight - y)) + keyPos[i],
                        CacheUnit.SetVector(len * Mathf.Cos(162 * Mathf.Deg2Rad), len * Mathf.Sin(162 * Mathf.Deg2Rad)) + keyPos[i]
                        );
                    drawAttribute.SetColor(
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                        ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor));
                    DrawSimpleQuad(vh, drawAttribute);
                }
                break;

            case PointItemMode.Circle:
                for (int i = 0; i < keyPos.Count; i++)
                {
                    for (int j = 0; j < 24; j++)
                    {
                        float cos = Mathf.Cos(j) * lineWidth, sin = Mathf.Sin(j) * lineWidth;
                        float nextCos = Mathf.Cos(j + 0.0628f * 15f) * lineWidth, nextSin = Mathf.Sin(j + 0.0628f * 15f) * lineWidth;

                        drawAttribute.SetPosition(
                            CacheUnit.SetVector(0, 0) + keyPos[i],
                            CacheUnit.SetVector(nextCos, nextSin) + keyPos[i],
                            CacheUnit.SetVector(cos, sin) + keyPos[i],
                            CacheUnit.SetVector(0, 0) + keyPos[i]
                            );
                        drawAttribute.SetColor(
                            ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                            ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                            ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor),
                            ChartUntils.GetMultipliedColor(tempVertexTriangleStream[0].color, PointColor));
                        DrawSimpleQuad(vh, drawAttribute);
                    }
                }
                break;

            case PointItemMode.None:
                break;

            default:
                break;
            }
        }