Beispiel #1
0
        public static async ETTask DownloadBundle(string url)
        {
            if (Define.IsAsync)
            {
                try
                {
                    using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>())
                    {
                        await bundleDownloaderComponent.StartAsync(url);

                        Game.EventSystem.Publish(new EventType.LoadingBegin()
                        {
                            Scene = Game.Scene
                        });

                        await bundleDownloaderComponent.DownloadAsync(url);
                    }

                    Game.EventSystem.Publish(new EventType.LoadingFinish());

                    Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets");
                    ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest");
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
        }
        public async ETVoid StartAsync(UILoadingComponent self)
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
            long           instanceId     = self.InstanceId;

            while (true)
            {
                await timerComponent.WaitAsync(1000);

                if (self.InstanceId != instanceId)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }
                self.text.text = $"{bundleDownloaderComponent.Progress}%";
            }
        }