Exemplo n.º 1
0
        private void CellGUI(Rect rect, BundleTreeItem item, ColumnEnum column, ref RowGUIArgs args)
        {
            CenterRectUsingSingleLineHeight(ref rect);
            switch (column)
            {
            case ColumnEnum.Name:
                float space = 5 + foldoutWidth + depthIndentWidth * item.depth;
                GUI.DrawTexture(new Rect(rect.x + space, rect.y, rect.height, rect.height), item.icon, ScaleMode.ScaleToFit);
                GUI.Label(new Rect(rect.x + space + rect.height, rect.y, rect.width - space - rect.height, rect.height),
                          item.displayName, item.style);
                break;

            case ColumnEnum.Connection:
                foreach (var p in item.packageItems)
                {
                    float width = rect.height;
                    float x     = rect.x;
                    Rect  r     = new Rect(x + G.g.packageTree.Packages.IndexOf(p.package) * (rect.height + 4), rect.y, width, rect.height);
                    if (GUI.Button(r, GUIContent.none, p.complete ? p.package.colorBlockStyle : p.package.colorBlockStyle_hollow))
                    {
                        LocatePackage(p);
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        private void AddBundlesToPackage(PackageTreeItem packageItem, BundleTreeItem item)
        {
            var p = RecursiveAddParents(item, packageItem);

            if (item.isFolder && item.hasChildren)
            {
                RecursiveAddChildren(item, p, packageItem);
            }
        }
Exemplo n.º 3
0
 void RecursiveAddChildren(BundleTreeItem bundleItemParent, PackageTreeItem packageParent, PackageTreeItem packageItem)
 {
     foreach (BundleTreeItem item in bundleItemParent.children)
     {
         var p = FindOrCreatePackageItem(item, packageParent, packageItem);
         if (item.isFolder && item.hasChildren)
         {
             RecursiveAddChildren(item, p, packageItem);
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 递归添加父节点
 /// </summary>
 /// <param name="bundleItem">要添加的bundle</param>
 /// <param name="packageItem">在此package里添加</param>
 /// <returns></returns>
 PackageTreeItem RecursiveAddParents(BundleTreeItem bundleItem, PackageTreeItem packageItem)
 {
     if (bundleItem.parent.depth < 0)
     {
         return(FindOrCreatePackageItem(bundleItem, packageItem, packageItem));//在packageItem下找到或创建一个以bundleItem为内容的packageItem
     }
     else
     {
         var parent = RecursiveAddParents((BundleTreeItem)bundleItem.parent, packageItem);
         return(FindOrCreatePackageItem(bundleItem, parent, packageItem));
     }
 }
Exemplo n.º 5
0
        protected override void DoubleClickedItem(int id)
        {
            BundleTreeItem item = FindItem(id, rootItem) as BundleTreeItem;

            if (item.hasChildren)
            {
                SetExpanded(id, !IsExpanded(id));
            }
            else
            {
                Locate(item);
            }
        }
Exemplo n.º 6
0
        private TreeViewItem BuildBundleTreeFromFolder()
        {
            string assetBundlesFolderPath = G.Module.ModuleConfig.BundleWorkFolderPath;

            if (!Directory.Exists(assetBundlesFolderPath))
            {
                G.Module.DisplayDialog("AssetBundles目录不存在:" + assetBundlesFolderPath);
                BundleTreeItem root = new BundleTreeItem()
                {
                    id          = 0,
                    depth       = -1,
                    displayName = "Root",
                    isFolder    = false,
                };
                return(root);
            }

            string rootPath = G.Module.GetBundleFolderPath();

            BundleTreeItem rootFolderItem = new BundleTreeItem()
            {
                id           = 0,
                depth        = -1,
                displayName  = Path.GetFileName(rootPath),
                isFolder     = true,
                path         = rootPath,
                relativePath = "", //这里是相对路径的根
                icon         = folderIcon
            };

            if (Directory.Exists(rootFolderItem.path))
            {
                AddDirectories(rootFolderItem);
                AddFiles(rootFolderItem);
                EditorUtility.ClearProgressBar();
            }

            SetupDepthsFromParentsAndChildren(rootFolderItem);

            //检查
            if (checkFailedItems.Count > 0)
            {
                G.Module.DisplayDialog("有 " + checkFailedItems.Count +
                                       " 个manifest文件缺少对应的bundle文件!\n(这些项已标记为警告色:黄色)");
            }
            LoadBundleInfo(); //加载信息文件
            return(rootFolderItem);
        }
Exemplo n.º 7
0
        private void Locate(BundleTreeItem item)
        {
            List <int> ids = new List <int>();

            foreach (var packageItem in item.packageItems)
            {
                ids.Add(packageItem.id);
            }

            G.g.packageTree.SetSelection(ids);
            foreach (var id in ids)
            {
                G.g.packageTree.FrameItem(id);
            }
            G.g.packageTree.SetFocus();
        }
Exemplo n.º 8
0
        void AddFiles(BundleTreeItem folderItem)
        {
            string[] files = Directory.GetFiles(folderItem.path);
            foreach (string filePath in files)
            {
                G.Module.DisplayProgressBar(string.Format("PackageManager(检查:{1},载入总数:{0})",
                                                          loadFileProgressCount, G.Module.ModuleConfig.Json.CheckBundle), filePath,
                                            (float)loadFileProgressCount % 100000 / 100000);

                loadFileProgressCount++;

                //Texture2D cachedIcon = AssetDatabase.GetCachedIcon(filePath) as Texture2D; //TODO:如何找到类似函数
                if (filePath.EndsWith(".manifest", StringComparison.Ordinal))
                {
                    string bundlePath = filePath.Remove(filePath.Length - 9, 9);
                    string bundleName = Path.GetFileName(bundlePath);
                    var    fileItem   = new BundleTreeItem()
                    {
                        isFolder     = false,
                        verify       = true,
                        path         = filePath,                 //manifest文件路径
                        relativePath = bundlePath.Remove(0, G.Module.GetBundleFolderPathStrCount()).Replace('\\', '/'),
                        bundlePath   = bundlePath,               //去掉manifest后缀的完整路径
                        displayName  = bundleName,
                        icon         = bundleIcon,
                        id           = ++fileLastID,
                        size         = -1,
                        style        = labelBundleStyle
                    };
                    folderItem.AddChild(fileItem);
                    bundleDic.Add(fileItem.relativePath, fileItem);
                    //检查manifest对应文件是否存在
                    if (G.Module.ModuleConfig.Json.CheckBundle)
                    {
                        fileItem.verify = File.Exists(bundlePath);
                        if (fileItem.verify == false)
                        {
                            checkFailedItems.Add(fileItem);
                            fileItem.style = labelWarningStyle;
                        }
                    }
                    //----------------------------
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 从任意一个packageItem节点的第一层children中找到包含bundleItem内容的packageItem,若没有则创建一个
        /// </summary>
        /// <param name="bundleItem">要找的内容</param>
        /// <param name="parent">在该parent节点的第一层子节点中查找</param>
        /// <param name="packageItem">要添加到bundleItem中的包信息</param>
        /// <returns></returns>
        private PackageTreeItem FindOrCreatePackageItem(BundleTreeItem bundleItem, PackageTreeItem parent, PackageTreeItem packageItem)
        {
            PackageTreeItem child = null;

            if (parent.hasChildren)
            {
                foreach (PackageTreeItem c in parent.children)
                {
                    if (c.bundleItem == bundleItem)
                    {
                        child = c;
                        break;
                    }
                }
            }
            if (child == null)
            {
                child = new PackageTreeItem()
                {
                    bundleItem = bundleItem,
                    id         = bundleItem.isFolder ? --folderID : ++bundleID,
                    package    = packageItem,
                    complete   = bundleItem.hasChildren ? false : true
                };
                if (!child.bundleItem.packageItems.Exists(x => x.package == packageItem))
                {
                    child.bundleItem.packageItems.Add(child);
                }
                if (child.bundleItem.isFolder)
                {
                    folderCount++;
                }
                else
                {
                    bundleCount++;
                }

                parent.AddChild(child);

                RecursiveUpdateParentComplete(parent);
            }
            return(child);
        }
Exemplo n.º 10
0
 void AddDirectories(BundleTreeItem parent)
 {
     string[] directories = Directory.GetDirectories(parent.path);
     foreach (string path in directories)
     {
         var folderItem = new BundleTreeItem()
         {
             id           = --directoryLastID,
             displayName  = Path.GetFileName(path),
             isFolder     = true,
             path         = path,
             relativePath = path.Remove(0, G.Module.GetBundleFolderPathStrCount()).Replace('\\', '/'),
             icon         = folderIcon
         };
         parent.AddChild(folderItem);
         AddDirectories(folderItem);
         AddFiles(folderItem);
         folderDic.Add(folderItem.relativePath, folderItem);
     }
 }
Exemplo n.º 11
0
        private TreeViewItem BuildBundleTreeFromConfig()
        {
            if (string.IsNullOrEmpty(BundleConfigPath))
            {
                BundleTreeItem root = new BundleTreeItem()
                {
                    id          = 0,
                    depth       = -1,
                    displayName = "Root",
                    isFolder    = false,
                };
                return(root);
            }

            BundleTreeItem rootFolderItem = new BundleTreeItem()
            {
                id           = 0,
                depth        = -1,
                displayName  = "Root",
                isFolder     = true,
                relativePath = "", //这里是相对路径的根
                icon         = folderIcon
            };

            AssetBundleBuild[] bundles = JsonConvert.DeserializeObject <AssetBundleBuild[]>(File.ReadAllText(BundleConfigPath));
            foreach (var bundleItem in bundles)
            {
                BundleTreeItem currentFolderItem = rootFolderItem;
                BundleTreeItem folderItem;
                string[]       folders    = bundleItem.assetBundleName.Split('/');
                string         bundleName = folders[folders.Length - 1];
                for (int i = 0; i < folders.Length - 1; i++)
                {
                    string folderName = folders[i];
                    folderItem = null;
                    if (currentFolderItem.hasChildren)
                    {
                        folderItem = (BundleTreeItem)currentFolderItem.children.Find(x => x.displayName == folderName); //x.id <= 0 说明该项为文件夹
                    }
                    if (folderItem == null)
                    {
                        folderItem = new BundleTreeItem()
                        {
                            id           = --directoryLastID,
                            displayName  = folderName,
                            isFolder     = true,
                            relativePath = currentFolderItem.relativePath == "" ? folderName : currentFolderItem.relativePath + "/" + folderName,
                            icon         = folderIcon
                        };
                        currentFolderItem.AddChild(folderItem);
                        folderDic.Add(folderItem.relativePath, folderItem);
                    }
                    currentFolderItem = folderItem;
                }
                var fileItem = new BundleTreeItem()
                {
                    isFolder     = false,
                    verify       = true,
                    path         = null,
                    relativePath = bundleItem.assetBundleName,
                    bundlePath   = null,
                    displayName  = bundleName,
                    icon         = bundleIcon,
                    id           = ++fileLastID,
                    size         = -1,
                    style        = labelBundleStyle
                };
                currentFolderItem.AddChild(fileItem);
                bundleDic.Add(fileItem.relativePath, fileItem);
            }
            //加入虚拟的assetbundlemanifest
            var assetbundlemanifest = new BundleTreeItem()
            {
                isFolder     = false,
                verify       = true,
                path         = null,
                relativePath = "assetbundlemanifest",
                bundlePath   = null,
                displayName  = "assetbundlemanifest",
                icon         = bundleIcon,
                id           = ++fileLastID,
                size         = -1,
                style        = labelBundleStyle
            };

            rootFolderItem.AddChild(assetbundlemanifest);
            bundleDic.Add(assetbundlemanifest.relativePath, assetbundlemanifest);

            SetupDepthsFromParentsAndChildren(rootFolderItem);
            return(rootFolderItem);
        }