示例#1
0
        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();
                    }
                }
            }
        }
示例#2
0
        public void OnGUI(Contents contents)
        {
            Event ev = Event.current;

            if (ev.type == EventType.KeyDown)
            {
                switch (ev.keyCode)
                {
                case KeyCode.F:
                {
                    FilterPath();
                    ev.Use();
                    break;
                }

                case KeyCode.L:
                {
                    if (ev.control != false)
                    {
                        searchField.SetFocus();
                        ev.Use();
                    }
                    break;
                }
                }
            }
            using (new EditorGUILayout.VerticalScope())
            {
                using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
                {
                    /* リスト表示廃止に伴い無効化 */
                        #if false
                    int mouseButton;

                    mouseButton = GUIExpansion.Toggle(viewType == View.Type.kTree,
                                                      new GUIContent(EditorGUIUtility.Load(treeTexture) as Texture2D),
                                                      EditorStyles.toolbarButton, GUILayout.ExpandWidth(false));
                    switch (mouseButton)
                    {
                    case 0:
                    {
                        if (viewType != View.Type.kTree)
                        {
                            viewType = View.Type.kTree;
                            Apply();
                        }
                        break;
                    }

                    case 1:
                    {
                        if (viewType == View.Type.kTree)
                        {
                            var contextMenu = new GenericMenu();

                            contextMenu.AddItem(new GUIContent("ExpandAll"), false, () =>
                                {
                                    view.ExpandAll();
                                });
                            contextMenu.AddItem(new GUIContent("CollapseAll"), false, () =>
                                {
                                    view.CollapseAll();
                                });
                            contextMenu.ShowAsContext();
                        }
                        break;
                    }
                    }
                    mouseButton = GUIExpansion.Toggle(viewType == View.Type.kList,
                                                      new GUIContent(AssetDatabase.LoadMainAssetAtPath(listTexture) as Texture2D),
                                                      EditorStyles.toolbarButton, GUILayout.ExpandWidth(false));
                    switch (mouseButton)
                    {
                    case 0:
                    {
                        if (viewType != View.Type.kList)
                        {
                            viewType = View.Type.kList;
                            Apply();
                        }
                        break;
                    }

                    case 1:
                    {
                        if (viewType == View.Type.kList)
                        {
                        }
                        break;
                    }
                    }
                    GUILayout.Space(6);
                        #endif
                        #if false
                    if (viewType == View.Type.kList)
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.TextField("Asssets/", EditorStyles.toolbarTextField);
                        EditorGUI.EndDisabledGroup();
                    }
                        #endif
                        #if WITH_SEARCHSTRING
                    string newSearchString = searchField.OnToolbarGUI(searchString, GUILayout.ExpandWidth(true));
                    if (searchString != newSearchString)
                    {
                        searchString = newSearchString;
                        searchFilter.Change(searchString);
                        view.Reload();
                    }
                        #else
                    view.searchString = searchField.OnToolbarGUI(view.searchString, GUILayout.ExpandWidth(true));
                        #endif
                    GUILayout.Space(4);

                    var  content = EditorGUIUtility.TrIconContent(typeTexture, "Search by Type");
                    Rect rect    = GUILayoutUtility.GetRect(content, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false));

                    if (EditorGUI.DropdownButton(rect, content,
                                                 FocusType.Passive, EditorStyles.toolbarButton) != false)
                    {
                        PopupWindow.Show(rect, new PopupList(objectTypes));
                    }
                }
                using (var scope = new EditorGUILayout.VerticalScope(GUILayout.ExpandHeight(true)))
                {
                    OnContextMenuEvent(contents, Event.current);
                    view.OnGUI(scope.rect);
                }
            }
        }