void ShowContextMenu(Rect cellRect, string markerName, GUIContent content) { Event current = Event.current; if (cellRect.Contains(current.mousePosition) && current.type == EventType.ContextClick) { GenericMenu menu = new GenericMenu(); menu.AddItem(Styles.menuItemSelectFramesInAll, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(markerName, false)); menu.AddItem(Styles.menuItemSelectFramesInCurrent, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(markerName, 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_ProfileAnalyzerWindow.GetNameFilters().Contains(markerName)) { menu.AddItem(Styles.menuItemAddToIncludeFilter, false, () => m_ProfileAnalyzerWindow.AddToIncludeFilter(markerName)); } else { menu.AddItem(Styles.menuItemRemoveFromIncludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromIncludeFilter(markerName)); } if (!m_ProfileAnalyzerWindow.GetNameExcludes().Contains(markerName)) { menu.AddItem(Styles.menuItemAddToExcludeFilter, false, () => m_ProfileAnalyzerWindow.AddToExcludeFilter(markerName)); } else { menu.AddItem(Styles.menuItemRemoveFromExcludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromExcludeFilter(markerName)); } menu.AddSeparator(""); menu.AddItem(Styles.menuItemSetAsParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(markerName)); menu.AddItem(Styles.menuItemClearParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter("")); menu.AddSeparator(""); if (content != null && !string.IsNullOrEmpty(content.text)) { menu.AddItem(Styles.menuItemCopyToClipboard, false, () => CopyToClipboard(current, content.text)); } menu.ShowAsContext(); current.Use(); } }
GenericMenu GenerateActiveContextMenu(string markerName, Event evt, GUIContent content) { GenericMenu menu = new GenericMenu(); menu.AddItem(Styles.menuItemSelectFramesInAll, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(markerName, false)); menu.AddItem(Styles.menuItemSelectFramesInCurrent, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(markerName, true)); if (m_ProfileAnalyzerWindow.AllSelected()) { menu.AddDisabledItem(Styles.menuItemSelectFramesAll); } else { menu.AddItem(Styles.menuItemSelectFramesAll, false, () => m_ProfileAnalyzerWindow.SelectAllFrames()); } menu.AddSeparator(""); if (!m_ProfileAnalyzerWindow.GetNameFilters().Contains(markerName, StringComparer.OrdinalIgnoreCase)) { menu.AddItem(Styles.menuItemAddToIncludeFilter, false, () => m_ProfileAnalyzerWindow.AddToIncludeFilter(markerName)); } else { menu.AddItem(Styles.menuItemRemoveFromIncludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromIncludeFilter(markerName)); } if (!m_ProfileAnalyzerWindow.GetNameExcludes().Contains(markerName, StringComparer.OrdinalIgnoreCase)) { menu.AddItem(Styles.menuItemAddToExcludeFilter, false, () => m_ProfileAnalyzerWindow.AddToExcludeFilter(markerName)); } else { menu.AddItem(Styles.menuItemRemoveFromExcludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromExcludeFilter(markerName)); } menu.AddSeparator(""); menu.AddItem(Styles.menuItemSetAsParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(markerName)); menu.AddItem(Styles.menuItemClearParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter("")); menu.AddSeparator(""); if (content != null && !string.IsNullOrEmpty(content.text)) { menu.AddItem(Styles.menuItemCopyToClipboard, false, () => CopyToClipboard(evt, content.text)); } return(menu); }
GenericMenu GenerateActiveContextMenu(string markerName, Event evt) { GenericMenu menu = new GenericMenu(); menu.AddItem(Styles.menuItemSelectFramesInAll, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(markerName, false)); menu.AddItem(Styles.menuItemSelectFramesInCurrent, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(markerName, true)); if (m_ProfileAnalyzerWindow.AllSelected()) { menu.AddDisabledItem(Styles.menuItemSelectFramesAll); } else { menu.AddItem(Styles.menuItemSelectFramesAll, false, () => m_ProfileAnalyzerWindow.SelectAllFrames()); } menu.AddSeparator(""); if (!m_CurrentSettings.rangeSettings.nameFilters.Contains(markerName)) { menu.AddItem(Styles.menuItemAddToIncludeFilter, false, () => m_ProfileAnalyzerWindow.AddToIncludeFilter(markerName)); } else { menu.AddItem(Styles.menuItemRemoveFromIncludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromIncludeFilter(markerName)); } if (!m_CurrentSettings.rangeSettings.nameExcludes.Contains(markerName)) { menu.AddItem(Styles.menuItemAddToExcludeFilter, false, () => m_ProfileAnalyzerWindow.AddToExcludeFilter(markerName)); } else { menu.AddItem(Styles.menuItemRemoveFromExcludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromExcludeFilter(markerName)); } menu.AddSeparator(""); menu.AddItem(Styles.menuItemSetAsParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(markerName)); menu.AddItem(Styles.menuItemClearParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter("")); menu.AddSeparator(""); menu.AddItem(Styles.menuItemCopyToClipboard, false, () => CopyToClipboard(evt, markerName)); return(menu); }
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(); }