public override void Draw( float offsetX, float offsetY, Renderer2D 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)); // 題名 renderer.Color = TextColor; if (text.Length > 0) { renderer.AddText( text, 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), offsetX + LocalLeftX + Width - (BorderWidth * 2f), offsetY + LocalTopY + (BorderWidth * 2f), Width - (BorderWidth * 2f), Height - (BorderWidth * 2f), AlignX.Right); }
public override void Draw( float offsetX, float offsetY, Renderer2D 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), offsetX + LocalLeftX + (BorderWidth * 2f), offsetY + LocalTopY + (BorderWidth * 2f), fontSize); // secondaryは右寄せ renderer.AddText( SecondaryValue.ToString(format), offsetX + LocalLeftX + Width - (BorderWidth * 2f), offsetY + LocalTopY + (BorderWidth * 2f), fontSize, AlignX.Right); } else // ラベルがあれば左にラベル、右にプライマリの数値 { renderer.AddText( Label, offsetX + LocalLeftX + (BorderWidth * 2f), offsetY + LocalTopY + (BorderWidth * 2f), fontSize); // 数字は右寄せ renderer.AddText( PrimaryValue.ToString(format), offsetX + LocalLeftX + Width - (BorderWidth * 2f), offsetY + LocalTopY + (BorderWidth * 2f), fontSize, AlignX.Right); } }
public override void Draw( float offsetX, float offsetY, Renderer2D renderer) { Color32 tmpColor = (On) ? OnColor : OffColor; renderer.Color = tmpColor; if (sprite != null) { renderer.AddSprite( offsetX + LocalLeftX + BorderWidth, offsetY + LocalTopY + BorderWidth, Width - (BorderWidth * 2f), Height - (BorderWidth * 2f), sprite); } else if (texture != null) { renderer.AddTexturedRectangle( offsetX + LocalLeftX + BorderWidth, offsetY + LocalTopY + BorderWidth, Width - (BorderWidth * 2f), Height - (BorderWidth * 2f), texture); } else { renderer.AddRectangle( offsetX + LocalLeftX + BorderWidth, offsetY + LocalTopY + BorderWidth, Width - (BorderWidth * 2f), Height - (BorderWidth * 2f)); } Color32 tmpTextColor = (On) ? OnTextColor : OffTextColor; renderer.Color = tmpTextColor; renderer.AddText( Text, offsetX + LocalLeftX + (Width * 0.5f), offsetY + LocalTopY + (Height * 0.5f), Width - (BorderWidth * 4f), Height - (BorderWidth * 4f), AlignX.Center, AlignY.Center); }
public override void Draw( float offsetX, float offsetY, Renderer2D renderer) { float x = offsetX + LocalLeftX; float y = offsetY + LocalTopY; var primAlignX = AlignX.Left; var primAlignY = AlignY.Top; switch (AlignX) { case AlignX.Center: x += Width * 0.5f; primAlignX = AlignX.Center; break; case AlignX.Right: x += Width; primAlignX = AlignX.Right; break; } switch (AlignY) { case AlignY.Center: y += Height * 0.5f; primAlignY = AlignY.Center; break; case AlignY.Bottom: y += Height; primAlignY = AlignY.Bottom; break; } renderer.Color = Color; renderer.AddText( Value, x, y, fontSize, Width, Height, primAlignX, primAlignY, LineSpacing); }
public override void Draw( float offsetX, float offsetY, Renderer2D renderer) { float margin = BorderEnabled ? (2f * BorderWidth) : 0f; float x = offsetX + LocalLeftX + margin; float y = offsetY + LocalTopY + Height - 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 addedLineCount = renderer.AddText( lines[index], x, y, fontSize, Width - (2f * margin), y - margin - (offsetY + LocalTopY), AlignX.Left, AlignY.Bottom); y -= renderer.CalcLineHeight(fontSize) * addedLineCount; } lineIndex++; } }
public override void Draw( float offsetX, float offsetY, Renderer2D 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 < seriesList.Count; seriesIndex++) { var series = seriesList[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(); }
public override void Draw( float offsetX, float offsetY, Renderer2D 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; } }