Exemplo n.º 1
0
        public override void ApplyOption()
        {
            ChartInstance chart = GUIChartEditor.CurrentChart;

            // Draws vertical lines.
            float x = chart.minX + (Mathf.Abs(chart.minX) % hSize);

            while (x < chart.maxX)
            {
                GUIChartEditor.PushLineChart(new Vector2[]
                {
                    new Vector2(x, chart.minY),
                    new Vector2(x, chart.maxY)
                }, gridColor);

                if (addLabels && x != 0 && x > chart.minX)
                {
                    float minHeight = Mathf.Ceil(GUIChartEditor.sprites.Digits["0"].height / 2 + 2);
                    float vOffset   = minHeight * GUIChartEditor.CurrentChart.userDefinedRect.height
                                      / GUIChartEditor.CurrentChart.pixelSizeRect.height;
                    GUIChartEditor.PushValueLabel(x, x, -vOffset, "0.0#");
                }

                x += hSize;
            }

            // Draws horizontal lines.
            float y = chart.minY + (Mathf.Abs(chart.minY) % vSize);

            while (y < chart.maxY)
            {
                GUIChartEditor.PushLineChart(new Vector2[]
                {
                    new Vector2(chart.minX, y),
                    new Vector2(chart.maxX, y)
                }, gridColor);

                if (addLabels && y != 0 && y > chart.minY)
                {
                    string label = y.ToString("0.0#").Replace(',', '.');
                    float  hSize = 0f;
                    foreach (char c in label)
                    {
                        hSize += GUIChartEditor.sprites.Digits[c.ToString()].width + 1;
                    }
                    float hOffset = hSize / 2 * GUIChartEditor.CurrentChart.userDefinedRect.width
                                    / GUIChartEditor.CurrentChart.pixelSizeRect.width;
                    GUIChartEditor.PushValueLabel(y, -hOffset, y, "0.0#");
                }

                y += vSize;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts drawing a new chart.
        /// </summary>
        /// <param name="layoutRect">The <see cref="Rect"/> used as layout.</param>
        /// <param name="backgroundColor">The color used for the background.</param>
        /// <param name="options">A set of options for customizing the chart.</param>
        public static void BeginChart(Rect layoutRect, Color backgroundColor, params ChartOption[] options)
        {
            // Creates new instance of a chart.
            CurrentChart = new ChartInstance(layoutRect, backgroundColor);

            // Default material
            CurrentChart.material = new Material(Shader.Find("Hidden/Internal-Colored"));

            // Applies options.
            var optionsList = new List <ChartOption>(options);

            optionsList.Sort(new ChartOptionComparer());
            foreach (var option in optionsList)
            {
                option.ApplyOption();
            }
        }