void OnContextMenuEvent(Contents contents, Event ev) { if (ev.type == EventType.MouseUp && ev.button == 1) { if (view.GetViewRect().Contains(ev.mousePosition) != false) { int selectedCount = view.GetSelectedCount(); if (selectedCount > 0) { var contextMenu = new GenericMenu(); if (selectedCount == 1) { contextMenu.AddItem(new GUIContent("Open"), false, () => { Element element = view.FirstSelectedElements((x => x.CanOpenAsset())); if (element.directory != false) { view.SetExpanded(element.id, !view.IsExpanded(element.id)); } else { AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(element.path)); } }); contextMenu.AddItem(new GUIContent("Show in Explorer"), false, () => { Element element = view.FirstSelectedElements((x => true)); EditorUtility.RevealInFinder(element.path); }); } if (selectedCount == 1 && view.ContainsSeelctedElements(true, x => x.directory) != false) { contextMenu.AddItem(new GUIContent("Filter Path"), false, () => { FilterPath(); }); } contextMenu.AddItem(new GUIContent("Copy Path"), false, () => { var elements = view.SelectSelectedElements(x => x.path); var builder = new System.Text.StringBuilder(); foreach (var element in elements) { builder.AppendLine(element); } EditorGUIUtility.systemCopyBuffer = builder.ToString(); }); contextMenu.AddItem(new GUIContent("Copy Guid"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); var builder = new System.Text.StringBuilder(); foreach (var element in elements) { builder.AppendLine(element); } EditorGUIUtility.systemCopyBuffer = builder.ToString(); }); contextMenu.AddItem(new GUIContent("Export Package/Select Only"), false, () => { var assetPaths = view.SelectSelectedElements(x => x.IsFile(), x => x.path).ToArray(); if (assetPaths.Length > 0) { string directory = System.IO.Path.GetFullPath("Assets/../"); string fileName = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); string savePath = EditorUtility.SaveFilePanel("Export Package", directory, fileName, "unitypackage"); if (string.IsNullOrEmpty(savePath) == false) { AssetDatabase.ExportPackage(assetPaths, savePath, ExportPackageOptions.Default | ExportPackageOptions.Interactive); } } }); contextMenu.AddItem(new GUIContent("Export Package/Include Dependencies"), false, () => { var assetPaths = view.SelectSelectedElements(x => x.IsFile(), x => x.path).ToArray(); if (assetPaths.Length > 0) { string directory = System.IO.Path.GetFullPath("Assets/../"); string fileName = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); string savePath = EditorUtility.SaveFilePanel("Export Package", directory, fileName, "unitypackage"); if (string.IsNullOrEmpty(savePath) == false) { AssetDatabase.ExportPackage(assetPaths, savePath, ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Interactive); } } }); if (selectedCount == 1) { contextMenu.AddItem(new GUIContent("Ping"), false, () => { Element element = view.FirstSelectedElements(x => x.CanPingObject()); element?.PingObject(true); }); contextMenu.AddItem(new GUIContent("Active"), false, () => { Element element = view.FirstSelectedElements(x => x.CanActiveObject()); element?.ActiveObject(true); }); } contextMenu.AddItem(new GUIContent("Search/Check Missing"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); contents?.SearchAssets(elements, SearchType.kCheckMissing); }); contextMenu.AddItem(new GUIContent("Search/Trace Precedents"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); contents?.SearchAssets(elements, SearchType.kTracePrecedents); }); contextMenu.AddItem(new GUIContent("Search/Trace Dependents"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); contents?.SearchAssets(elements, SearchType.kTraceDependents); }); contextMenu.AddItem(new GUIContent("Search/Trace Precedents new tab"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); contents?.OpenSearchAssets(elements, SearchType.kTracePrecedents); }); contextMenu.AddItem(new GUIContent("Search/Trace Dependents new tab"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); contents?.OpenSearchAssets(elements, SearchType.kTraceDependents); }); if (view.ContainsSeelctedElements(AssetType.kMaterial, x => x.type) != false) { contextMenu.AddItem(new GUIContent("Material Cleaner"), false, () => { var elements = view.SelectSelectedElements(x => x.guid); MaterialCleaner.Clean(elements); }); } contextMenu.ShowAsContext(); ev.Use(); } } } }