示例#1
0
        public void CreateVersionFile(List <BundleInfo> bundles, bool copyToStreamingAssets = false)
        {
            string        destPath = copyToStreamingAssets ? ResourcesPath : BuildPath;
            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);

            using (MemoryStream memeory = new MemoryStream())
            {
                StreamUtils.Write(memeory, verJson);
                BundleEncode.CreateBinaryFileAndHead(destPath + "/" + BundleConfig.versionFileName, memeory.ToArray());
            }

            // 对比后的新文件
            //BundleManager.GetInstance ().UpdateLocalVersionConfig (vc, destPath + "/" + BundleConfig.versionFileName + BundleConfig.suffix);
        }
示例#2
0
        public AssetBundle LoadAssetBundle(string bundleName, bool cache = true)
        {
            if (assetBundleCache.ContainsKey(bundleName))
            {
                return(assetBundleCache[bundleName]);
            }
            AssetBundle bundle = null;

            var memory = BundleLoader.LoadFileMemory(LocalVersionConfig.bundleRelativePath + "/" + bundleName + BundleConfig.suffix);

            using (var bundleStream = BundleEncode.DeompressAndDecryptLZMA(memory, password))
            {
                if (bundleStream == null)
                {
                    return(bundle);
                }
                bundle = AssetBundle.CreateFromMemoryImmediate(bundleStream.ToArray());
                if (bundle == null)                             // 如果没有则直接返回
                {
                    return(bundle);
                }
            }
            if (cache)
            {
                assetBundleCache.Add(bundleName, bundle);
            }
            return(bundle);
        }
示例#3
0
        void CopyResources()
        {
            string destPath = isPackageInApp
                                ? BundleConfig.resourcesPath + "/" + BundleConfig.bundleRelativePath
                                : BuildPath;

            if (Directory.Exists(destPath))
            {
                Directory.Delete(destPath, true);
            }
            Directory.CreateDirectory(destPath);

            foreach (var bundle in bundles)
            {
                var bytes  = File.ReadAllBytes(BundleConfig.bundlePoolRelativePath + "/" + buildTarget + "/" + bundle.name);
                var memory = BundleEncode.GetCompressAndEncryptLZMA(bytes, BundleConfig.password);

                bundle.size = (uint)memory.Length;
                bundle.md5  = BundleEncode.GetFileMD5(memory);

                if (isPackageInApp || !bundle.isExist())
                {
                    BundleEncode.CreateBinaryFile(destPath + "/" + BundleConfig.versionFileName, memory);
                }
            }
        }
示例#4
0
        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)
                {
                    Debug.Log("Item is : " + item.name);
                    count = (int)item.size;
                    using (MemoryStream bundleStream = new MemoryStream()){
                        bundleStream.Write(buffer, index, count);
                        //File.WriteAllBytes (BuildPath + "/" + item.name + BundleConfig.suffix, bundleStream.ToArray ());
                        var decryptBuffer = BundleEncode.DeompressAndDecryptLZMA(bundleStream.ToArray(), BundleConfig.password);
                        var assetbundle   = AssetBundle.CreateFromMemoryImmediate(decryptBuffer.ToArray());
                        foreach (var entry in item.include)
                        {
                            Debug.Log("Asset Name is : " + entry);
                        }
                        assetbundle.Unload(true);
                    }
                    index += count;
                }
            }
        }
示例#5
0
        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);
        }