void GetAssetPoolBundles() { string relativePath = BuildPath + "/" + BundleConfig.versionFileName; var memory = File.ReadAllBytes(relativePath); using (MemoryStream memoryStream = new MemoryStream()) { byte[] length = null; int offset = System.Runtime.InteropServices.Marshal.SizeOf(typeof(int)); memoryStream.Write(memory, 0, offset); length = memoryStream.ToArray(); var versionLength = BitConverter.ToInt32(length, 0); memoryStream.Position = 0; memoryStream.Write(memory, offset, versionLength); byte[] versionByte = memoryStream.ToArray(); using (MemoryStream versionStream = new MemoryStream(versionByte)) { string versionContent = ""; StreamUtils.Read(versionStream, out versionContent); currVersion = JsonMapper.ToObject <VersionConfig>(versionContent); } offset = offset + versionByte.Length; int limit = memory.Length - offset; memoryStream.Position = 0; memoryStream.Write(memory, offset, limit); byte[] buffer = memoryStream.ToArray(); int index = 0; int count = 0; foreach (var item in currVersion.bundles) { count = ( int )item.size; using (MemoryStream bundleStream = new MemoryStream()) { bundleStream.Write(buffer, index, count); var decryptBuffer = BundleEncode.DeompressAndDecryptLZMA(bundleStream.ToArray(), BundleConfig.password); var assetbundle = AssetBundle.CreateFromMemoryImmediate(decryptBuffer.ToArray()); assetbundle.Unload(true); } index += count; } } }
void GetAssetPoolBundles(byte[] memory) { using (MemoryStream memoryStream = new MemoryStream()) { byte[] length = null; int offset = System.Runtime.InteropServices.Marshal.SizeOf(typeof(int)); memoryStream.Write(memory, 0, offset); length = memoryStream.ToArray(); var versionLength = BitConverter.ToInt32(length, 0); memoryStream.Position = 0; memoryStream.Write(memory, offset, versionLength); byte[] versionByte = memoryStream.ToArray(); VersionConfig diffVersion = null; using (MemoryStream versionStream = new MemoryStream(versionByte)) { string versionContent = ""; StreamUtils.Read(versionStream, out versionContent); diffVersion = JsonMapper.ToObject <VersionConfig>(versionContent); } offset = offset + versionByte.Length; int limit = memory.Length - offset; memoryStream.Position = 0; memoryStream.Write(memory, offset, limit); byte[] buffer = memoryStream.ToArray(); int index = 0; int count = 0; foreach (var item in diffVersion.bundles) { Debug.Log("Item is : " + item.name); count = (int)item.size; using (MemoryStream bundleStream = new MemoryStream()){ bundleStream.Write(buffer, index, count); File.WriteAllBytes(Application.temporaryCachePath + "/" + BundleConfig.bundleRelativePath + "/" + item.name + BundleConfig.suffix, bundleStream.ToArray()); } index += count; } UpdateLocalVersionConfig(diffVersion, Application.temporaryCachePath + "/" + BundleConfig.bundleRelativePath + "/" + BundleConfig.versionFileName + BundleConfig.suffix); } }
public void CreateVersionFile(List <BundleInfo> bundles, bool copyToStreamingAssets = false) { string destPath = ""; if (copyToStreamingAssets) { destPath = ResourcesPath + "/" + BundleConfig.versionFileName + BundleConfig.suffix; } else { destPath = BuildPath + BundleConfig.versionFileName; } VersionConfig vc = new VersionConfig(); vc.versionNum = DateTime.Now.ToString(); vc.bundleRelativePath = BundleConfig.bundleRelativePath; if (!copyToStreamingAssets) { foreach (var item in bundles) { if (!item.isExist()) { vc.bundles.Add(item); } } } else { vc.bundles = bundles; } string verJson = JsonMapper.ToJson(vc); BundleEncode.CreateBinaryFileAndHead(destPath, verJson); // Diff version file //BundleManager.GetInstance ().UpdateLocalVersionConfig (vc, destPath + "/" + BundleConfig.versionFileName + BundleConfig.suffix); }