static void BuildAsset(BuildTarget target) { string Path = GetPath(target); string outPath = "Assets/Patcher/ABs/" + Path; if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath); AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outPath, BuildAssetBundleOptions.None, target); if(null != manifest) { Patcher.PatcherElem elem = new Patcher.PatcherElem(); string[] abs = manifest.GetAllAssetBundles(); foreach(var ab in abs) { Patcher.PatcherElem.Elem e = new Patcher.PatcherElem.Elem(); e.szName = ab; e.mVersion = manifest.GetAssetBundleHash(ab).ToString(); e.mDepends = manifest.GetAllDependencies(ab); string filePath = outPath + "/" + ab; byte[] bs = File.ReadAllBytes(filePath); e.mLength = bs.Length; elem.AddElem(e); } string manifestPath = Application.dataPath + "/Patcher/ABs/" + Path; elem.Serialize(manifestPath + "/Pather.txt"); } AssetDatabase.Refresh(); }
void Update() { if (mDownloads == null) { return; } if (mStatus != STATUS.DOWNLOADING) { return; } if (mDownloads.mElems.Count == 0) { mStatus = STATUS.NONE; if (null != mOnFinish) { mOnFinish(mDownloadeds); } } mLeft = 0; List <Patcher.PatcherElem.Elem> rm = new List <Patcher.PatcherElem.Elem>(); foreach (var e in mDownloads.mElems) { if (e.mDonload.isDone) { if (e.mDonload.error == null) { File.WriteAllBytes(e.ResPath, e.mDonload.bytes); e.mDonload = null; rm.Add(e); } else { mStatus = STATUS.ERROR; } } else { mLeft += (int)(e.mLength * (1 - e.mDonload.progress)); } } bool mWrite = false; foreach (var r in rm) { mDownloads.RemoveElem(r); mDownloadeds.AddElem(r); mWrite = true; } if (mWrite) { string localPath = Application.persistentDataPath + "/Pather"; mDownloadeds.Serialize(localPath); } }