Example #1
0
    static long MatchFileInfo(string path, ref List <FileInfo> olist, ref List <FileInfo> nlist,
                              ref Dictionary <string, List <string> > buildin,
                              ref HashSet <string> named, ref long csize, HashSet <string> obs = null)
    {
        if (buildin != null)
        {
            foreach (var b in  buildin)
            {
                if (path.IndexOf(b.Key) >= 0)
                {
                    b.Value.Add(path);
                    return(0);
                }
            }
        }

        if (named.Contains(path))
        {
            return(0);
        }

        try
        {
            string   fullpath = Path.Combine(Application.dataPath.Replace("Assets", ""), path);
            FileInfo fs       = new FileInfo(fullpath);
            if (!fs.Exists)
            {
                return(0);
            }

            string nfp = GetBundlesInfoName(path);
            var    bi  = BundleInfoManager.GetBundleInfoWithFullPath(nfp);
            if (bi == null)
            {
                nlist.Add(fs);
            }
            else if (obs != null && Path.GetDirectoryName(bi.name) != CommonAssets)
            {
                nlist.Add(fs);
            }
            else if (obs == null && Path.GetDirectoryName(bi.name) == CommonAssets)
            {
                nlist.Add(fs);
            }
            else
            {
                olist.Add(fs);
            }

            named.Add(path);
            long fsize = GetFileSize(path, fs.Length);
            csize += fsize;
            return(fsize);
        }catch (Exception ex)
        {
            Debug.Log(ex);
        }
        return(0);
    }
Example #2
0
    static bool ReBuildAssetBundles(string directory, List <FileInfo> ofiles, List <FileInfo> nfiles,
                                    ref List <BundleInfo> bundles, ref int count,
                                    bool igoresize = false)
    {
        List <BundleInfo> oldlbds = new List <BundleInfo>();

        ofiles.Sort(new FileComparer());
        nfiles.Sort(new FileComparer());
        directory = directory == CommonAssets ? CommonAssets : DataAssets;

        for (int i = 0; i < ofiles.Count; ++i)
        {
            var    f        = ofiles[i];
            string filePath = f.FullName.Replace('\\', '/').Replace(Application.dataPath, "Assets");
            string nfp      = GetBundlesInfoName(filePath);// filePath.Replace("Assets/" + RootDir + "/", "").ToLower();
            if (EditorUtility.DisplayCancelableProgressBar(string.Format("name {0}/{1}", i, ofiles.Count), filePath, (float)i / (float)ofiles.Count))
            {
                return(false);
            }
            var bdi  = BundleInfoManager.GetBundleInfoWithFullPath(nfp);
            var nbdi = bundles.Find((info) =>
            {
                return(info.name == bdi.name);
            });
            if (nbdi == null)
            {
                nbdi = new BundleInfo(bdi.name);

                bundles.Add(nbdi);
            }

            if (!oldlbds.Contains(nbdi))
            {
                oldlbds.Add(nbdi);
            }
            count++;

            nbdi.files.Add(nfp);
            nbdi.size += f.Length;
            SetAssetBundleName(filePath, nbdi.name);
        }

        BundleInfo cbdi = null;

        // find min bundle, ready for insert
        for (int i = 0; i < oldlbds.Count; ++i)
        {
            var v = oldlbds[i];
            if (cbdi != null)
            {
                if (v.size < cbdi.size)
                {
                    cbdi = v;
                }

                continue;
            }

            if (v.size < BundleMinSize)
            {
                cbdi = v;
            }
        }

        for (int i = 0; i < nfiles.Count; ++i)
        {
            var    f        = nfiles[i];
            string filePath = f.FullName.Replace('\\', '/').Replace(Application.dataPath, "Assets");

            if (EditorUtility.DisplayCancelableProgressBar(string.Format("name {0} {1}/{2}", directory, i, nfiles.Count), filePath, (float)i / (float)nfiles.Count))
            {
                return(false);
            }

            string nfp  = GetBundlesInfoName(filePath);
            long   size = GetFileSize(filePath, f.Length);

            if (cbdi == null)
            {
                cbdi = new BundleInfo(directory + "/" + BundleInfoManager.GetEmptyBundleName());
                bundles.Add(cbdi);
            }

            if (size > BundleMinSize * 1.5 && !igoresize)
            {
                var nbdi = new BundleInfo(directory + "/" + BundleInfoManager.GetEmptyBundleName());
                bundles.Add(nbdi);
                nbdi.files.Add(nfp);
                SetAssetBundleName(filePath, nbdi.name);
                Debug.LogFormat("file '{0}' is large {1}", filePath, size);
            }
            else
            {
                cbdi.files.Add(nfp);
                cbdi.size += f.Length;
                SetAssetBundleName(filePath, cbdi.name);

                if (cbdi.size > BundleMinSize && !igoresize)
                {
                    cbdi = null;
                }
            }
            count++;
        }

        return(true);
    }