public void DrawData(float width, float height, int[] buckets, int totalFrameCount, float min, float max, Color barColor, float spacing) { float range = max - min; //int bucketCount = (range == 0f) ? 1 : buckets.Length; int bucketCount = buckets.Length; float x = (spacing / 2); float y = 0; float w = ((width + spacing) / bucketCount) - spacing; float h = height; float bucketWidth = (range / bucketCount); Rect rect = GUILayoutUtility.GetLastRect(); for (int bucketAt = 0; bucketAt < bucketCount; bucketAt++) { var count = buckets[bucketAt]; float barHeight = (h * count) / totalFrameCount; if (count > 0) // Make sure we always slow a small bar if non zero { barHeight = Mathf.Max(1.0f, barHeight); } m_2D.DrawFilledBox(x, y, w, barHeight, barColor); float bucketStart = min + (bucketAt * bucketWidth); float bucketEnd = bucketStart + bucketWidth; var tooltip = string.Format("{0}-{1}\n{2} {3}\n\nBar width: {4}", m_Units.ToTooltipString(bucketStart, false), m_Units.ToTooltipString(bucketEnd, true), count, count == 1 ? "frame" : "frames", m_Units.ToTooltipString(bucketWidth, true) ); var content = new GUIContent("", tooltip); GUI.Label(new Rect(rect.x + x, rect.y + y, w, h), content); x += w; x += spacing; } }
public int Draw(MarkerData marker, ProfileDataView markerContext, int topNumber, string[] topStrings, int[] topValues) { GUIStyle style = GUI.skin.label; float w = m_WidthColumn0; float h = style.lineHeight; float ySpacing = 2; float barHeight = h - ySpacing; EditorGUILayout.BeginVertical(GUILayout.Width(w + m_WidthColumn1 + m_WidthColumn2 + m_WidthColumn3)); topNumber = DrawTopNumber(topNumber, topStrings, topValues); /* * EditorGUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("", GUILayout.Width(w)); * EditorGUILayout.LabelField("Value", GUILayout.Width(LayoutSize.WidthColumn1)); * EditorGUILayout.LabelField("Frame", GUILayout.Width(LayoutSize.WidthColumn2)); * EditorGUILayout.EndHorizontal(); */ // var frameSummary = m_ProfileSingleView.analysis.GetFrameSummary(); float barMax = marker.msMax; // frameSummary.msMax if (m_Units.Units == Units.Count) { barMax = marker.countMax; } // Marker frames are ordered by frame time // If we are sorting by count then we need to apply a sort bool showCount = m_Units.Units == Units.Count; List <FrameTime> frames = GetTopN(marker, topNumber, showCount); foreach (FrameTime frameTime in frames) { float barValue = (m_Units.Units == Units.Count) ? frameTime.count : frameTime.ms; float barLength = Math.Min((w * barValue) / barMax, w); EditorGUILayout.BeginHorizontal(); if (m_2D.DrawStart(w, h, Draw2D.Origin.TopLeft, style)) { m_2D.DrawFilledBox(0, ySpacing, barLength, barHeight, colorBar); m_2D.DrawFilledBox(barLength, ySpacing, w - barLength, barHeight, colorBarBackground); m_2D.DrawEnd(); Rect rect = GUILayoutUtility.GetLastRect(); GUI.Label(rect, new GUIContent("", m_Units.ToTooltipString(barValue, true))); } EditorGUILayout.LabelField(m_Units.ToGUIContentWithTooltips(barValue, true), GUILayout.Width(m_WidthColumn2)); if (m_DrawFrameIndexButton != null) { m_DrawFrameIndexButton(frameTime.frameIndex, markerContext); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } // Show blank space for missing frames var content = new GUIContent("", ""); Vector2 size = GUI.skin.button.CalcSize(content); h = Math.Max(barHeight, size.y); for (int i = frames.Count; i < topNumber; i++) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Height(h)); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); return(topNumber); }
string ToTooltipDisplayUnits(float ms, bool showUnits = false) { return(m_Units.ToTooltipString(ms, showUnits)); }