Example #1
0
        private void AddGlobalMenuItem(GenericMenu menu)
        {
            menu.AddItem(new GUIContent("Export Checked Items"), false, () =>
            {
                string path = EditorUtility.SaveFilePanel("Export", moduleConfig.Json.OutputPath, null, "txt");
                if (!string.IsNullOrEmpty(path))
                {
                    int exportCount = 0;
                    using (var writer = new StreamWriter(path))
                    {
                        for (int i = 0; i < rootItem.children.Count; i++)
                        {
                            var item = rootItem.children[i];
                            if (((AssetTreeItem)item).Check == true)
                            {
                                writer.WriteLine(item.displayName);
                                exportCount++;
                            }
                        }
                    }
                    EditorUtility.DisplayDialog("导出成功", "已将" + exportCount + "项导出到文件" + path, "确定");
                }
            });

            menu.AddSeparator(null);
            menu.AddItem(new GUIContent("Delete Checked Files"), false, () =>
            {
                int checkedCount = 0;
                foreach (AssetTreeItem item in rootItem.children)
                {
                    if (item.Check == true)
                    {
                        checkedCount++;
                    }
                }
                if (EditorUtility.DisplayDialog("删除文件", "你确定要删除所有勾选✔的文件? (共" + checkedCount + "项)", "删除所有勾选的文件", "取消"))
                {
                    int deleteCount = 0;
                    AssetDatabase.StartAssetEditing();
                    for (int i = 0; i < rootItem.children.Count; i++)
                    {
                        var item = (AssetTreeItem)rootItem.children[i];
                        if (item.Check == true)
                        {
                            AssetDatabase.DeleteAsset(item.displayName);
                            deleteCount++;
                            if (EditorUtility.DisplayCancelableProgressBar("Delete Assets", item.displayName, (float)deleteCount / checkedCount))
                            {
                                EditorUtility.ClearProgressBar();
                                EditorUtility.DisplayDialog("删除被中止", "已删除" + deleteCount + "个文件", "确定");
                                Reload();
                                return;
                            }
                        }
                    }
                    AssetDatabase.StopAssetEditing();
                    EditorUtility.ClearProgressBar();
                    EditorUtility.DisplayDialog("删除成功", "已删除" + deleteCount + "个文件", "确定");
                    Reload();
                }
            });
            menu.AddSeparator(null);
            menu.AddItem(new GUIContent("Open Map File"), false, () =>
            {
                string path = EditorUtility.OpenFilePanel("Open", moduleConfig.Json.OutputPath, "json");
                if (string.IsNullOrEmpty(path) || !File.Exists(path))
                {
                    return;
                }
                moduleConfig.AllBundles             = JsonConvert.DeserializeObject <BundleRDDictionary>(File.ReadAllText(path));
                stateConfig.Json.CurrentMapFilePath = path;
                stateConfig.Save();
                Reload();
            });
        }