public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            DrawGauge(offsetX, offsetY, renderer, secondaryValue, secondaryGaugeColor);
            DrawGauge(offsetX, offsetY, renderer, primaryValue, primaryGaugeColor);

            float fontSize = height - (2f * borderWidth);

            fontSize      *= 0.8f;
            renderer.color = textColor;
            string format = _asInteger ? "F0" : "F1";

            if (string.IsNullOrEmpty(label))             // ラベルがなければ両方の数字を左右に分けて出す
            {
                // primaryは左寄せ
                renderer.AddText(
                    primaryValue.ToString(format),
                    fontSize,
                    offsetX + localLeftX + (borderWidth * 2f),
                    offsetY + localTopY + (borderWidth * 2f),
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f));

                // secondaryは右寄せ
                renderer.AddText(
                    secondaryValue.ToString(format),
                    fontSize,
                    offsetX + localLeftX + (borderWidth * 2f),
                    offsetY + localTopY + (borderWidth * 2f),
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f),
                    DebugPrimitiveRenderer.Alignment.Right);
            }
            else             // ラベルがあれば左にラベル、右にプライマリの数値
            {
                renderer.AddText(
                    label,
                    fontSize,
                    offsetX + localLeftX + (borderWidth * 2f),
                    offsetY + localTopY + (borderWidth * 2f),
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f));

                // 数字は右寄せ
                renderer.AddText(
                    primaryValue.ToString(format),
                    fontSize,
                    offsetX + localLeftX + (borderWidth * 2f),
                    offsetY + localTopY + (borderWidth * 2f),
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f),
                    DebugPrimitiveRenderer.Alignment.Right);
            }
        }
Example #2
0
        public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            // 棒を描画
            float ratio;

            if (_mode == Mode.Log10)
            {
                float logMin = Mathf.Log10(_min);
                float logMax = Mathf.Log10(_max);
                ratio = (Mathf.Log10(value) - logMin) / (logMax - logMin);
            }
            else
            {
                ratio = (value - _min) / (_max - _min);
            }
            ratio = (ratio < 0f) ? 0f : ((ratio > 1f) ? 1f : ratio);
            float barWidth = (width - (2f * borderWidth)) * ratio;

            renderer.color = gaugeColor;
            renderer.AddRectangle(
                offsetX + localLeftX + borderWidth,
                offsetY + localTopY + borderWidth,
                barWidth,
                height - (2f * borderWidth));

            // 題名
            float fontSize = height - (2f * borderWidth);

            fontSize      *= 0.8f;
            renderer.color = textColor;
            if (_text.Length > 0)
            {
                renderer.AddText(
                    _text,
                    fontSize,
                    offsetX + localLeftX + (borderWidth * 2f),
                    offsetY + localTopY + (borderWidth * 2f),
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f));
            }

            string formatString = (_mode == Mode.Integer) ? "F0" : "F2";

            // 数字は右寄せ
            renderer.AddText(
                value.ToString(formatString),
                fontSize,
                offsetX + localLeftX + (borderWidth * 2f),
                offsetY + localTopY + (borderWidth * 2f),
                width - (borderWidth * 2f),
                height - (borderWidth * 2f),
                DebugPrimitiveRenderer.Alignment.Right);
        }
Example #3
0
        private void DrawDragMark(DebugUiControl dragged)
        {
            float s  = dragged.dragMarkSize;
            float x0 = _input.pointerX;
            float y0 = _input.pointerY;
            float x1 = x0 - (s * 0.5f);
            float y1 = y0 - s;
            float x2 = x0 + (s * 0.5f);
            float y2 = y0 - s;

            // 背景
            _renderer.color = dragged.dragMarkColor;
            _renderer.AddTriangle(x0, y0, x1, y1, x2, y2);
            // 枠
            _renderer.color = new Color32(255, 255, 255, 255);
            _renderer.AddTriangleFrame(x0, y0, x1, y1, x2, y2, s * 0.125f);
            // テキスト
            if (dragged.dragMarkLetter != '\0')
            {
                _renderer.color = dragged.dragMarkLetterColor;
                _renderer.AddText(
                    new string(dragged.dragMarkLetter, 1),
                    s * 0.5f,
                    x0 - (s * 0.25f),
                    y1,
                    dragged.dragMarkSize,
                    dragged.dragMarkSize);
            }
        }
Example #4
0
        protected static void DrawTextSingleLine(
            DebugPrimitiveRenderer2D renderer,
            string text,
            Color32 color,
            float fontSize,
            float leftX,
            float topY,
            float width,
            float height,
            bool leftAlign        = true,
            bool rotateToVertical = false)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            renderer.color = color;
            float x = leftX;
            float y = topY;

            DebugPrimitiveRenderer.Alignment align;
            if (leftAlign)
            {
                align = DebugPrimitiveRenderer.Alignment.Left;
            }
            else
            {
                if (rotateToVertical)
                {
                    y = topY + height;
                }
                else
                {
                    x = leftX + width;
                }
                align = DebugPrimitiveRenderer.Alignment.Right;
            }

            renderer.AddText(
                text,
                fontSize,
                x,
                y,
                width,
                height,
                align,
                rotateToVertical);
        }
        public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            Color32 tmpColor = (isPointerDown) ? pointerDownColor : color;

            renderer.color = tmpColor;
            if (texture != null)
            {
                renderer.AddTexturedRectangle(
                    offsetX + localLeftX + borderWidth,
                    offsetY + localTopY + borderWidth,
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f),
                    texture);
            }
            else if (sprite != null)
            {
                renderer.AddSprite(
                    offsetX + localLeftX + borderWidth,
                    offsetY + localTopY + borderWidth,
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f),
                    sprite);
            }
            else
            {
                renderer.AddRectangle(
                    offsetX + localLeftX + borderWidth,
                    offsetY + localTopY + borderWidth,
                    width - (borderWidth * 2f),
                    height - (borderWidth * 2f));
            }

            Color32 tmpTextColor = (isPointerDown) ? pointerDownTextColor : textColor;

            renderer.color = tmpTextColor;
            renderer.AddText(
                text,
                offsetX + localLeftX + (width * 0.5f),
                offsetY + localTopY + (height * 0.5f),
                width - (borderWidth * 4f),
                height - (borderWidth * 4f),
                DebugPrimitiveRenderer.AlignX.Center,
                DebugPrimitiveRenderer.AlignY.Center);
        }
Example #6
0
        public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            float x          = offsetX + this.localLeftX;
            float y          = offsetY + this.localTopY;
            var   primAlignX = DebugPrimitiveRenderer.AlignX.Left;
            var   primAlignY = DebugPrimitiveRenderer.AlignY.Top;

            switch (this.alignX)
            {
            case AlignX.Center:
                x         += this.width * 0.5f;
                primAlignX = DebugPrimitiveRenderer.AlignX.Center;
                break;

            case AlignX.Right:
                x         += this.width;
                primAlignX = DebugPrimitiveRenderer.AlignX.Right;
                break;
            }
            switch (this.alignY)
            {
            case AlignY.Center:
                y         += this.height * 0.5f;
                primAlignY = DebugPrimitiveRenderer.AlignY.Center;
                break;

            case AlignY.Bottom:
                y         += this.height;
                primAlignY = DebugPrimitiveRenderer.AlignY.Bottom;
                break;
            }
            renderer.color = this.color;
            renderer.AddText(
                this.text,
                x,
                y,
                _fontSize,
                this.width,
                this.height,
                primAlignX,
                primAlignY,
                this.lineSpacing);
        }
Example #7
0
        public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            float margin    = borderEnabled ? (2f * borderWidth) : 0f;
            float x         = offsetX + localLeftX + margin;
            float y         = offsetY + localTopY + this.height - margin;     // 下端から上へ向かって描画する
            float textWidth = width - (2f * margin);
            int   lineCount = _lines.Length;
            int   lineIndex = 0;

            while (lineIndex < lineCount)
            {
                int index = _nextLinePos - 1 - lineIndex;
                if (index < 0)
                {
                    index += lineCount;
                }
                else if (index >= lineCount)
                {
                    index -= lineCount;
                }
                if (_lines[index] != null)
                {
                    renderer.color = _colors[index];
                    var lines = renderer.AddText(
                        _lines[index],
                        x,
                        y,
                        _fontSize,
                        width - (2f * margin),
                        y - margin - (offsetY + localTopY),
                        DebugPrimitiveRenderer.AlignX.Left,
                        DebugPrimitiveRenderer.AlignY.Bottom);
                    y -= renderer.CalcLineHeight(_fontSize) * lines;
                }
                lineIndex++;
            }
        }
Example #8
0
        public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            // 罫線を描く
            renderer.color = borderColor;
            // まず縦
            int   end             = _widths.Length - 1; // 最後の右端線は不要
            float x               = offsetX + localLeftX + borderWidth;
            float topY            = offsetY + localTopY;
            float halfBorderWidth = borderWidth * 0.5f;

            for (int i = 0; i < end; i++)
            {
                x += _widths[i];
                x += halfBorderWidth;                 // 線の中心までずらす
                renderer.AddVerticalLine(
                    x,
                    topY,
                    height,
                    borderWidth);
                x += halfBorderWidth;
            }
            // 次に横
            end = _heights.Length - 1;             // 最後の下端線は不要
            float y     = offsetY + localTopY + borderWidth;
            float leftX = offsetX + localLeftX;

            for (int i = 0; i < end; i++)
            {
                y += _heights[i];
                y += halfBorderWidth;                 // 線の中心までずらす
                renderer.AddHorizontalLine(
                    leftX,
                    y,
                    width,
                    borderWidth);
                y += halfBorderWidth;
            }

            y = offsetY + localTopY + borderWidth;
            for (int rowIndex = 0; rowIndex < _heights.Length; rowIndex++)
            {
                float cellHeight = _heights[rowIndex];
                x = offsetX + localLeftX + borderWidth;
                for (int colIndex = 0; colIndex < _widths.Length; colIndex++)
                {
                    float cellWidth = _widths[colIndex];
                    var   cell      = cells[rowIndex, colIndex];
                    if (string.IsNullOrEmpty(cell.text) == false)
                    {
                        renderer.color = textColor;
                        renderer.AddText(
                            cell.text,
                            x,
                            y,
                            _fontSize);
                    }
                    x += cellWidth + borderWidth;
                }
                y += cellHeight + borderWidth;
            }
        }
Example #9
0
        public override void Draw(
            float offsetX,
            float offsetY,
            DebugPrimitiveRenderer2D renderer)
        {
            UnityEngine.Profiling.Profiler.BeginSample("DebugUiGraph.Draw");
            var now       = Time.time;
            var startTime = now - _duration;
            // 単純な折れ線だけとりあえず用意
            float netHeight = height - (2f * borderWidth);
            float xScale    = CalcXScale();
            float xOffset   = offsetX + localLeftX + borderWidth;
            float yScale    = -netHeight / _yWidth;
            float yOffset   = offsetY + localTopY + height - borderWidth - (netHeight * 0.5f);
            float yMin      = float.MaxValue;
            float yMax      = -yMin;

            for (int seriesIndex = 0; seriesIndex < _series.Count; seriesIndex++)
            {
                var series    = _series[seriesIndex];
                int dst       = 0;
                int dataCount = series.data.Count;
                renderer.color = series.color;
                // 最初のデータを打ち込むところまでまず回す
                UnityEngine.Profiling.Profiler.BeginSample("DebugUiGraph.Draw FirstLine");
                int dataIndex = 0;
                while (dataIndex < (dataCount - 1))
                {
                    series.data[dst] = series.data[dataIndex];
                    var d0 = series.data[dataIndex];
                    var d1 = series.data[dataIndex + 1];
                    dataIndex++;
                    if ((d0.time >= startTime) && (d1.time >= startTime))                     // どちらか範囲内なら描画
                    {
                        var x0 = ((d0.time - startTime) * xScale) + xOffset;
                        var x1 = ((d1.time - startTime) * xScale) + xOffset;
                        var y0 = ((d0.value - _yCenter) * yScale) + yOffset;
                        var y1 = ((d1.value - _yCenter) * yScale) + yOffset;
                        renderer.AddLine(x0, y0, x1, y1, 1f);
                        dst++;
                        yMin = Mathf.Min(yMin, d0.value);
                        yMax = Mathf.Max(yMax, d0.value);
                        break;
                    }
                }
                UnityEngine.Profiling.Profiler.EndSample();

                // 続き描画
                UnityEngine.Profiling.Profiler.BeginSample("DebugUiGraph.Draw FollowingLines");
                while (dataIndex < (dataCount - 1))
                {
                    series.data[dst] = series.data[dataIndex];
                    var d0 = series.data[dataIndex];
                    var d1 = series.data[dataIndex + 1];
                    dataIndex++;
                    var x1 = ((d1.time - startTime) * xScale) + xOffset;
                    var y1 = ((d1.value - _yCenter) * yScale) + yOffset;
                    renderer.ContinueLine(x1, y1, 1f);
                    dst++;
                    yMin = Mathf.Min(yMin, d0.value);
                    yMax = Mathf.Max(yMax, d0.value);
                }
                UnityEngine.Profiling.Profiler.EndSample();

                if (dataCount > 0)
                {
                    var last = series.data[dataCount - 1];
                    series.data[dst] = last;
                    dst++;
                    series.data.RemoveRange(dst, dataCount - dst);
                    yMin = Mathf.Min(yMin, last.value);
                    yMax = Mathf.Max(yMax, last.value);
                }
            }

            if (yMin != float.MaxValue)             // データがある
            {
                _yCenterGoal = (yMin + yMax) * 0.5f;
                if (yMin != yMax)                 // 最低2種以上値がある
                {
                    _yWidthGoal = (yMax - yMin);
                }
            }
            yMin = _yCenter - (_yWidth * 0.5f);
            yMax = _yCenter + (_yWidth * 0.5f);

            renderer.color = new Color32(255, 255, 255, 255);
            renderer.AddText(
                yMax.ToString("F3"),
                offsetX + localLeftX + borderWidth,
                offsetY + localTopY + borderWidth,
                10f);
            renderer.AddText(
                yMin.ToString("F3"),
                offsetX + localLeftX + borderWidth,
                offsetY + localTopY + borderWidth + netHeight - 10f,
                10f);
            UnityEngine.Profiling.Profiler.EndSample();
        }