Beispiel #1
0
        public static void GenerateNodeDependencies(Dictionary <string, AssetNode> nodeDict)
        {
            int count = nodeDict.Count;
            int index = 0;

            foreach (var kvp in nodeDict)
            {
                EditorUtility.DisplayProgressBar("生成每个节点依赖的节点", index + "/" + count, 1f * (index++) / count);

                AssetNode node = kvp.Value;

                string[] dependencies = AssetDatabase.GetDependencies(node.path);

                for (int i = 0; i < dependencies.Length; i++)
                {
                    string path = dependencies[i];
                    if (path == node.path)
                    {
                        continue;
                    }

                    AssetNode depNode;
                    if (nodeDict.TryGetValue(path, out depNode))
                    {
                        node.AddDependencie(depNode);
                    }
                }
            }

            EditorUtility.ClearProgressBar();
            if (isLog)
            {
                AssetNode.PrintNodeDict(nodeDict, "生成每个节点依赖的节点 nodeDict");
            }
        }
Beispiel #2
0
 /// <summary>
 /// 添加资源
 /// </summary>
 /// <param name="node"></param>
 public void AddAsset(AssetNode node)
 {
     if (!assets.Contains(node))
     {
         assets.Add(node);
         node.parents.Add(this);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 添加依赖
 /// </summary>
 /// <param name="node"></param>
 public void AddDependencie(AssetNode node)
 {
     if (!childs.Contains(node))
     {
         childs.Add(node);
         node.parents.Add(this);
     }
 }
Beispiel #4
0
 public void ForcedSetRoot()
 {
     for (int i = parents.Count - 1; i >= 0; i--)
     {
         AssetNode parent = parents[i];
         parent.RemoveDependencie(this);
     }
 }
Beispiel #5
0
 /// <summary>
 /// 移除依赖
 /// </summary>
 /// <param name="node"></param>
 public void RemoveDependencie(AssetNode node)
 {
     if (childs.Contains(node))
     {
         childs.Remove(node);
         if (node.parents.Contains(this))
         {
             node.parents.Remove(this);
         }
     }
 }
Beispiel #6
0
        public static void PrintNodeDict(Dictionary <string, AssetNode> dict, string destr = "")
        {
            // 打印信息树
            string str = "[" + destr + "]\n";

            foreach (var kvp in dict)
            {
                AssetNode node = kvp.Value;
                str += node + "\n";
            }
            Debuger.Log(str);
        }
Beispiel #7
0
 public void MergeAssetToParent(AssetNode pnode)
 {
     foreach (AssetNode node in assets)
     {
         pnode.assets.Add(node);
         node.parents.Remove(this);
         if (!node.parents.Contains(pnode))
         {
             node.parents.Add(pnode);
         }
     }
 }
Beispiel #8
0
        public static void PrintNodeTree(List <AssetNode> roots, string destr = "")
        {
            // 打印信息树
            string str = "[" + destr + "]\n";

            for (int i = 0; i < roots.Count; i++)
            {
                AssetNode node = roots[i];
                str += node.GetTreeInfo(0, "-- ");
                str += "========================\n\n";
            }
            Debuger.Log(str);
        }
Beispiel #9
0
        public static void FilterDotNeedNode(Dictionary <string, AssetNode> needDict, List <AssetNode> needRoots)
        {
            int count = needRoots.Count;

            for (int i = 0; i < needRoots.Count; i++)
            {
                EditorUtility.DisplayProgressBar("过滤不需要打包的节点", i + "/" + count, 1f * i / count);
                needRoots[i].FilterDotNeedNode(needDict);
            }

            if (isLog)
            {
                AssetNode.PrintNodeTree(needRoots, "过滤不需要打包的节点");
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #10
0
        public static void RemoveParentShare(List <AssetNode> roots)
        {
            int count = roots.Count;
            int index = 0;

            foreach (AssetNode node in roots)
            {
                EditorUtility.DisplayProgressBar("移除父节点的依赖和自己依赖相同的节点", index + "/" + count, 1f * (index++) / count);
                node.RemoveParentShare();
            }

            if (isLog)
            {
                AssetNode.PrintNodeTree(roots, "移除父节点的依赖和自己依赖相同的节点");
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #11
0
        public static void MergeParentCountOnce(List <AssetNode> roots)
        {
            int count = roots.Count;
            int index = 0;

            foreach (AssetNode node in roots)
            {
                EditorUtility.DisplayProgressBar("入度为1的节点自动打包到上一级节点", index + "/" + count, 1f * (index++) / count);
                node.MergeParentCountOnce();
            }

            if (isLog)
            {
                AssetNode.PrintNodeTree(roots, "入度为1的节点自动打包到上一级节点");
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #12
0
 public void GetNeedParentNodeList(Dictionary <string, AssetNode> needDict, Dictionary <string, AssetNode> needParentDict)
 {
     for (int i = parents.Count - 1; i >= 0; i--)
     {
         AssetNode parent = parents[i];
         if (needDict.ContainsKey(parent.path))
         {
             if (!needParentDict.ContainsKey(parent.path))
             {
                 needParentDict.Add(parent.path, parent);
             }
         }
         else
         {
             parent.GetNeedParentNodeList(needDict, needParentDict);
         }
     }
 }
Beispiel #13
0
        public void MergeParentCountOnce()
        {
            for (int i = childs.Count - 1; i >= 0; i--)
            {
                AssetNode cnode = childs[i];
                cnode.MergeParentCountOnce();

                if (cnode.ParentCount == 1 && cnode.CanMergeParent())
                {
                    // 子节点 变为 包含资源
                    assets.Add(cnode);
                    childs.Remove(cnode);

                    // 包含的资源 合并到 父亲节点
                    cnode.MergeAssetToParent(this);
                }
            }
        }
Beispiel #14
0
        public static Dictionary <string, AssetNode> GenerateAssetBundleNodes(List <AssetNode> roots)
        {
            Dictionary <string, AssetNode> nodeDict = new Dictionary <string, AssetNode>();
            int count = roots.Count;

            for (int i = 0; i < roots.Count; i++)
            {
                EditorUtility.DisplayProgressBar("生成需要设置AssetBundleName的节点", i + "/" + count, 1f * i / count);
                roots[i].GenerateAssetBundleNodes(nodeDict);
            }

            if (isLog)
            {
                AssetNode.PrintNodeDict(nodeDict, "生成需要设置AssetBundleName的节点");
            }
            EditorUtility.ClearProgressBar();
            return(nodeDict);
        }
Beispiel #15
0
        public static void ForcedSetRoots(Dictionary <string, AssetNode> nodeDict, List <string> forceRootList)
        {
            int count = forceRootList.Count;
            int index = 0;

            foreach (string path in forceRootList)
            {
                EditorUtility.DisplayProgressBar("强制设置某些节点为Root节点,删掉被依赖", index + "/" + count, 1f * (index++) / count);
                if (nodeDict.ContainsKey(path))
                {
                    AssetNode node = nodeDict[path];
                    node.ForcedSetRoot();
                }
            }
            if (isLog)
            {
                AssetNode.PrintNodeDict(nodeDict, "强制设置某些节点为Root节点,删掉被依赖");
            }

            EditorUtility.ClearProgressBar();
        }
Beispiel #16
0
        public static List <AssetNode> FindRoots(Dictionary <string, AssetNode> nodeDict)
        {
            int count = nodeDict.Count;
            int index = 0;
            List <AssetNode> roots = new List <AssetNode>();

            foreach (KeyValuePair <string, AssetNode> kvp in nodeDict)
            {
                EditorUtility.DisplayProgressBar("寻找入度为0的节点", index + "/" + count, 1f * (index++) / count);
                AssetNode node = kvp.Value;
                if (node.IsRoot)
                {
                    roots.Add(node);
                }
            }
            if (isLog)
            {
                AssetNode.PrintNodeTree(roots, "寻找入度为0的节点");
            }
            EditorUtility.ClearProgressBar();
            return(roots);
        }
Beispiel #17
0
        public void FilterDotNeedNode(Dictionary <string, AssetNode> needDict)
        {
            for (int i = childs.Count - 1; i >= 0; i--)
            {
                AssetNode child = childs[i];
                child.FilterDotNeedNode(needDict);
            }

            if (!needDict.ContainsKey(path))
            {
                for (int i = parents.Count - 1; i >= 0; i--)
                {
                    AssetNode parent = parents[i];
                    parent.RemoveDependencie(this);
                }
            }
            else
            {
                Dictionary <string, AssetNode> needParentDict = new Dictionary <string, AssetNode>();

                GetNeedParentNodeList(needDict, needParentDict);

                foreach (var kvp in needParentDict)
                {
                    kvp.Value.AddDependencie(this);
                }

                for (int i = parents.Count - 1; i >= 0; i--)
                {
                    AssetNode parent = parents[i];
                    if (!needParentDict.ContainsKey(parent.path))
                    {
                        parent.RemoveDependencie(this);
                    }
                }
            }
        }
Beispiel #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resList">需要打包的列表</param>
        /// <param name="filterDirList">过滤的目录</param>
        /// <param name="filterExts">过滤的扩展名</param>
        /// <param name="imageExts"></param>
        /// <param name="isSpriteTag"></param>
        /// <param name="assetbundleExt"></param>
        /// <returns></returns>
        public static Dictionary <string, AssetNode> GenerateAllNode(List <string> resList, List <string> filterDirList, List <string> filterExts, List <string> imageExts, bool isSpriteTag = false, string assetbundleExt = ".assetbundle")
        {
            Dictionary <string, AssetNode> nodeDict             = new Dictionary <string, AssetNode>();
            Dictionary <string, AssetNode> spriteTagPackageDict = new Dictionary <string, AssetNode>();
            List <AssetNode> spriteTagPackageList = new List <AssetNode>();

            string[] dependencies = AssetDatabase.GetDependencies(resList.ToArray());
            int      count        = dependencies.Length;

            for (int i = 0; i < count; i++)
            {
                EditorUtility.DisplayProgressBar("生成所有节点", i + "/" + count, 1f * i / count);
                string path        = dependencies[i];
                bool   isFilterDir = false;
                if (filterDirList.Count > 0)
                {
                    foreach (string filterDir in filterDirList)
                    {
                        if (path.IndexOf(filterDir, StringComparison.Ordinal) != -1)
                        {
                            isFilterDir = true;
                            break;
                        }
                    }
                }

                if (isFilterDir)
                {
                    continue;
                }
                string ext = Path.GetExtension(path).ToLower();
                if (filterExts.IndexOf(ext) != -1)
                {
                    continue;
                }
                AssetImporter assetImporter = AssetImporter.GetAtPath(path);
                if (!string.IsNullOrEmpty(assetImporter.assetBundleName))
                {
                    assetImporter.assetBundleName = string.Empty;
                }
                if (isSpriteTag && imageExts.IndexOf(ext) != -1)
                {
                    TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
                    if (importer.textureType == TextureImporterType.Sprite && !string.IsNullOrEmpty(importer.spritePackingTag))
                    {
                        importer.assetBundleName = importer.spritePackingTag + assetbundleExt;
                        AssetNode spriteTagPackageNode;

                        if (!spriteTagPackageDict.TryGetValue(importer.spritePackingTag, out spriteTagPackageNode))
                        {
                            spriteTagPackageNode      = new AssetNode();
                            spriteTagPackageNode.path = importer.spritePackingTag;
                            spriteTagPackageDict.Add(spriteTagPackageNode.path, spriteTagPackageNode);
                            spriteTagPackageList.Add(spriteTagPackageNode);
                        }

                        AssetNode spriteTagNode = new AssetNode();
                        spriteTagNode.path = path;
                        spriteTagPackageNode.AddAsset(spriteTagNode);
                        continue;
                    }
                }

                AssetNode node = new AssetNode();
                node.path = path;
                nodeDict.Add(node.path, node);
            }

            if (isLog)
            {
                AssetNode.PrintNodeDict(nodeDict, "nodeDict");
            }
            if (isLog)
            {
                AssetNode.PrintNodeTree(spriteTagPackageList, "图集");
            }
            EditorUtility.ClearProgressBar();
            return(nodeDict);
        }