public IEnumerator FinalizeDownloadRequest(UnityWebRequest request, DLCBundle bundle) { if (requiresUnpacking.Contains(request) && !(request.isHttpError || request.isNetworkError)) { // construct the parameters to decompress file DecompressZipfileParams p = new DecompressZipfileParams(bundle.path, bundle.category); // create a new thread so we dont block the main thread while we decompress Thread t = new Thread(DecompressZipfile); // start the work t.Start(p); // wait till the thread indicates it's ready yield return(new WaitUntil(() => p.isFinished)); // join the thread t.Join(); // remove the request from the requiresUnpacking list requiresUnpacking.Remove(request); // delete the zip file we downloaded earlier DeleteFile(bundle.path); } request.Dispose(); }
private IEnumerator LoadSceneFromBundle(DLCBundle bundle, Action <string> errorCallback) { if (!LoadDLL(bundle)) { errorCallback("error: couldn't load assembly"); yield break; } AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(bundle.path); yield return(request); if (request.assetBundle == null) { errorCallback("error: could't read assetbundle"); yield break; } loadedBundle = request.assetBundle; string[] scenePaths = loadedBundle.GetAllScenePaths(); if (scenePaths.Length == 0) { errorCallback("error: no scenes in assetbundle"); loadedBundle.Unload(true); yield break; } AnalyticsService.Instance.LogEvent("scene_load", new Dictionary <string, object> { { "scene_name", scenePaths[0] } }); AsyncOperation async = SceneManager.LoadSceneAsync(scenePaths[0], LoadSceneMode.Single); SceneManager.sceneLoaded += OnExternalSceneLoaded; }
public UnityWebRequest HeadBundleRequest(DLCBundle bundle) { string path = hostPath + SystemInfoUtil.PlatformName() + "/" + bundle.category + "/" + bundle.name; UnityWebRequest www = UnityWebRequest.Head(path); return(www); }
public void ReadDLCList(bool forceReload = false) { if (localBundles != null && !forceReload) { return; } localBundles = new List <DLCBundle>(); // glob directories: these are the different categories DirectoryInfo[] categories = new DirectoryInfo(GetDLCPath()).GetDirectories(); // per directory find all files: these are the assets foreach (DirectoryInfo dir in categories) { FileInfo[] files = dir.GetFiles("*.unity3d"); // construct an asset object for each file and add it to the list foreach (FileInfo file in files) { DLCBundle bundle = BundleFromFile(file, dir); if (!PlayerPrefs.HasKey(GetDownloadKey(bundle))) { localBundles.Add(bundle); } else { DLCManager.Instance.CleanUpDLCBundle(bundle); } } } }
public void DeleteBundle(DLCBundle bundle) { AnalyticsService.Instance.LogEvent("dlc_manager", new Dictionary <string, object> { { "msg", "Deleting bundle: " + bundle.ToString() } }); DeleteFile(bundle.path); DeleteFile(bundle.DLLPath()); }
private IEnumerator GetRemoteBundleSize(DLCBundle bundle) { UnityWebRequest r = HeadBundleRequest(bundle); yield return(r.SendWebRequest()); if (!r.isHttpError && !r.isNetworkError) { bundle.byteSize = int.Parse(r.GetResponseHeader("Content-Length")); } }
private DLCBundle BundleFromFile(FileInfo file, DirectoryInfo dir) { DLCBundle bundle = new DLCBundle(); bundle.name = file.Name; bundle.category = dir.Name; bundle.path = file.FullName; bundle.has_dll = File.Exists(file.FullName.Replace(".unity3d", ".dll")); bundle.byteSize = file.Length; return(bundle); }
public UnityWebRequest DownloadBundleRequest(DLCBundle bundle) { string path = hostPath + SystemInfoUtil.PlatformName() + "/" + bundle.category + "/" + bundle.name; UnityWebRequest www = UnityWebRequest.Get(path); bundle.path = Path.Combine(DLCLocalService.Instance.GetDLCPath(), Path.Combine(bundle.category, bundle.name)); DownloadHandlerFile handler = new DownloadHandlerFile(bundle.path); handler.removeFileOnAbort = true; www.downloadHandler = handler; if (bundle.IsZip()) { requiresUnpacking.Add(www); } return(www); }
private bool LoadDLL(DLCBundle bundle) { if (bundle.has_dll) { if (!loadedAssemblies.Contains(bundle.path)) { try { Assembly.LoadFrom(bundle.path.Replace(".unity3d", ".dll")); loadedAssemblies.Add(bundle.path); return(true); } catch (Exception e) { AnalyticsService.Instance.LogEvent(AnalyticsService.EventType.Error, new Dictionary <string, object> { { "load-assembly", e.Message } }); return(false); } } } return(true); }
public void LoadDLCScene(DLCBundle bundle, Action <string> errorCallback) { sourceScene = SceneManager.GetActiveScene().name; StartCoroutine(LoadSceneFromBundle(bundle, errorCallback)); }
public string GetDownloadKey(DLCBundle bundle) { return(to_download_key_prefix + bundle.category + "-" + bundle.name); }