Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        public UnityWebRequest HeadBundleRequest(DLCBundle bundle)
        {
            string          path = hostPath + SystemInfoUtil.PlatformName() + "/" + bundle.category + "/" + bundle.name;
            UnityWebRequest www  = UnityWebRequest.Head(path);

            return(www);
        }
Exemplo n.º 4
0
        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);
                    }
                }
            }
        }
Exemplo n.º 5
0
 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());
 }
Exemplo n.º 6
0
        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"));
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 public void LoadDLCScene(DLCBundle bundle, Action <string> errorCallback)
 {
     sourceScene = SceneManager.GetActiveScene().name;
     StartCoroutine(LoadSceneFromBundle(bundle, errorCallback));
 }
Exemplo n.º 11
0
 public string GetDownloadKey(DLCBundle bundle)
 {
     return(to_download_key_prefix + bundle.category + "-" + bundle.name);
 }