Пример #1
0
 void OnShowNameContextMenu(GenericMenu menu)
 {
     if (!string.IsNullOrEmpty(m_Object.name))
     {
         menu.AddItem(new GUIContent("Find in Project"), false, (GenericMenu.MenuFunction2) delegate(object userData)
         {
             var o = (RichNativeObject)userData;
             HeEditorUtility.SearchProjectBrowser(string.Format("t:{0} {1}", o.type.name, o.name));
         }, m_Object);
     }
 }
Пример #2
0
        static void Create()
        {
            if (!HeEditorUtility.IsVersionOrNewer(2019, 3))
            {
                if (EditorUtility.DisplayDialog(HeGlobals.k_Title, string.Format("{0} requires Unity 2019.3 or newer.", HeGlobals.k_Title), "Forum", "Close"))
                {
                    Application.OpenURL(HeGlobals.k_ForumUrl);
                }
                return;
            }

            EditorWindow.GetWindow <HeapExplorerWindow>();
        }
Пример #3
0
        void DrawToolbar()
        {
            using (new GUILayout.HorizontalScope(EditorStyles.toolbar, GUILayout.ExpandWidth(true)))
            {
                EditorGUI.BeginDisabledGroup(!m_GotoHistory.HasBack());
                if (GUILayout.Button(new GUIContent(HeEditorStyles.backwardImage, "Navigate Backward"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                {
                    var cmd = m_GotoHistory.Back();
                    if (cmd != null)
                    {
                        GotoInternal(cmd, true);
                    }
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(!m_GotoHistory.HasForward());
                if (GUILayout.Button(new GUIContent(HeEditorStyles.forwardImage, "Navigate Forward"), EditorStyles.toolbarButton, GUILayout.Width(24)))
                {
                    var cmd = m_GotoHistory.Forward();
                    if (cmd != null)
                    {
                        GotoInternal(cmd, false);
                    }
                }
                EditorGUI.EndDisabledGroup();


                if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(60)))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Open..."), false, LoadFromFile);

                    for (int n = 0; n < HeMruFiles.count; ++n)
                    {
                        var path = HeMruFiles.GetPath(n);

                        if (string.IsNullOrEmpty(path))
                        {
                            continue;
                        }

                        if (!System.IO.File.Exists(path))
                        {
                            continue;
                        }

                        menu.AddItem(new GUIContent(string.Format("Recent/{0}     {1}", (n + 1), path.Replace('/', '\\'))), false, delegate(System.Object obj)
                        {
                            var p = obj as string;
                            LoadFromFile(p);
                        }, path);
                    }
                    menu.AddSeparator("Recent/");
                    menu.AddItem(new GUIContent("Recent/Clear list"), false, delegate()
                    {
                        if (EditorUtility.DisplayDialog("Clear list...", "Do you want to clear the most recently used files list?", "Clear", "Cancel"))
                        {
                            HeMruFiles.RemoveAll();
                        }
                    });

                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Close Snapshot"), false, CloseFile);
                    menu.AddSeparator("");
                    if (m_Heap == null)
                    {
                        menu.AddDisabledItem(new GUIContent("Save as..."));
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("Save as..."), false, SaveToFile);
                    }
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("New Window"), false, delegate()
                    {
                        var wnd = EditorWindow.CreateInstance <HeapExplorerWindow>();
                        wnd.Show();
                    });

                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Settings/Use Multi-Threading"), useThreads, delegate()
                    {
                        useThreads = !useThreads;
                    });
                    menu.AddItem(new GUIContent("Settings/Debug View Menu"), debugViewMenu, delegate()
                    {
                        debugViewMenu = !debugViewMenu;
                    });
                    menu.AddItem(new GUIContent("Settings/Exclude NativeObject connections when capturing a snapshot (experimental)"), excludeNativeFromConnections, delegate()
                    {
                        excludeNativeFromConnections = !excludeNativeFromConnections;
                    });
                    menu.AddItem(new GUIContent("Settings/Ignore nested structs (workaround for bug Case 1104590)"), ignoreNestedStructs, delegate()
                    {
                        ignoreNestedStructs = !ignoreNestedStructs;
                    });
                    menu.AddItem(new GUIContent("Settings/Show unaligned memory sections (removes MonoMemPool sections)"), showInternalMemorySections, delegate()
                    {
                        showInternalMemorySections = !showInternalMemorySections;
                    });
                    menu.DropDown(m_FileToolbarButtonRect);
                }
                if (Event.current.type == EventType.Repaint)
                {
                    m_FileToolbarButtonRect = GUILayoutUtility.GetLastRect();
                }


                EditorGUI.BeginDisabledGroup(m_Heap == null || m_Heap.isBusy);
                if (GUILayout.Button("View", EditorStyles.toolbarDropDown, GUILayout.Width(60)))
                {
                    m_Views.Sort(delegate(HeapExplorerView x, HeapExplorerView y)
                    {
                        var value = x.viewMenuOrder.CompareTo(y.viewMenuOrder);
                        if (value == 0)
                        {
                            value = string.Compare(x.titleContent.text, y.titleContent.text);
                        }
                        return(value);
                    });

                    var prevOrder = -1;
                    var menu      = new GenericMenu();
                    foreach (var view in m_Views)
                    {
                        if (view.viewMenuOrder < 0)
                        {
                            continue;
                        }
                        if (prevOrder == -1)
                        {
                            prevOrder = view.viewMenuOrder;
                        }

                        var p0 = prevOrder / 100;
                        var p1 = view.viewMenuOrder / 100;
                        if (p1 - p0 >= 1)
                        {
                            var i = view.titleContent.text.LastIndexOf("/");
                            if (i == -1)
                            {
                                menu.AddSeparator("");
                            }
                            else
                            {
                                menu.AddSeparator(view.titleContent.text.Substring(0, i));
                            }
                        }
                        prevOrder = view.viewMenuOrder;

                        var c = new GUIContent(view.titleContent);
                        if (debugViewMenu)
                        {
                            c.text = string.Format("{2}   [viewMenuOrder={0}, type={1}]", view.viewMenuOrder, view.GetType().Name, c.text);
                        }

                        menu.AddItem(c, m_ActiveView == view, (GenericMenu.MenuFunction2) delegate(System.Object o)
                        {
                            if (o == m_ActiveView)
                            {
                                return;
                            }

                            var v  = o as HeapExplorerView;
                            var c0 = m_ActiveView.GetRestoreCommand(); c0.fromView = m_ActiveView;
                            var c1 = v.GetRestoreCommand(); c1.toView = v;
                            m_GotoHistory.Add(c0, c1);
                            ActivateView(v);
                        }, view);
                    }

                    menu.DropDown(m_ViewToolbarButtonRect);
                }
                if (Event.current.type == EventType.Repaint)
                {
                    m_ViewToolbarButtonRect = GUILayoutUtility.GetLastRect();
                }
                EditorGUI.EndDisabledGroup();


                var connectedProfiler = UnityEditorInternal.ProfilerDriver.GetConnectionIdentifier(UnityEditorInternal.ProfilerDriver.connectedProfiler);
                if (GUILayout.Button(new GUIContent("Capture", HeEditorStyles.magnifyingGlassImage), EditorStyles.toolbarDropDown, GUILayout.Width(80)))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(new GUIContent(string.Format("Capture and Save '{0}'...", connectedProfiler)), false, CaptureAndSaveHeap);
                    menu.AddItem(new GUIContent(string.Format("Capture and Analyze '{0}'", connectedProfiler)), false, CaptureAndAnalyzeHeap);
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent(string.Format("Open Profiler")), false, delegate() { HeEditorUtility.OpenProfiler(); });
                    menu.DropDown(m_CaptureToolbarButtonRect);
                }
                if (Event.current.type == EventType.Repaint)
                {
                    m_CaptureToolbarButtonRect = GUILayoutUtility.GetLastRect();
                }

                if (m_ActiveView != null)
                {
                    m_ActiveView.OnToolbarGUI();
                }
            }
        }