void WaitURL() { if (mWeb.isDone) { if (mWeb.isError) { if (null != mOnFinish) { mOnFinish(null, mWeb.error); } mStatus = STATUS.NONE; } else { string txt = mWeb.downloadHandler.text; BundleManifest mRemoteManifest = XmlHelper.XmlDeserialize <BundleManifest>(txt, System.Text.Encoding.UTF8); foreach (var b in mRemoteManifest.mBundles.mList) { mRemoteBundle[b.mName] = b; } mStatus = STATUS.OBTAIN_LOCAL; } mWeb.Dispose(); mWeb = null; } }
void ObtainLocal() { string path = System.IO.Path.Combine(mLocal, "bundleManifest"); string localTxt = File.ReadAllText(path); BundleManifest mLocalManifest = XmlHelper.XmlDeserialize <BundleManifest>(localTxt, System.Text.Encoding.UTF8); foreach (var b in mLocalManifest.mBundles.mList) { mLocalBundle[b.mName] = b; } mStatus = STATUS.COMPARE; }
void BuildBundle(BuildTarget bt) { string path = EditorUtility.SaveFolderPanel(string.Empty, string.Empty, string.Empty); if (!string.IsNullOrEmpty(path)) { BundleManifest bundleManifest = new BundleManifest(); List <AssetBundleBuild> abs = new List <AssetBundleBuild>(); Bundles bundlList = new Bundles(); Bundles ConfiglList = new Bundles(); string tempPath = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + "tmp"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } Directory.CreateDirectory(tempPath); string bundlePath = path + "/bundles"; string configPath = path + "/config"; if (!Directory.Exists(bundlePath)) { Directory.CreateDirectory(bundlePath); } if (!Directory.Exists(configPath)) { Directory.CreateDirectory(configPath); } foreach (var f in mFolders) { switch (f.mType) { case LancherFolder.TYPE.PREFABS: { string[] files = Directory.GetFiles(f.mFolder); foreach (var file in files) { if (!file.EndsWith(".prefab")) { continue; } string szName = Path.GetFileNameWithoutExtension(file); AssetBundleBuild ab = new AssetBundleBuild(); ab.assetBundleName = szName; ab.assetNames = new string[] { file }; abs.Add(ab); } } break; case LancherFolder.TYPE.CONFIG: { string[] files = Directory.GetFiles(f.mFolder); foreach (var file in files) { if (file.EndsWith(".meta")) { continue; } Bundle b = new Bundle(); b.mName = Path.GetFileName(file); b.mType = Bundle.TYPE.CONFIG; b.mVersion = GetMD5HashFromFile(file); ConfiglList.mList.Add(b); string tagetPath = configPath + "/" + b.mName; string srcPath = file; if (File.Exists(tagetPath)) { FileUtil.ReplaceFile(srcPath, tagetPath); } else { FileUtil.CopyFileOrDirectory(srcPath, tagetPath); } } } break; } } AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(tempPath, abs.ToArray(), BuildAssetBundleOptions.None, bt); string[] bundels = manifest.GetAllAssetBundles(); foreach (var b in bundels) { Bundle bundle = new Bundle(); bundle.mName = b; uint crc = 0; if (BuildPipeline.GetCRCForAssetBundle(tempPath + "/" + b, out crc)) { bundle.mType = Bundle.TYPE.AB; bundle.mVersion = crc.ToString(); bundle.depences = manifest.GetAllDependencies(b); bundlList.mList.Add(bundle); } else { EditorUtility.DisplayDialog("error", "something wrong happened", "ok"); } string tagetPath = bundlePath + "/" + b; string srcPath = tempPath + "/" + b; if (File.Exists(tagetPath)) { FileUtil.ReplaceFile(srcPath, tagetPath); } else { FileUtil.CopyFileOrDirectory(srcPath, tagetPath); } } bundleManifest.mBundles = bundlList; bundleManifest.mBundles.mList.AddRange(ConfiglList.mList); Directory.Delete(tempPath, true); XmlHelper.XmlSerializeToFile(bundleManifest, path + "/bundleManifest", System.Text.Encoding.UTF8); } }