public override void Draw( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { renderer.color = new Color32(255, 255, 255, 255); if (_sprite != null) { renderer.AddSprite( offsetX + localLeftX, offsetY + localTopY, width, height, _sprite); } else if (_texture != null) { renderer.AddTexturedRectangle( offsetX + localLeftX, offsetY + localTopY, width, height, _texture); } else { renderer.AddRectangle( offsetX + localLeftX, offsetY + localTopY, width, height); } }
public override void Draw( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { float x = offsetX + localLeftX + (2f * borderWidth); float y = offsetY + localTopY + (2f * borderWidth); float textWidth = width - (4f * borderWidth); int lineCount = _lines.Length; for (int i = 0; i < lineCount; i++) { int index = i + _nextLinePos; index = (index >= lineCount) ? (index - lineCount) : index; if (_lines[index] != null) { DrawTextSingleLine( renderer, _lines[index], _colors[index], _fontSize, x, y, textWidth, _lineHeight); y += _lineHeight; } } }
protected static void DrawTextMultiLine( DebugPrimitiveRenderer2D renderer, string text, Color32 color, float fontSize, float leftX, float topY, float width, float height, bool autoLineBreak = false, bool rotateToVertical = false, float lineHeight = DebugPrimitiveRenderer.DefaultLineHeight) { if (string.IsNullOrEmpty(text)) { return; } renderer.color = color; renderer.AddTextMultiLine( text, fontSize, leftX, topY, width, height, autoLineBreak, rotateToVertical, lineHeight); }
public void Initialize(DebugPrimitiveRenderer2D renderer) { _renderer = renderer; _root = new DebugUiControl(); _input = new Input(); this.raycastTarget = true; inputEnabled = true; }
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); }
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); } }
protected override void DrawChildren( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { var child = _firstChild; while (child != null) { child.DrawRecursive(offsetX, offsetY, renderer); child = child.nextBrother; } }
public override void DrawPostChild( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { if ((_activeIndex >= 0) && (_activeIndex < _activeMenu.itemCount)) { var item = _activeMenu.GetItem(_activeIndex); var button = item.button; button.color = this.color; button.textColor = this.textColor; } }
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 = (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; DrawTextAuto( renderer, text, tmpTextColor, offsetX + localLeftX + (borderWidth * 2f), offsetY + localTopY + (borderWidth * 2f), width - (borderWidth * 4f), height - (borderWidth * 4f), _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); }
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); }
public static DebugUiManager Create( GameObject parentGameObject, DebugPrimitiveRenderer2D renderer) { var self = parentGameObject.AddComponent <DebugUiManager>(); self.Initialize(renderer); Debug.Assert(self.rectTransform != null, "RectTransformがない!canvasの下にあるGameObjectを指定してください!"); if (self.rectTransform != null) { self.rectTransform.anchorMin = new Vector2(0f, 0f); self.rectTransform.anchorMax = new Vector2(1f, 1f); self.rectTransform.offsetMin = new Vector2(0f, 0f); self.rectTransform.offsetMax = new Vector2(0f, 0f); } return(self); }
public override void Draw( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { DrawTextMultiLine( renderer, text, color, _fontSize, offsetX + localLeftX, offsetY + localTopY, width, height, true, _rotateToVertical, lineHeight); }
public void DrawRecursive( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { if (!_enabled) { return; } // まず自分描画 if (backgroundEnabled) { renderer.color = backgroundColor; renderer.AddRectangle( offsetX + localLeftX, offsetY + localTopY, width, height); } if (borderEnabled) { renderer.color = borderColor; renderer.AddRectangleFrame( offsetX + localLeftX, offsetY + localTopY, width, height, borderWidth); } Draw(offsetX, offsetY, renderer); // グローバル座標を計算して子を描画 float globalLeftX = offsetX + localLeftX; float globalTopY = offsetY + localTopY; var child = _firstChild; while (child != null) { child.DrawRecursive(globalLeftX, globalTopY, renderer); child = child._nextBrother; } }
/// フォントサイズ自動計算。lineSpacingRatioは自動計算されたフォントサイズを基準にした行間スペース protected static void DrawTextAuto( DebugPrimitiveRenderer2D renderer, string text, Color32 color, float leftX, float topY, float width, float height, bool rotateToVertical = false, float lineSpacingRatio = 0.2f) { int textLength = text.Length; if (textLength <= 0) { return; } // ボタンの縦横比と文字数から妥当な行数を決める float fontSize; if (rotateToVertical) { fontSize = CalcOptimalFontSize(height, width, textLength, lineSpacingRatio); } else { fontSize = CalcOptimalFontSize(width, height, textLength, lineSpacingRatio); } fontSize *= 0.9f; //入り切らないことがあるので少し小さく DrawTextMultiLine( renderer, text, color, fontSize, leftX, topY, width, height, true, rotateToVertical, fontSize * (1f + lineSpacingRatio)); }
void DrawGauge( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer, float value, Color32 color) { // seconadary float ratio = (value - _min) / (_max - _min); ratio = (ratio < 0f) ? 0f : ((ratio > 1f) ? 1f : ratio); float length = ratio * (width - (2f * borderWidth)); renderer.color = color; renderer.AddRectangle( offsetX + localLeftX + borderWidth, offsetY + localTopY + borderWidth, length, height - (2f * borderWidth)); }
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++; } }
public void DrawRecursive( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { if (!_enabled) { return; } // まず自分描画 if (backgroundEnabled) { renderer.color = backgroundColor; renderer.AddRectangle( offsetX + localLeftX, offsetY + localTopY, width, height); } if (borderEnabled) { renderer.color = borderColor; renderer.AddRectangleFrame( offsetX + localLeftX, offsetY + localTopY, width, height, borderWidth); } Draw(offsetX, offsetY, renderer); // グローバル座標を計算して子を描画 float globalLeftX = offsetX + localLeftX; float globalTopY = offsetY + localTopY; DrawChildren(globalLeftX, globalTopY, renderer); DrawPostChild(offsetX, offsetY, renderer); }
void Initialize( DebugPrimitiveRenderer2D renderer, Camera camera, Transform meshTransform, int referenceScreenWidth, int referenceScreenHeight, float screenPlaneDistance) { safeAreaVisualizationEnabled = true; this.scale = 1f; _renderer = renderer; _camera = camera; _screenPlaneDistance = screenPlaneDistance; _meshTransform = meshTransform; _referenceScreenHeight = referenceScreenHeight; _referenceScreenWidth = referenceScreenWidth; _root = new DebugUiContainer(name: "RootContainer"); _input = new Input(); inputEnabled = true; // 初回サイズ決定 UpdateTransform(); }
public override void Draw( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { // 単純な折れ線だけとりあえず用意 float netHeight = height - (2f * borderWidth); float xScale = CalcXScale(); float xOffset = offsetX + localLeftX; float yScale = -netHeight / (_yMax - _yMin); float yOffset = offsetY + localTopY + height - borderWidth; for (int i = 1; i < _data.Count; i++) { var d0 = _data[i - 1]; var d1 = _data[i]; var x0 = (d0.time * xScale) + xOffset; var x1 = (d1.time * xScale) + xOffset; var y0 = (d0.value * yScale) + yOffset; var y1 = (d1.value * yScale) + yOffset; renderer.AddLine(x0, y0, x1, y1, 1f); } }
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) { DrawTextMultiLine( renderer, cell.text, textColor, _fontSize, x, y, cellWidth, cellHeight, true); } x += cellWidth + borderWidth; } y += cellHeight + borderWidth; } }
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(); }
public void Dispose() { _root = null; _input = null; _renderer = null; }
protected virtual void DrawChildren( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { }
public virtual void Draw( float offsetX, float offsetY, DebugPrimitiveRenderer2D renderer) { }