Пример #1
0
        IEnumerator Download()
        {
            this.downloading = true;
            try
            {
                IProgressResult <Progress, BundleManifest> manifestResult = this.downloader.DownloadManifest(BundleSetting.ManifestFilename);

                yield return(manifestResult.WaitForDone());

                if (manifestResult.Exception != null)
                {
                    Debug.LogFormat("Downloads BundleManifest failure.Error:{0}", manifestResult.Exception);
                    yield break;
                }

                BundleManifest manifest = manifestResult.Result;

                IProgressResult <float, List <BundleInfo> > bundlesResult = this.downloader.GetDownloadList(manifest);
                yield return(bundlesResult.WaitForDone());

                List <BundleInfo> bundles = bundlesResult.Result;

                if (bundles == null || bundles.Count <= 0)
                {
                    Debug.LogFormat("Please clear cache and remove StreamingAssets,try again.");
                    yield break;
                }

                IProgressResult <Progress, bool> downloadResult = this.downloader.DownloadBundles(bundles);
                downloadResult.Callbackable().OnProgressCallback(p =>
                {
                    Debug.LogFormat("Downloading {0:F2}KB/{1:F2}KB {2:F3}KB/S", p.GetCompletedSize(UNIT.KB), p.GetTotalSize(UNIT.KB), p.GetSpeed(UNIT.KB));
                });

                yield return(downloadResult.WaitForDone());

                if (downloadResult.Exception != null)
                {
                    Debug.LogFormat("Downloads AssetBundle failure.Error:{0}", downloadResult.Exception);
                    yield break;
                }

                Debug.Log("OK");

                if (this.resources != null)
                {
                    BundleResources bundleResources = (this.resources as BundleResources);
                    bundleResources.BundleManifest = manifest;
                }

#if UNITY_EDITOR
                UnityEditor.EditorUtility.OpenWithDefaultApp(BundleUtil.GetStorableDirectory());
#endif
            }
            finally
            {
                this.downloading = false;
            }
        }
Пример #2
0
    IResources CreateResources()
    {
        IResources resources = null;

#if UNITY_EDITOR
        if (SimulationSetting.IsSimulationMode)
        {
            LogManager.Log("Use SimulationResources. Run In Editor");

            /* Create a PathInfoParser. */
            //IPathInfoParser pathInfoParser = new SimplePathInfoParser("@");
            IPathInfoParser pathInfoParser = new SimulationAutoMappingPathInfoParser();

            /* Create a BundleManager */
            IBundleManager manager = new SimulationBundleManager();

            /* Create a BundleResources */
            resources = new SimulationResources(pathInfoParser, manager);
        }
        else
#endif
        {
            /* Create a BundleManifestLoader. */
            IBundleManifestLoader manifestLoader = new BundleManifestLoader();


            /* Loads BundleManifest. */
            BundleManifest manifest;
            manifest = manifestLoader.Load(BundleUtil.GetStorableDirectory() + BundleSetting.ManifestFilename);

            //manifest.ActiveVariants = new string[] { "", "sd" };
            //manifest.ActiveVariants = new string[] { "", "hd" };

            /* Create a PathInfoParser. */
            //IPathInfoParser pathInfoParser = new SimplePathInfoParser("@");
            IPathInfoParser pathInfoParser = new AutoMappingPathInfoParser(manifest);

            /* Create a BundleLoaderBuilder */
            ILoaderBuilder builder;
            builder = new WWWComplexLoaderBuilder(new Uri(BundleUtil.GetStorableDirectory()), false);

            /* Create a BundleManager */
            IBundleManager manager = new BundleManager(manifest, builder);

            /* Create a BundleResources */
            resources = new BundleResources(pathInfoParser, manager);
        }
        return(resources);
    }
Пример #3
0
    public IEnumerator LoadGame(string name)
    {
        if (!gamesMap.ContainsKey(name))
        {
            Debug.Log("load game not found: " + name);
            yield break;
        }

#if UNITY_EDITOR
        if (SimulationSetting.IsSimulationMode)
        {
            var ret = simulator.LoadBundle(name + "lua");
            yield return(ret.WaitForDone());

            yield break;
        }
#endif

        Debug.Log("enter LoadGame " + name);

        var cfg = gamesMap[name];

        IBundleManifestLoader manifestLoader = new BundleManifestLoader();

        var path = BundleUtil.GetStorableDirectory() + name + "/";
        var mani = path + BundleSetting.ManifestFilename;

        BundleManifest  manifest       = manifestLoader.Load(mani);
        IPathInfoParser pathInfoParser = new AutoMappingPathInfoParser(manifest);
        ILoaderBuilder  builder        = new CustomBundleLoaderBuilder(new Uri(path), false);

        IBundleManager manager = new BundleManager(manifest, builder);

        var rc = new BundleResources(pathInfoParser, manager);

        cfg.resources = rc;

        var result = rc.LoadBundle(name + "lua");
        yield return(result.WaitForDone());

        cfg.luaBundle = result.Result as DefaultBundle;

        Debug.Log("leave LoadGame " + name);
    }