public void DrawBackground(float width, float height, int bucketCount, float spacing) { float x = (spacing / 2); float y = 0; float w = ((width + spacing) / bucketCount) - spacing; float h = height; for (int i = 0; i < bucketCount; i++) { m_2D.DrawFilledBox(x, y, w, h, m_ColorBarBackground); x += w; x += spacing; } }
void ShowBar(Rect rect, float ms, float range, GUIContent content) { if (ms > 0.0f) { if (m_2D.DrawStart(rect)) { float w = Math.Max(1.0f, rect.width * ms / range); m_2D.DrawFilledBox(0, 1, w, rect.height - 1, m_BarColor); m_2D.DrawEnd(); } } GUI.Label(rect, content); }
public int Draw(MarkerData marker, 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.ToString(barValue, true, 5))); } EditorGUILayout.LabelField(ToDisplayUnitsWithTooltips(barValue, true), GUILayout.Width(m_WidthColumn2)); if (m_DrawFrameIndexButton != null) { m_DrawFrameIndexButton(frameTime.frameIndex); } 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); }
public void Draw(ProfileAnalysis analysis, Rect rect, Color barColor, int barCount, float timeRange, int depthFilter, Color selectedBackground, Color selectedBorder, Color selectedText, bool includeOthers, bool includeUnaccounted) { if (analysis == null) { return; } FrameSummary frameSummary = analysis.GetFrameSummary(); if (frameSummary == null) { return; } var markers = analysis.GetMarkers(); if (markers == null) { return; } // Start by adding frame link button for median frame int buttonWidth = 50; int buttonWidthWithoutMargins = buttonWidth - 4; Rect buttonRect = new Rect(rect.x, rect.y, buttonWidthWithoutMargins, rect.height); m_ProfileAnalyzerWindow.DrawFrameIndexButton(buttonRect, frameSummary.medianFrameIndex); // After the marker graph we want an indication of the time range int rangeLabelWidth = 60; Rect rangeLabelRect = new Rect(rect.x + rect.width - rangeLabelWidth, rect.y, rangeLabelWidth, rect.height); string timeRangeString = ToDisplayUnits(timeRange, true); string frameTimeString = ToDisplayUnits(frameSummary.msMedian, true, 0); string timeRangeTooltip = string.Format("{0} median frame time", frameTimeString); GUI.Label(rangeLabelRect, new GUIContent(timeRangeString, timeRangeTooltip)); // Reduce the size of the marker graph for the button/label we just added rect.x += buttonWidth; rect.width -= (buttonWidth + rangeLabelWidth); // Show marker graph float x = 0; float y = 0; float width = rect.width; float height = rect.height; int max = barCount; int at = 0; var selectedPairingMarkerName = m_ProfileAnalyzerWindow.GetSelectedMarkerName(); float spacing = 2; float other = 0.0f; List <string> nameFilters = m_ProfileAnalyzerWindow.GetNameFilters(); List <string> nameExcludes = m_ProfileAnalyzerWindow.GetNameExcludes(); if (timeRange <= 0.0f) { timeRange = frameSummary.msMedian; } float msToWidth = (width - spacing) / timeRange; float totalMarkerTime = 0; if (m_2D.DrawStart(rect, Draw2D.Origin.BottomLeft)) { m_2D.DrawFilledBox(x, y, width, height, m_BackgroundColor); foreach (var marker in markers) { float ms = MarkerData.GetMsAtMedian(marker); totalMarkerTime += ms; if (depthFilter >= 0 && marker.minDepth != depthFilter) { continue; } if (nameFilters.Count > 0) { if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters)) { continue; } } if (nameExcludes.Count > 0) { if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes)) { continue; } } if (at < max) { float w = ms * msToWidth; if (x + w > width) { w = width - x; } if (marker.name == selectedPairingMarkerName) { m_2D.DrawFilledBox(x + 1, y + 1, w, height - 2, selectedBorder); m_2D.DrawFilledBox(x + 2, y + 2, w - 2, height - 4, selectedBackground); } else { m_2D.DrawFilledBox(x + 2, y + 2, w - 2, height - 4, barColor); } x += w; } else { other += ms; if (!includeOthers) { break; } } at++; } if (includeOthers && other > 0.0f) { x += DrawBar(x, y, other, msToWidth, width, height, barColor); } if (includeUnaccounted && totalMarkerTime < frameSummary.msMedian) { float unaccounted = frameSummary.msMedian - totalMarkerTime; Color color = new Color(barColor.r * 0.5f, barColor.g * 0.5f, barColor.b * 0.5f, barColor.a); x += DrawBar(x, y, unaccounted, msToWidth, width, height, color); } m_2D.DrawEnd(); } else if (includeOthers) { // Need to calculate the size of the others for the input phase if not drawing at this time at = 0; foreach (var marker in markers) { float ms = MarkerData.GetMsAtMedian(marker); totalMarkerTime += ms; if (depthFilter >= 0 && marker.minDepth != depthFilter) { continue; } if (nameFilters.Count > 0) { if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters)) { continue; } } if (nameExcludes.Count > 0) { if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes)) { continue; } } if (at >= max) { other += ms; if (!includeOthers) { break; } } at++; } } at = 0; x = 0.0f; GUIStyle centreAlignStyle = new GUIStyle(GUI.skin.label); centreAlignStyle.alignment = TextAnchor.MiddleCenter; centreAlignStyle.normal.textColor = m_TextColor; GUIStyle leftAlignStyle = new GUIStyle(GUI.skin.label); leftAlignStyle.alignment = TextAnchor.MiddleLeft; leftAlignStyle.normal.textColor = m_TextColor; Color contentColor = GUI.contentColor; for (int index = 0; index < markers.Count; index++) { var marker = markers[index]; if (depthFilter >= 0 && marker.minDepth != depthFilter) { continue; } if (nameFilters.Count > 0) { if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters)) { continue; } } if (nameExcludes.Count > 0) { if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes)) { continue; } } if (at < max) { float w = MarkerData.GetMsAtMedian(marker) * msToWidth; if (x + w > width) { w = width - x; } Rect labelRect = new Rect(rect.x + x, rect.y, w, rect.height); GUIStyle style = centreAlignStyle; String displayName = ""; if (w >= 20) { displayName = marker.name; Vector2 size = centreAlignStyle.CalcSize(new GUIContent(marker.name)); if (size.x > w) { var words = marker.name.Split('.'); displayName = words[words.Length - 1]; style = leftAlignStyle; } } float percentAtMedian = MarkerData.GetMsAtMedian(marker) * 100 / timeRange; string tooltip = string.Format("{0}\n{1:f2}% ({2} on median frame {3})\n\nMedian marker time (in currently selected frames)\n{4} on frame {5}", marker.name, percentAtMedian, ToDisplayUnits(marker.msAtMedian, true, 0), frameSummary.medianFrameIndex, ToDisplayUnits(marker.msMedian, true, 0), marker.medianFrameIndex); if (marker.name == selectedPairingMarkerName) { style.normal.textColor = selectedText; } else { style.normal.textColor = m_TextColor; } GUI.Label(labelRect, new GUIContent(displayName, tooltip), style); Event current = Event.current; if (labelRect.Contains(current.mousePosition)) { if (current.type == EventType.ContextClick) { GenericMenu menu = new GenericMenu(); menu.AddItem(Styles.menuItemSelectFramesInAll, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(marker.name, false)); menu.AddItem(Styles.menuItemSelectFramesInCurrent, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(marker.name, true)); menu.AddItem(Styles.menuItemSelectFramesAll, false, m_ProfileAnalyzerWindow.SelectAllFrames); menu.AddSeparator(""); if (!m_ProfileAnalyzerWindow.GetNameFilters().Contains(marker.name)) { menu.AddItem(Styles.menuItemAddToIncludeFilter, false, () => m_ProfileAnalyzerWindow.AddToIncludeFilter(marker.name)); } else { menu.AddItem(Styles.menuItemRemoveFromIncludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromIncludeFilter(marker.name)); } if (!m_ProfileAnalyzerWindow.GetNameExcludes().Contains(marker.name)) { menu.AddItem(Styles.menuItemAddToExcludeFilter, false, () => m_ProfileAnalyzerWindow.AddToExcludeFilter(marker.name)); } else { menu.AddItem(Styles.menuItemRemoveFromExcludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromExcludeFilter(marker.name)); } menu.AddSeparator(""); menu.AddItem(Styles.menuItemSetAsParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(marker.name)); menu.AddItem(Styles.menuItemClearParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter("")); menu.AddSeparator(""); menu.AddItem(Styles.menuItemCopyToClipboard, false, () => CopyToClipboard(current, marker.name)); menu.ShowAsContext(); current.Use(); } if (current.type == EventType.MouseDown) { m_ProfileAnalyzerWindow.SelectMarker(marker.name); m_ProfileAnalyzerWindow.RequestRepaint(); } } x += w; } else { break; } at++; } if (includeOthers) { x += DrawBarText(rect, x, other, "Others", msToWidth, timeRange, leftAlignStyle, frameSummary.medianFrameIndex); } if (includeUnaccounted && totalMarkerTime < frameSummary.msMedian) { float unaccounted = frameSummary.msMedian - totalMarkerTime; x += DrawBarText(rect, x, unaccounted, "Unaccounted", msToWidth, timeRange, leftAlignStyle, frameSummary.medianFrameIndex); } }
public int Draw(MarkerData marker, 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)); 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; } FrameTime zeroTime = new FrameTime(0, 0.0f, 0); int index = marker.frames.Count - 1; for (int i = 0; i < topNumber; i++) { FrameTime frameTime = new FrameTime((index >= 0) ? marker.frames[index] : zeroTime); 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)) { if (i < marker.frames.Count) { 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.ToString(barValue, true, 5))); } if (i < marker.frames.Count) { EditorGUILayout.LabelField(ToDisplayUnitsWithTooltips(barValue, true), GUILayout.Width(m_WidthColumn2)); if (m_DrawFrameIndexButton != null) { m_DrawFrameIndexButton(marker.frames[index].frameIndex); } } EditorGUILayout.EndHorizontal(); index--; } EditorGUILayout.EndVertical(); return(topNumber); }
public void Draw(Rect rect, float x, float y, float w, float h, float min, float lowerQuartile, float median, float upperQuartile, float max, float yAxisStart, float yAxisEnd, Color color, Color colorFilled, bool clearFirst = true) { string tooltip = GetTooltip(min, lowerQuartile, median, upperQuartile, max); GUI.Label(rect, new GUIContent("", tooltip)); if (clearFirst) { m_2D.DrawFilledBox(x, y, w, h, m_ColorBackground); } float first = yAxisStart; float last = yAxisEnd; float range = last - first; bool startCap = (min >= first) ? true : false; bool endCap = (max <= last) ? true : false; // Range clamping min = ClampToRange(min, first, last); lowerQuartile = ClampToRange(lowerQuartile, first, last); median = ClampToRange(median, first, last); upperQuartile = ClampToRange(upperQuartile, first, last); max = ClampToRange(max, first, last); float hMax = h - 1; float yMin = hMax * (min - first) / range; float yLowerQuartile = hMax * (lowerQuartile - first) / range; float yMedian = hMax * (median - first) / range; float yUpperQuartile = hMax * (upperQuartile - first) / range; float yMax = hMax * (max - first) / range; // Min to max line float xCentre = x + (w / 2); m_2D.DrawLine(xCentre, y + yMin, xCentre, y + yLowerQuartile, color); m_2D.DrawLine(xCentre, y + yUpperQuartile, xCentre, y + yMax, color); // Quartile boxes float xMargin = (2 * w / 8); float x1 = x + xMargin; float x2 = x + (w - xMargin); float wBox = x2 - x1; if (colorFilled != color) { m_2D.DrawFilledBox(x1, y + yLowerQuartile, wBox, (yMedian - yLowerQuartile), colorFilled); } m_2D.DrawBox(x1, y + yLowerQuartile, wBox, (yMedian - yLowerQuartile), color); if (colorFilled != color) { m_2D.DrawFilledBox(x1, y + yMedian, wBox, (yUpperQuartile - yMedian), colorFilled); } m_2D.DrawBox(x1, y + yMedian, wBox, (yUpperQuartile - yMedian), color); // Median line //xMargin = (1 * w / 8); //x1 = x + xMargin; //x2 = x + (w - xMargin); m_2D.DrawLine(x1, y + yMedian, x2, y + yMedian, color); m_2D.DrawLine(x1, y + yMedian + 1, x2, y + yMedian + 1, color); // Line caps xMargin = (3 * w / 8); x1 = x + xMargin; x2 = x + (w - xMargin); if (startCap) { m_2D.DrawLine(x1, y + yMin, x2, y + yMin, color); } if (endCap) { m_2D.DrawLine(x1, y + yMax, x2, y + yMax, color); } }
public void Draw(Rect rect, Color barColor, int barCount, float timeRange, Color selectedBackground, Color selectedBorder, Color selectedText, bool includeOthers, bool includeUnaccounted) { Settings newSettings = new Settings(m_RequestedRangeSettings, barCount, timeRange, includeOthers, includeUnaccounted); if (m_CurrentSettings != newSettings) { Profiler.BeginSample("CalculateTopMarkers"); m_CurrentSettings = newSettings; m_MarkerSummary = CalculateTopMarkers(); Profiler.EndSample(); } if (m_CurrentSettings.rangeSettings == null) { return; } if (m_CurrentSettings.rangeSettings.dataView == null) { return; } if (m_CurrentSettings.rangeSettings.dataView.analysis == null) { return; } if (m_MarkerSummary == null || m_MarkerSummary.entry == null) { return; } ProfileAnalysis analysis = m_CurrentSettings.rangeSettings.dataView.analysis; int depthFilter = m_CurrentSettings.rangeSettings.depthFilter; List <string> nameFilters = m_CurrentSettings.rangeSettings.nameFilters; List <string> nameExcludes = m_CurrentSettings.rangeSettings.nameExcludes; FrameSummary frameSummary = analysis.GetFrameSummary(); if (frameSummary == null) { return; } if (frameSummary.count <= 0) { return; } var markers = analysis.GetMarkers(); if (markers == null) { return; } Profiler.BeginSample("DrawHeader"); int rangeLabelWidth = 60; // After the marker graph we want an indication of the time range if (frameSummary.count > 0) { Rect rangeLabelRect = new Rect(rect.x + rect.width - rangeLabelWidth, rect.y, rangeLabelWidth, rect.height); GUIContent timeRangeText = ConstructTimeRangeText(); GUI.Label(rangeLabelRect, timeRangeText); } // Reduce the size of the marker graph for the button/label we just added rect.width -= rangeLabelWidth; // Show marker graph float y = 0; float width = rect.width; float height = rect.height; var selectedPairingMarkerName = m_ProfileAnalyzerWindow.GetSelectedMarkerName(); if (timeRange <= 0.0f) { timeRange = frameSummary.msMedian; } Profiler.EndSample(); if (m_2D.DrawStart(rect, Draw2D.Origin.BottomLeft)) { Profiler.BeginSample("DrawBars"); m_2D.DrawFilledBox(0, y, width, height, m_BackgroundColor); foreach (MarkerSummaryEntry entry in m_MarkerSummary.entry) { String name = entry.name; float x = entry.x * width; float w = entry.w * width; if (entry.summaryType == SummaryType.Marker) { if (name == selectedPairingMarkerName) { DrawBar(x, y, w, height, selectedBackground, selectedBorder, true); } else { DrawBar(x, y, w, height, barColor, selectedBorder, false); } } else { // Others / Unaccounted Color color = entry.summaryType == SummaryType.Unaccounted ? new Color(barColor.r * 0.5f, barColor.g * 0.5f, barColor.b * 0.5f, barColor.a) : barColor; DrawBar(x, y, w, height, color, selectedBorder, false); } } Profiler.EndSample(); m_2D.DrawEnd(); } GUIStyle centreAlignStyle = new GUIStyle(GUI.skin.label); centreAlignStyle.alignment = TextAnchor.MiddleCenter; centreAlignStyle.normal.textColor = m_TextColor; GUIStyle leftAlignStyle = new GUIStyle(GUI.skin.label); leftAlignStyle.alignment = TextAnchor.MiddleLeft; leftAlignStyle.normal.textColor = m_TextColor; Color contentColor = GUI.contentColor; int frameSummaryMedianFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(frameSummary.medianFrameIndex, m_CurrentSettings.rangeSettings.dataView); Profiler.BeginSample("DrawText"); foreach (MarkerSummaryEntry entry in m_MarkerSummary.entry) { String name = entry.name; float x = entry.x * width; float w = entry.w * width; float msAtMedian = entry.msAtMedian; if (entry.summaryType == SummaryType.Marker) { Rect labelRect = new Rect(rect.x + x, rect.y, w, rect.height); GUIStyle style = centreAlignStyle; String displayName = ""; if (w >= 20) { displayName = name; Vector2 size = centreAlignStyle.CalcSize(new GUIContent(name)); if (size.x > w) { var words = name.Split('.'); displayName = words[words.Length - 1]; style = leftAlignStyle; } } float percentAtMedian = msAtMedian * 100 / timeRange; string tooltip = string.Format( Content.tooltip, name, percentAtMedian, ToDisplayUnits(msAtMedian, true, 0), frameSummaryMedianFrameIndex, ToDisplayUnits(entry.msMedian, true, 0), entry.medianFrameIndex); if (name == selectedPairingMarkerName) { style.normal.textColor = selectedText; } else { style.normal.textColor = m_TextColor; } GUI.Label(labelRect, new GUIContent(displayName, tooltip), style); Event current = Event.current; if (labelRect.Contains(current.mousePosition)) { if (current.type == EventType.ContextClick) { GenericMenu menu; if (!m_ProfileAnalyzerWindow.IsAnalysisRunning()) { menu = GenerateActiveContextMenu(name, current); } else { menu = GenerateDisabledContextMenu(name); } menu.ShowAsContext(); current.Use(); } if (current.type == EventType.MouseDown) { m_ProfileAnalyzerWindow.SelectMarker(name); m_ProfileAnalyzerWindow.RequestRepaint(); } } } else { DrawBarText(rect, x, w, msAtMedian, name, timeRange, leftAlignStyle, frameSummaryMedianFrameIndex); } } Profiler.EndSample(); }
public void Draw(Rect rect, Color barColor, int barCount, float timeRange, Color selectedBackground, Color selectedBorder, Color selectedText, bool includeOthers, bool includeUnaccounted) { if (m_Analysis == null) { return; } Settings currentSettings = new Settings(m_Analysis, barCount, timeRange, m_DepthFilter, includeOthers, includeUnaccounted, m_NameFilters, m_NameExcludes); if (currentSettings != m_LastSettings) { Profiler.BeginSample("CalculateTopMarkers"); m_MarkerSummary = CalculateTopMarkers(m_Analysis, barCount, timeRange, m_DepthFilter, includeOthers, includeUnaccounted, m_NameFilters, m_NameExcludes); m_LastSettings = currentSettings; Profiler.EndSample(); } if (m_MarkerSummary == null || m_MarkerSummary.entry == null) { return; } FrameSummary frameSummary = m_Analysis.GetFrameSummary(); if (frameSummary == null) { return; } if (frameSummary.count <= 0) { return; } var markers = m_Analysis.GetMarkers(); if (markers == null) { return; } Profiler.BeginSample("DrawHeader"); // After the marker graph we want an indication of the time range int rangeLabelWidth = 60; Rect rangeLabelRect = new Rect(rect.x + rect.width - rangeLabelWidth, rect.y, rangeLabelWidth, rect.height); string timeRangeString = ToDisplayUnits(timeRange, true); string frameTimeString = ToDisplayUnits(frameSummary.msMedian, true, 0); string timeRangeTooltip = string.Format("{0} median frame time", frameTimeString); if (frameSummary.count > 0) { GUI.Label(rangeLabelRect, new GUIContent(timeRangeString, timeRangeTooltip)); } // Reduce the size of the marker graph for the button/label we just added rect.width -= rangeLabelWidth; // Show marker graph float y = 0; float width = rect.width; float height = rect.height; var selectedPairingMarkerName = m_ProfileAnalyzerWindow.GetSelectedMarkerName(); if (timeRange <= 0.0f) { timeRange = frameSummary.msMedian; } Profiler.EndSample(); if (m_2D.DrawStart(rect, Draw2D.Origin.BottomLeft)) { Profiler.BeginSample("DrawBars"); m_2D.DrawFilledBox(0, y, width, height, m_BackgroundColor); foreach (MarkerSummaryEntry entry in m_MarkerSummary.entry) { String name = entry.name; float x = entry.x * width; float w = entry.w * width; if (entry.summaryType == SummaryType.Marker) { if (name == selectedPairingMarkerName) { DrawBar(x, y, w, height, selectedBackground, selectedBorder, true); } else { DrawBar(x, y, w, height, barColor, selectedBorder, false); } } else { // Others / Unaccounted Color color = entry.summaryType == SummaryType.Unaccounted ? new Color(barColor.r * 0.5f, barColor.g * 0.5f, barColor.b * 0.5f, barColor.a) : barColor; DrawBar(x, y, w, height, color, selectedBorder, false); } } Profiler.EndSample(); m_2D.DrawEnd(); } GUIStyle centreAlignStyle = new GUIStyle(GUI.skin.label); centreAlignStyle.alignment = TextAnchor.MiddleCenter; centreAlignStyle.normal.textColor = m_TextColor; GUIStyle leftAlignStyle = new GUIStyle(GUI.skin.label); leftAlignStyle.alignment = TextAnchor.MiddleLeft; leftAlignStyle.normal.textColor = m_TextColor; Color contentColor = GUI.contentColor; Profiler.BeginSample("DrawText"); foreach (MarkerSummaryEntry entry in m_MarkerSummary.entry) { String name = entry.name; float x = entry.x * width; float w = entry.w * width; float msAtMedian = entry.msAtMedian; if (entry.summaryType == SummaryType.Marker) { Rect labelRect = new Rect(rect.x + x, rect.y, w, rect.height); GUIStyle style = centreAlignStyle; String displayName = ""; if (w >= 20) { displayName = name; Vector2 size = centreAlignStyle.CalcSize(new GUIContent(name)); if (size.x > w) { var words = name.Split('.'); displayName = words[words.Length - 1]; style = leftAlignStyle; } } float percentAtMedian = msAtMedian * 100 / timeRange; string tooltip = string.Format("{0}\n{1:f2}% ({2} on median frame {3})\n\nMedian marker time (in currently selected frames)\n{4} on frame {5}", name, percentAtMedian, ToDisplayUnits(msAtMedian, true, 0), frameSummary.medianFrameIndex, ToDisplayUnits(entry.msMedian, true, 0), entry.medianFrameIndex); if (name == selectedPairingMarkerName) { style.normal.textColor = selectedText; } else { style.normal.textColor = m_TextColor; } GUI.Label(labelRect, new GUIContent(displayName, tooltip), style); Event current = Event.current; if (labelRect.Contains(current.mousePosition)) { if (current.type == EventType.ContextClick) { GenericMenu menu = new GenericMenu(); menu.AddItem(Styles.menuItemSelectFramesInAll, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(name, false)); menu.AddItem(Styles.menuItemSelectFramesInCurrent, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(name, true)); if (m_ProfileAnalyzerWindow.AllSelected()) { menu.AddDisabledItem(Styles.menuItemSelectFramesAll); } else { menu.AddItem(Styles.menuItemSelectFramesAll, false, () => m_ProfileAnalyzerWindow.SelectAllFrames()); } /* * if (m_ProfileAnalyzerWindow.AllSelected() || m_ProfileAnalyzerWindow.HasSelection()) * menu.AddItem(Styles.menuItemClearSelection, false, () => m_ProfileAnalyzerWindow.ClearSelection()); * else * menu.AddDisabledItem(Styles.menuItemClearSelection); */ menu.AddSeparator(""); if (!m_NameFilters.Contains(name)) { menu.AddItem(Styles.menuItemAddToIncludeFilter, false, () => m_ProfileAnalyzerWindow.AddToIncludeFilter(name)); } else { menu.AddItem(Styles.menuItemRemoveFromIncludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromIncludeFilter(name)); } if (!m_NameExcludes.Contains(name)) { menu.AddItem(Styles.menuItemAddToExcludeFilter, false, () => m_ProfileAnalyzerWindow.AddToExcludeFilter(name)); } else { menu.AddItem(Styles.menuItemRemoveFromExcludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromExcludeFilter(name)); } menu.AddSeparator(""); menu.AddItem(Styles.menuItemSetAsParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(name)); menu.AddItem(Styles.menuItemClearParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter("")); menu.AddSeparator(""); menu.AddItem(Styles.menuItemCopyToClipboard, false, () => CopyToClipboard(current, name)); menu.ShowAsContext(); current.Use(); } if (current.type == EventType.MouseDown) { m_ProfileAnalyzerWindow.SelectMarker(name); m_ProfileAnalyzerWindow.RequestRepaint(); } } } else { DrawBarText(rect, x, w, msAtMedian, name, timeRange, leftAlignStyle, frameSummary.medianFrameIndex); } } Profiler.EndSample(); }