Esempio n. 1
0
        /// <summary>
        /// 查找自己被使用了几次.
        /// </summary>
        /// <param name="tempNode"></param>
        private void BuildAlreadyBuildCount(AssetDependenctGraph.Node tempNode)
        {
            for (int i = 0; i < tempNode.Parents.Count; i++)
            {
                AssetDependenctGraph.Node node;

                if (Tree.TryGetValue(tempNode.Parents[i], out node))
                {
                    AssetBundleInfo bundles;

                    var bundleKey = BuildUtils.GetPathDirWithoutExtension(tempNode.Parents[i]);

                    if (sortedBundleTree.TryGetValue(bundleKey, out bundles))
                    {
                        if (bundles.AlreadyBuild())// && Mathf.Abs(bundles.selfNode.Depth - this.selfNode.Depth) == 1)
                        {
                            alreadyBuildCount++;
                            continue;
                        }
                    }
                    if (node.Parents != null && node.Parents.Count > 0)
                    {
                        //继续上走
                        BuildAlreadyBuildCount(node);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 构建除了单独打包之外的其他资源
        /// </summary>
        /// <param name="withSubAsset"></param>
        private static AssetBundleBuild[] BuildAllResourceEx(Dictionary <string, AssetDependenctGraph.Node> dic, bool withSubAsset = true)
        {
            var assetBundlesList = new List <AssetBundleBuild>();

            //自底层分析出来 哪个资源需要单独拆出来打包
            int maxdepth = AssetDependenctGraph.Node.MaxDepth;

            //资源按照depth排序 计算出来最大的深度
            for (int i = maxdepth; i >= 0; i--)
            {
                var currentDepth = i;

                //获取某一 depth 的所有资源数据
                var alldepth = BuildUtils.FindAll(dic, tree => tree.PositiveDepth == currentDepth);

                for (int j = 0; j < alldepth.Count; j++)
                {
                    AssetBundleInfo info;

                    var bundleKey = BuildUtils.GetPathDirWithoutExtension(alldepth[j].NodePath);

                    //如果不在资源打包列表,那么添加进来
                    if (!bundleListEx.TryGetValue(bundleKey, out info))
                    {
                        info = new AssetBundleInfo(alldepth[j], dic, bundleListEx);

                        Debug.Log(bundleKey);

                        bundleListEx.Add(bundleKey, info);
                    }

                    //查找自己被使用了几次
                    info.BuildAlreadyBuildCount();

                    //检测是否需要单独进行打包
                    if (info.BuildAlone())
                    {
                        //设置flag已经被放到打包列表里面了
                        info.MarkAsBuild();

                        var assetBundleBuild = new AssetBundleBuild();

                        var assetBundleName = GetAssetNamePath(info) + extension;

                        assetBundleBuild.assetNames = new string[1] {
                            info.selfNode.NodePath
                        };

                        assetBundleBuild.assetBundleName = assetBundleName;

                        assetBundlesList.Add(assetBundleBuild);
                    }
                    else//如果不需要单独打包 就不做任何处理
                    {
                    }
                }
            }

            return(assetBundlesList.ToArray());
        }
Esempio n. 3
0
        ///// <summary>
        ///// 检测,设置构建单个包的数据资源
        ///// </summary>
        //static AssetBundleBuild[] BuildSinglePackage()
        //{
        //    var singleBuilds = new AssetBundleBuild[AssetBundleInfo.OnePackageTypes.Length];

        //    for (int oneIndex = 0; oneIndex < AssetBundleInfo.OnePackageTypes.Length; oneIndex++)
        //    {
        //        //进行单独打成一个包的资源数据
        //        var list = new List<AssetBundleInfo>();

        //        foreach (var result in AssetDependenctTree.resourceGraph.result)
        //        {
        //            var node = result.Value;

        //            AssetBundleInfo bundle;

        //            //获取一个没有后缀名的全路径
        //            var bundleKey = BuildUtils.GetPathDirWithoutExtension(node.NodePath);

        //            if (!bundleListEx.TryGetValue(bundleKey, out bundle))
        //            {
        //                bundle = new AssetBundleInfo(node, AssetDependenctTree.resourceGraph.result, bundleListEx);

        //                bundleListEx.Add(bundleKey, bundle);
        //            }

        //            //检测是否为当前同种类型
        //            if (AssetBundleInfo.OnePackageTypes[oneIndex] == bundle.type)
        //            {
        //                bundle.MarkAsBuild();

        //                list.Add(bundle);
        //            }
        //        }

        //        var singleBuild = new AssetBundleBuild();

        //        var assetPath = "res/" + AssetBundleInfo.OnePackageTypes[oneIndex].ToString() + extension;

        //        singleBuild.assetBundleName = assetPath;

        //        singleBuild.assetNames = new string[list.Count];

        //        for (int i = 0; i < list.Count; i++)
        //        {
        //            singleBuild.assetNames[i] = list[i].selfNode.NodePath;
        //        }

        //        singleBuilds[oneIndex] = singleBuild;
        //    }

        //    return singleBuilds;
        //}

        ///// <summary>
        ///// 构建除了单独打包之外的其他资源
        ///// </summary>
        ///// <param name="withSubAsset"></param>
        //private static AssetBundleBuild[] BuildAllResourceEx(bool withSubAsset = true)
        //{
        //    var assetBundlesList = new List<AssetBundleBuild>();

        //    //自底层分析出来 哪个资源需要单独拆出来打包
        //    int maxdepth = AssetDependenctGraph.Node.MaxDepth;

        //    //资源按照depth排序 计算出来最大的深度
        //    for (int i = maxdepth; i >= 0; i--)
        //    {
        //        var currentDepth = i;

        //        //获取某一 depth 的所有资源数据
        //        var alldepth = BuildUtils.FindAll(AssetDependenctTree.resourceGraph.result, tree => tree.Depth == currentDepth);

        //        for (int j = 0; j < alldepth.Count; j++)
        //        {
        //            AssetBundleInfo info;

        //            var bundleKey = BuildUtils.GetPathDirWithoutExtension(alldepth[j].NodePath);

        //            //如果不在资源打包列表,那么添加进来
        //            if (!bundleListEx.TryGetValue(bundleKey, out info))
        //            {
        //                info = new AssetBundleInfo(alldepth[j], AssetDependenctTree.resourceGraph.result, bundleListEx);

        //                Debug.Log(bundleKey);

        //                bundleListEx.Add(bundleKey, info);
        //            }

        //            //查找自己被使用了几次
        //            info.BuildAlreadyBuildCount();

        //            //检测是否需要单独进行打包
        //            if (info.BuildAlone())
        //            {
        //                //设置flag已经被放到打包列表里面了
        //                info.MarkAsBuild();

        //                var assetBundleBuild = new AssetBundleBuild();

        //                var assetBundleName = GetAssetNamePath(info) + extension;

        //                assetBundleBuild.assetNames = new string[1] { info.selfNode.NodePath };

        //                assetBundleBuild.assetBundleName = assetBundleName;

        //                assetBundlesList.Add(assetBundleBuild);
        //            }
        //            else//如果不需要单独打包 就不做任何处理
        //            {

        //            }
        //        }
        //    }

        //    return assetBundlesList.ToArray();
        //}

        /// <summary>
        /// 检测,设置构建单个包的数据资源
        /// </summary>
        static AssetBundleBuild[] BuildSinglePackage(Dictionary <string, AssetDependenctGraph.Node> dic)
        {
            var singleBuilds = new AssetBundleBuild[AssetBundleInfo.OnePackageTypes.Length];

            for (int oneIndex = 0; oneIndex < AssetBundleInfo.OnePackageTypes.Length; oneIndex++)
            {
                //进行单独打成一个包的资源数据
                var list = new List <AssetBundleInfo>();

                foreach (var result in dic)
                {
                    var node = result.Value;

                    AssetBundleInfo bundle;

                    //获取一个没有后缀名的全路径
                    var bundleKey = BuildUtils.GetPathDirWithoutExtension(node.NodePath);

                    if (!bundleListEx.TryGetValue(bundleKey, out bundle))
                    {
                        bundle = new AssetBundleInfo(node, dic, bundleListEx);

                        bundleListEx.Add(bundleKey, bundle);
                    }

                    //检测是否为当前同种类型
                    if (AssetBundleInfo.OnePackageTypes[oneIndex] == bundle.type)
                    {
                        bundle.MarkAsBuild();

                        list.Add(bundle);
                    }
                }

                var singleBuild = new AssetBundleBuild();

                var assetPath = "res/" + AssetBundleInfo.OnePackageTypes[oneIndex].ToString() + extension;

                singleBuild.assetBundleName = assetPath;

                singleBuild.assetNames = new string[list.Count];

                for (int i = 0; i < list.Count; i++)
                {
                    singleBuild.assetNames[i] = list[i].selfNode.NodePath;
                }

                singleBuilds[oneIndex] = singleBuild;
            }

            return(singleBuilds);
        }
Esempio n. 4
0
        /// <summary>
        /// 按照目录进行打包
        /// </summary>
        static AssetBundleBuild[] BuildDirectoryPackage(Dictionary <string, AssetDependenctGraph.Node> all)
        {
            List <AssetBundleBuild> singleBuilds = new List <AssetBundleBuild>();

            //需要进行目录打包的资源
            Dictionary <string, List <AssetBundleInfo> > dic = new Dictionary <string, List <AssetBundleInfo> >();

            for (int oneIndex = 0; oneIndex < AssetBundleInfo.DirectoryTypes.Length; oneIndex++)
            {
                foreach (var result in all)
                {
                    var node = result.Value;

                    AssetBundleInfo bundle;

                    //获取一个没有后缀名的全路径
                    var bundleKey = BuildUtils.GetPathDirWithoutExtension(node.NodePath);

                    if (!bundleListEx.TryGetValue(bundleKey, out bundle))
                    {
                        bundle = new AssetBundleInfo(node, all, bundleListEx);

                        bundleListEx.Add(bundleKey, bundle);
                    }

                    //检测是否为当前同种类型
                    if (AssetBundleInfo.DirectoryTypes[oneIndex] == bundle.type)
                    {
                        bundle.MarkAsBuild();

                        string url = Path.GetDirectoryName(node.NodePath);

                        if (dic.ContainsKey(url))
                        {
                            dic[url].Add(bundle);
                        }
                        else
                        {
                            List <AssetBundleInfo> list = new List <AssetBundleInfo>();
                            list.Add(bundle);
                            dic[url] = list;
                        }
                    }
                }


                foreach (var item in dic)
                {
                    var singleBuild = new AssetBundleBuild();

                    var assetPath = AssetPathRule.GetDirectoryBuildBundlePath(item.Key) + extension;

                    singleBuild.assetBundleName = assetPath;

                    var list = item.Value;

                    singleBuild.assetNames = new string[list.Count];

                    for (int i = 0; i < list.Count; i++)
                    {
                        singleBuild.assetNames[i] = list[i].selfNode.NodePath;
                    }

                    singleBuilds.Add(singleBuild);
                }
            }

            return(singleBuilds.ToArray());
        }