Exemple #1
0
        //这里需要做下合并,减少ab数量:一个依赖的与依赖合并,一个引用的与引用合并
        private void Build4Share()
        {
            List <string>          shareAssetList  = CollectShare();
            List <AssetBundlePair> shareBundleList = GetOrCreateShareList();

            Dictionary <string, string> depMap = new Dictionary <string, string>();
            Dictionary <string, string> refMap = new Dictionary <string, string>();

            if (AssetBuildConfiger.GetInstance().isOptimzeShareBundle)
            {
                foreach (var assetPath in shareAssetList)
                {
                    string[] dps = AssetBuildRelationship.GetDependencies(assetPath);
                    foreach (var dp in dps)
                    {
                        //忽略自己
                        if (string.Compare(assetPath, dp, true) == 0)
                        {
                            continue;
                        }

                        // 单一依赖
                        if (dps.Length == 2)
                        {
                            depMap[assetPath] = dp;
                        }

                        //单一引用
                        if (refMap.ContainsKey(dp))
                        {
                            refMap[dp] = "";    //已经不是单一引用了
                        }
                        else
                        {
                            refMap[dp] = assetPath;
                        }
                    }
                }
            }

            foreach (var assetPath in shareAssetList)
            {
                string shareBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(assetPath);//全部打到Share里去
                if (depMap.TryGetValue(assetPath, out var depFilePath))
                {
                    shareBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(depFilePath);
                }
                else if (refMap.TryGetValue(assetPath, out var refFilePath))
                {
                    if (!string.IsNullOrEmpty(refFilePath))
                    {
                        shareBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(refFilePath);
                    }
                }

                shareBundleList.Add(new AssetBundlePair(assetPath, shareBundleName));
            }
        }
Exemple #2
0
        private List <string> CollectShare()
        {
            Dictionary <string, int> refCounts = new Dictionary <string, int>();

            foreach (var kv in m_buildAssetMap)
            {
                foreach (var fullPath in kv.Value)
                {
                    string   assetPath = XPathTools.GetRelativePath(fullPath);
                    string[] dps       = AssetBuildRelationship.GetDependencies(assetPath);
                    foreach (var dp in dps)
                    {
                        if (refCounts.TryGetValue(dp, out var refCount))
                        {
                            refCounts[dp] = refCount + 1;
                        }
                        else
                        {
                            refCounts.Add(dp, 1);
                        }
                    }
                }
            }

            List <string> shareAssetList = new List <string>();

            foreach (var refKV in refCounts)
            {
                if (refKV.Value > 1)
                {
                    shareAssetList.Add(refKV.Key);
                }
            }

            return(shareAssetList);
        }
Exemple #3
0
 protected virtual string[] GetDependencies(string assetPath)
 {
     assetPath = XPathTools.GetRelativePath(assetPath);
     return(AssetBuildRelationship.GetDependencies(assetPath));
 }