private static async Task LoadBundleFromServer(object __instance) { EasyBundleHelper easyBundle = new EasyBundleHelper(__instance); var path = easyBundle.Path; var bundleKey = Regex.Split(path, "bundle/", RegexOptions.IgnoreCase)[1]; var cachePath = Settings.cachePach; if (path.IndexOf("http") != -1) { using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(path)) { unityWebRequest.certificateHandler = _certificateHandler; unityWebRequest.disposeCertificateHandlerOnDispose = false; await unityWebRequest.SendWebRequest().Await(); if (!unityWebRequest.isNetworkError && !unityWebRequest.isHttpError) { var fileName = path.Split('/').ToList().Last(); var dirPath = Regex.Split(bundleKey, fileName, RegexOptions.IgnoreCase)[0]; if (!Directory.Exists(cachePath + dirPath)) { Directory.CreateDirectory(cachePath + dirPath); } File.WriteAllBytes(cachePath + bundleKey, unityWebRequest.downloadHandler.data); easyBundle.Path = cachePath + bundleKey; } else { Debug.Log("cant load " + path + " because of error " + unityWebRequest.error); } } } await easyBundle.LoadingCoroutine(); }
static bool PatchPrefix(IEasyBundle __instance, string key, string rootPath, UnityEngine.AssetBundleManifest manifest, IBundleLock bundleLock) { EasyBundleHelper esayBundle = new EasyBundleHelper(__instance); esayBundle.Key = key; var path = rootPath + key; BundleInfo bundle; if (Settings.bundles.TryGetValue(key, out bundle)) { path = bundle.Path; } esayBundle.Path = path; esayBundle.KeyWithoutExtension = Path.GetFileNameWithoutExtension(key); string[] dependencyKeys = manifest.GetDirectDependencies(key); foreach (KeyValuePair <string, BundleInfo> kvp in Settings.bundles) { if (!key.Equals(kvp.Key)) { continue; } List <string> result = dependencyKeys == null ? new List <string>() : dependencyKeys.ToList <string>(); dependencyKeys = result.Union(kvp.Value.DependencyKeys).ToList <string>().ToArray <string>(); break; } esayBundle.DependencyKeys = dependencyKeys; esayBundle.LoadState = new BindableState(ELoadState.Unloaded, null); esayBundle.BundleLock = bundleLock; return(false); }