public void OnWindowCreated(WindowCreatedArgs args)
        {
            var defaultName           = PackageCreator.GenerateUniquePackageDisplayName("New Package");
            var createPackageDropdown = args.window.addMenu.AddDropdownItem();

            createPackageDropdown.text = "Create package...";
            createPackageDropdown.insertSeparatorBefore = true;
            createPackageDropdown.action = () =>
            {
                args.window.addMenu.ShowInputDropdown(new InputDropdownArgs
                {
                    title            = "Create package",
                    defaultValue     = defaultName,
                    submitButtonText = "Create",
                    onInputSubmitted = displayName =>
                    {
                        var packageName = PackageCreator.CreatePackage(k_PackagesFolder + displayName).Replace(k_PackagesFolder, "");
                        PackageObject.instance.packageName = packageName;
                        Client.Resolve();
                    }
                });
            };

            if (Unsupported.IsDeveloperMode())
            {
                m_ShowDevelopmentToolsDropdown = args.window.advancedMenu.AddDropdownItem();
                m_ShowDevelopmentToolsDropdown.insertSeparatorBefore = true;
                m_ShowDevelopmentToolsDropdown.text      = "Internal/Always show development tools";
                m_ShowDevelopmentToolsDropdown.action    = OnDevelopmentToolToggle;
                m_ShowDevelopmentToolsDropdown.isChecked = alwaysShowDevTools;
            }
        }
Пример #2
0
        public void OnAddMenuCreate(DropdownMenu menu)
        {
            menu.AppendSeparator("");

            menu.AppendAction("Create Package...", a =>
            {
                var defaultName              = PackageCreator.GenerateUniquePackageDisplayName("New Package");
                var createPackage            = new PackagesAction("Create", defaultName);
                createPackage.actionClicked += displayName =>
                {
                    createPackage.Hide();
                    var packagePath = PackageCreator.CreatePackage("Packages/" + displayName);
                    PackageManagerWindowAnalytics.SendEvent("createPackage");
                    AssetDatabase.Refresh();
#if UNITY_2020_1_OR_NEWER
                    EditorApplication.delayCall += () => Window.Open(displayName);
#else
                    EditorApplication.delayCall += () =>
                    {
                        var path = Path.Combine(packagePath, "package.json");
                        var o    = AssetDatabase.LoadMainAssetAtPath(path);
                        if (o != null)
                        {
                            Selection.activeObject = o;
                        }

                        PackageManagerWindow.SelectPackageAndFilter(displayName, PackageFilterTab.InDevelopment, true);
                    };
#endif
                };

                var parent = EditorWindow.GetWindow <PackageManagerWindow>()
                             .rootVisualElement.Q <PackageManagerToolbar>("topMenuToolbar")
                             .parent;
                parent.Add(createPackage);
                createPackage.Show();
            }, a => DropdownMenuAction.Status.Normal);
        }