void OnGUI() { EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true)); GUIStyle style = new GUIStyle(GUI.skin.label); style.alignment = TextAnchor.MiddleLeft; GUILayout.Label("Select Thread : ", style); EditorGUILayout.BeginHorizontal(); bool lastEnabled = GUI.enabled; GUI.enabled = m_EnableResetButton; if (GUILayout.Button(Styles.reset, GUILayout.Width(50))) { // Reset the thread window contents only CreateTable(m_ProfileAnalyzerWindow, m_ThreadNames, m_ThreadUINames, m_OriginalThreadSelection); m_EnableApplyButton = true; m_EnableResetButton = false; } GUI.enabled = lastEnabled; if (GUILayout.Button(Styles.clear, GUILayout.Width(50))) { m_ThreadTable.ClearThreadSelection(); } if (GUILayout.Button(Styles.main, GUILayout.Width(100))) { m_ThreadTable.SelectMain(); } if (GUILayout.Button(Styles.common, GUILayout.Width(100))) { m_ThreadTable.SelectCommon(); } GUI.enabled = m_EnableApplyButton && !m_ProfileAnalyzerWindow.IsAnalysisRunning(); EditorGUILayout.Space(); if (GUILayout.Button(Styles.apply, GUILayout.Width(50))) { m_ProfileAnalyzerWindow.SetThreadSelection(m_ThreadTable.GetThreadSelection()); m_EnableApplyButton = false; m_EnableResetButton = true; } GUI.enabled = lastEnabled; EditorGUILayout.EndHorizontal(); if (m_ThreadTable != null) { Rect r = EditorGUILayout.GetControlRect(GUILayout.ExpandHeight(true)); m_ThreadTable.OnGUI(r); } EditorGUILayout.EndVertical(); }
void ShowContextMenu(Rect cellRect, string markerName, GUIContent content) { Event current = Event.current; if (cellRect.Contains(current.mousePosition) && current.type == EventType.ContextClick) { GenericMenu menu; if (!m_ProfileAnalyzerWindow.IsAnalysisRunning()) { menu = GenerateActiveContextMenu(markerName, current, content); } else { menu = GenerateDisabledContextMenu(markerName, content); } menu.ShowAsContext(); current.Use(); } }
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(); }