WaitAsync() public méthode

public WaitAsync ( long time ) : Task
time long
Résultat Task
Exemple #1
0
        public async void UpdateAsync()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                // 如果队列中消息多于4个,则加速跑帧
                this.waitTime = maxWaitTime;
                if (this.Queue.Count > 4)
                {
                    this.waitTime = maxWaitTime - (this.Queue.Count - 4) * 2;
                }
                // 最快加速一倍
                if (this.waitTime < 20)
                {
                    this.waitTime = 20;
                }

                await timerComponent.WaitAsync(waitTime);

                if (this.IsDisposed)
                {
                    return;
                }

                this.UpdateFrame();
            }
        }
Exemple #2
0
        private async void StartRecv()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                if (this.Id == 0)
                {
                    return;
                }

                byte[] messageBytes;
                try
                {
                    if (this.isRpc)
                    {
                        this.isRpc = false;
                        await timerComponent.WaitAsync(0);
                    }
                    messageBytes = await channel.Recv();
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    continue;
                }

                if (messageBytes.Length < 6)
                {
                    continue;
                }

                ushort opcode = BitConverter.ToUInt16(messageBytes, 0);

                try
                {
                    this.Run(opcode, messageBytes);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
Exemple #3
0
        public async void UpdateFrameAsync()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                if (Id == 0)
                {
                    return;
                }

                await timerComponent.WaitAsync(40);

                Broadcast(FrameMessage, unitComponent.GetAll());
                ++Frame;
                FrameMessage = new FrameMessage()
                {
                    Frame = Frame
                };
            }
        }
Exemple #4
0
        public override async void Start(UILoadingComponent self)
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

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

                if (self.IsDisposed)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }
                self.text.text = $"{bundleDownloaderComponent.Progress}%";
            }
        }
Exemple #5
0
        public async void Start()
        {
            UILoadingComponent self = this.Get();

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

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

                if (self.Id == 0)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }
                self.text.text = $"{bundleDownloaderComponent.Progress}%";
            }
        }
        public async Task DownloadAndCacheAsync(string uri, string assetBundleName)
        {
            assetBundleName = (assetBundleName + ".unity3d").ToLower();

            AssetBundle assetBundle;
            // 异步下载资源
            string         url            = uri + "StreamingAssets/" + assetBundleName;
            int            count          = 0;
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                using (WWWAsync wwwAsync = new WWWAsync())
                {
                    try
                    {
                        ++count;
                        if (count > 1)
                        {
                            await timerComponent.WaitAsync(1000);
                        }

                        if (this.Id == 0)
                        {
                            return;
                        }

                        await wwwAsync.LoadFromCacheOrDownload(url, ResourcesComponent.AssetBundleManifestObject.GetAssetBundleHash(assetBundleName));

                        assetBundle = wwwAsync.www.assetBundle;

                        break;
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                    }
                }
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetBundleLoaderAsync assetBundleLoaderAsync = new AssetBundleLoaderAsync(assetBundle))
                {
                    assets = await assetBundleLoaderAsync.LoadAllAssetsAsync();
                }


                foreach (UnityEngine.Object asset in assets)
                {
                    string path = $"{assetBundleName}/{asset.name}".ToLower();
                    this.resourceCache[path] = asset;
                }
            }

            if (this.bundleCaches.ContainsKey(assetBundleName))
            {
                throw new Exception($"重复加载资源: {assetBundleName}");
            }
            this.bundleCaches[assetBundleName] = assetBundle;
        }