Ejemplo n.º 1
0
        /// <summary>
        /// 加载依赖项
        /// </summary>
        /// <param name="abNode"></param>
        private void AnalyzeNode(ABNode abNode)
        {
            //提取依赖项
            string[] dependPaths = AssetDatabase.GetDependencies(abNode.Path);

            foreach (var tempDependPath in dependPaths)
            {
                string path = tempDependPath.Replace("\\", "/");

                if (path.Equals(abNode.Path))
                {
                    continue;                           //依赖自己
                }
                if (!IsFileVaild(path))
                {
                    continue;                     //判读文件合法性。具体看整合代码
                }
                var abDependNode = CreateNode(path);

                abNode.Dependences.Add(path, abDependNode);          //添加依赖项

                abDependNode.BeDependences.Add(abNode.Path, abNode); //添加被依赖项

                if (!abNodeDic.ContainsKey(path))
                {
                    abNodeDic.Add(path, abDependNode);

                    AnalyzeNode(abDependNode); //递归分析,保证所有节点被创建
                }
            }
        }
Ejemplo n.º 2
0
 private string GetAbName(ABNode abNode)
 {
     if (abNode.IsRoot)
     {
         // root节点以所在路径为加载路径
         return(abNode.Name.Replace("Assets/", "") + ".ab");
     }
     else
     {
         // 依赖节点以guid作为路径
         return("depends/" + AssetDatabase.AssetPathToGUID(abNode.Path) + ".ab");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private ABNode CreateNode(string path)
        {
            if (!abNodeDic.ContainsKey(path))
            {
                var abNode = new ABNode()
                {
                    Name = Path.GetFileNameWithoutExtension(path),
                    Path = path,
                };

                abNode.Combinelist.Add(path);

                abNodeDic.Add(path, abNode);
            }

            return(abNodeDic[path]);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 所有依赖项合并
        /// </summary>
        /// <param name="abNode"></param>
        private void MergeWithDependNode(ABNode abNode)
        {
            if (abNode.IsCombine)
            {
                return;
            }

            var depends = abNode.Dependences.Values.ToArray();

            for (var i = 0; i < depends.Length; i++)
            {
                if (depends[i].IsCombine)
                {
                    continue;
                }

                for (var j = i + 1; j < depends.Length; j++)
                {
                    if (depends[j].IsCombine)
                    {
                        continue;
                    }

                    if (IsBeDependsEqual(depends[i], depends[j]))
                    {
                        depends[i].Combinelist.AddRange(depends[j].Combinelist);

                        foreach (var beDepend in depends[j].BeDependences.Values)
                        {
                            beDepend.Dependences.Remove(depends[j].Path);
                        }

                        depends[j].IsCombine = true;

                        depends[j].BeDependences.Clear();

                        abNode.Dependences.Remove(depends[j].Path);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private bool IsBeDependsEqual(ABNode a, ABNode b)
        {
            if (a.BeDependences.Count != b.BeDependences.Count)
            {
                return(false);
            }

            if (a.BeDependences.Count == 0)
            {
                return(false);
            }

            foreach (var beDepend in a.BeDependences.Values)
            {
                if (!b.BeDependences.ContainsKey(beDepend.Path))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 跟被依赖合并
        /// </summary>
        /// <param name="abNode"></param>
        private void MergeWithBeDependNode(ABNode abNode)
        {
            if (abNode.IsCombine)
            {
                return;
            }

            if (abNode.Path.ToLower().EndsWith(".shader"))
            {
                return;
            }

            if (abNode.Dependences.Count == 0)
            {
                // 向上合并
                if (abNode.BeDependences.Count == 1)
                {
                    var beDepend = abNode.BeDependences.Values.ToArray()[0];

                    abNode.IsCombine = true;

                    beDepend.Combinelist.AddRange(abNode.Combinelist);

                    abNode.BeDependences.Remove(beDepend.Path);

                    beDepend.Dependences.Remove(abNode.Path);
                }
            }
            else
            {
                var depends = abNode.Dependences.Values.ToArray();

                for (var i = 0; i < depends.Length; i++)
                {
                    MergeWithBeDependNode(depends[i]);
                }
            }
        }