Beispiel #1
0
        public virtual BundleManifest CopyAssetBundle(BundleManifest manifest, DirectoryInfo src, DirectoryInfo dest, List <IBundleModifier> bundleModifierChain = null, IBundleFilter bundleFilter = null)
        {
            if (!src.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Not found the directory '{0}'.", src.FullName));
            }

            try
            {
                foreach (BundleInfo bundleInfo in manifest.GetAll())
                {
                    if (bundleFilter != null && !bundleFilter.IsValid(bundleInfo))
                    {
                        continue;
                    }

                    FileInfo   srcFile    = new FileInfo(System.IO.Path.Combine(src.FullName, bundleInfo.Filename).Replace(@"\", "/"));
                    byte[]     data       = File.ReadAllBytes(srcFile.FullName);
                    BundleData bundleData = new BundleData(bundleInfo, data);
                    if (bundleModifierChain != null && bundleModifierChain.Count > 0)
                    {
                        foreach (IBundleModifier modifier in bundleModifierChain)
                        {
                            modifier.Modify(bundleData);
                        }
                    }

                    FileInfo destFile = new FileInfo(System.IO.Path.Combine(dest.FullName, bundleInfo.Filename).Replace(@"\", "/"));
                    if (destFile.Exists)
                    {
                        destFile.Delete();
                    }

                    if (!destFile.Directory.Exists)
                    {
                        destFile.Directory.Create();
                    }

                    File.WriteAllBytes(destFile.FullName, bundleData.Data);
                }
                return(manifest);
            }
            catch (System.Exception e)
            {
                throw new System.Exception(string.Format("Copy AssetBundles failure from {0} to {1}.", src.FullName, dest.FullName), e);
            }
        }
Beispiel #2
0
        public virtual BundleManifest CopyAssetBundleAndManifest(DirectoryInfo src, DirectoryInfo dest, List <IBundleModifier> bundleModifierChain = null, IBundleFilter bundleFilter = null)
        {
            if (!src.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Not found the directory '{0}'.", src.FullName));
            }

            try
            {
                string         json     = File.ReadAllText(System.IO.Path.Combine(src.FullName, BundleSetting.ManifestFilename).Replace(@"\", "/"));
                BundleManifest manifest = BundleManifest.Parse(json);
                manifest = this.CopyAssetBundle(manifest, src, dest, bundleModifierChain, bundleFilter);
                if (manifest != null)
                {
                    File.WriteAllText(System.IO.Path.Combine(dest.FullName, BundleSetting.ManifestFilename).Replace(@"\", "/"), manifest.ToJson());
                }
                return(manifest);
            }
            catch (System.Exception e)
            {
                throw new System.Exception(string.Format("Copy AssetBundles failure from {0} to {1}.", src.FullName, dest.FullName), e);
            }
        }