Beispiel #1
0
        private static int AddBundle(string path, AssetRef asset, ref List <BundleRef> bundles)
        {
            var bundleName = path.Replace("Assets/", "");
            var destFile   = Path.Combine(outputPath, bundleName);
            var destDir    = Path.GetDirectoryName(destFile);

            if (!Directory.Exists(destDir) && !string.IsNullOrEmpty(destDir))
            {
                Directory.CreateDirectory(destDir);
            }
            File.Copy(path, destFile, true);
            using (var stream = File.OpenRead(destFile))
            {
                var bundle = new BundleRef
                {
                    name = bundleName,
                    id   = bundles.Count,
                    len  = stream.Length,
                    crc  = Utility.GetCRC32Hash(stream),
                    hash = string.Empty
                };
                asset.bundle = bundles.Count;
                bundles.Add(bundle);
            }
            return(asset.bundle);
        }
Beispiel #2
0
        private static bool IsNew(BundleRef bundle)
        {
            if (localVersions != null)
            {
                if (localVersions.Contains(bundle))
                {
                    return(false);
                }
            }

            var path = updatePath + bundle.name;

            if (!File.Exists(updatePath + bundle.name))
            {
                return(true);
            }

            using (var stream = File.OpenRead(path))
            {
                if (stream.Length != bundle.len)
                {
                    return(true);
                }
                if (verifyBy != VerifyBy.CRC)
                {
                    return(false);
                }
                var comparison = StringComparison.OrdinalIgnoreCase;
                var crc        = Utility.GetCRC32Hash(stream);
                return(!crc.Equals(bundle.crc, comparison));
            }
        }
Beispiel #3
0
 public bool Equals(BundleRef other)
 {
     return(name == other.name &&
            len == other.len &&
            location == other.location &&
            crc.Equals(other.crc, StringComparison.OrdinalIgnoreCase));
 }
Beispiel #4
0
        public bool Contains(BundleRef bundle)
        {
            BundleRef file;

            if (_bundles.TryGetValue(bundle.name, out file))
            {
                if (file.Equals(bundle))
                {
                    if (patchesInBuild.Count == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        foreach (var item in patchesInBuild)
                        {
                            Patch patch;
                            if (_patches.TryGetValue(item, out patch))
                            {
                                if (patch.files.Contains(file.id))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #5
0
        public void Deserialize(BinaryReader reader)
        {
            ver = reader.ReadString();
            var count = reader.ReadInt32();

            dirs = new string[count];
            for (var i = 0; i < count; i++)
            {
                dirs[i] = reader.ReadString();
            }

            count          = reader.ReadInt32();
            activeVariants = new string[count];
            for (var i = 0; i < count; i++)
            {
                activeVariants[i] = reader.ReadString();
            }

            count = reader.ReadInt32();
            for (var i = 0; i < count; i++)
            {
                var file = new AssetRef();
                file.Deserialize(reader);
                assets.Add(file);
            }

            count = reader.ReadInt32();
            for (var i = 0; i < count; i++)
            {
                var file = new BundleRef();
                file.Deserialize(reader);
                file.id = bundles.Count;
                bundles.Add(file);
                _bundles[file.name] = file;
            }

            count = reader.ReadInt32();
            for (var i = 0; i < count; i++)
            {
                var patch = new Patch();
                patch.Deserialize(reader);
                patches.Add(patch);
                _patches[patch.name] = patch;
            }

            count = reader.ReadInt32();
            for (var i = 0; i < count; i++)
            {
                var patch = reader.ReadString();
                patchesInBuild.Add(patch);
            }
        }
Beispiel #6
0
        public bool Contains(BundleRef bundle)
        {
            BundleRef file;

            if (_bundles.TryGetValue(bundle.name, out file))
            {
                if (file.Equals(bundle))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
        private static bool IsNew(BundleRef bundle)
        {
            if (buildinVersions != null)
            {
                if (buildinVersions.Contains(bundle))
                {
                    return(false);
                }
            }

            var path = string.Format("{0}{1}", updatePath, bundle.name);
            var info = new FileInfo(path);

            if (!info.Exists)
            {
                return(true);
            }

            // 直接读取 PlayerPrefs 中保存的内容,该值在 Download.Copy 方法中写入
            var comparison = StringComparison.OrdinalIgnoreCase;
            var ver        = PlayerPrefs.GetString(path);

            if (ver.Equals(bundle.crc, comparison))
            {
                return(false);
            }

            return(true);
            // using (var stream = File.OpenRead(path))
            // {
            //     if (stream.Length != bundle.len)
            //         return true;
            //     if (verifyBy != VerifyBy.CRC)
            //         return false;
            //     var crc = Utility.GetCRC32Hash(stream);
            //     return !crc.Equals(bundle.crc, comparison);
            // }
        }
        private static void BuildManifest(AssetBundleManifest assetBundleManifest, string bundleDir, BuildRules rules)
        {
            var manifest        = GetManifest();
            var allAssetBundles = assetBundleManifest.GetAllAssetBundles();
            var bundle2Ids      = GetBundle2Ids(allAssetBundles);
            var bundles         = GetBundles(assetBundleManifest, bundleDir, allAssetBundles, bundle2Ids);
            var dirs            = new List <string>();
            var assets          = new List <AssetRef>();
            var patches         = new List <VPatch>();

            for (var i = 0; i < rules.assets.Length; i++)
            {
                var item  = rules.assets[i];
                var path  = item.path;
                var dir   = Path.GetDirectoryName(path).Replace("\\", "/");
                var index = dirs.FindIndex(o => o.Equals(dir));
                if (index == -1)
                {
                    index = dirs.Count;
                    dirs.Add(dir);
                }

                var asset = new AssetRef();
                if (!bundle2Ids.TryGetValue(item.bundle, out asset.bundle))
                {
                    // 第三方资源
                    var bundle = new BundleRef();
                    bundle.id   = bundles.Count;
                    bundle.name = Path.GetFileName(path);
                    using (var stream = File.OpenRead(path))
                    {
                        bundle.len = stream.Length;
                        bundle.crc = Utility.GetCRC32Hash(stream);
                    }

                    bundles.Add(bundle);
                    asset.bundle = bundle.id;
                }

                asset.dir  = index;
                asset.name = Path.GetFileName(path);
                assets.Add(asset);
                var patch = patches.Find(pr => pr.@by == item.patch);
                if (patch == null)
                {
                    patch = new VPatch()
                    {
                        @by = item.patch
                    };
                    patches.Add(patch);
                }
                if (asset.bundle != -1)
                {
                    if (!patch.files.Contains(asset.bundle))
                    {
                        patch.files.Add(asset.bundle);
                    }
                    var bundle = bundles[asset.bundle];
                    foreach (var child in bundle.children)
                    {
                        if (!patch.files.Contains(child))
                        {
                            patch.files.Add(child);
                        }
                    }
                }
            }

            manifest.dirs    = dirs.ToArray();
            manifest.assets  = assets.ToArray();
            manifest.bundles = bundles.ToArray();

            EditorUtility.SetDirty(manifest);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            var manifestBundleName = "manifest.unity3d";
            var builds             = new[]
            {
                new AssetBundleBuild
                {
                    assetNames      = new[] { AssetDatabase.GetAssetPath(manifest), },
                    assetBundleName = manifestBundleName
                }
            };

            var targetPlatform = EditorUserBuildSettings.activeBuildTarget;

            BuildPipeline.BuildAssetBundles(bundleDir, builds, rules.buildBundleOptions, targetPlatform);
            {
                var path   = bundleDir + "/" + manifestBundleName;
                var bundle = new BundleRef();
                bundle.id   = bundles.Count;
                bundle.name = Path.GetFileName(path);
                using (var stream = File.OpenRead(path))
                {
                    bundle.len = stream.Length;
                    bundle.crc = Utility.GetCRC32Hash(stream);
                }
                var patch = patches.Find(pr => pr.@by == PatchBy.Level0);
                if (patch == null)
                {
                    patch = new VPatch()
                    {
                        @by = PatchBy.Level0
                    };
                    patches.Add(patch);
                }
                bundles.Add(bundle);
            }
            Versions.BuildVersion(bundleDir, bundles, patches, GetBuildRules().AddVersion());
        }
Beispiel #9
0
 public bool EqualsWithContent(BundleRef other)
 {
     return(len == other.len && crc.Equals(other.crc, StringComparison.OrdinalIgnoreCase));
 }