コード例 #1
0
ファイル: CoroutineTest.cs プロジェクト: ngtrhieu/unitythread
        public IEnumerator CoroutineExecutedNextUpdate()
        {
            UnityThread.ExecuteCoroutine(ACoroutine());

            // Runner is spawned
            var runner = GameObject.Find("UnityThreadRunner");

            Assert.NotNull(runner);

            // Counter not yet modified
            Assert.AreEqual(0, counter);

            yield return(null);

            // 0.3 sec has not passed, counter should not been increased
            Assert.AreEqual(0, counter);

            yield return(new WaitForSeconds(0.3f));

            Assert.AreEqual(1, counter);
            yield return(new WaitForSeconds(0.4f));

            Assert.AreEqual(2, counter);
            yield return(new WaitForSeconds(0.6f));

            Assert.AreEqual(4, counter);
            yield return(new WaitForSeconds(1f));

            Assert.AreEqual(5, counter);
        }
コード例 #2
0
        private void AddListenerToImproveButton(WarshipDto warshipDto)
        {
            var button = warshipsUiStorage.modalWindowImproveButton.GetComponent <Button>();

            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() =>
            {
                UnityThread.ExecuteCoroutine(Coroutine());
            });

            IEnumerator Coroutine()
            {
                //Отправить запрос
                var downloader = new WarshipImprovementDownloader().TryBuy(warshipDto.Id);

                yield return(new WaitUntil(() => downloader.IsCompleted));

                bool success = downloader.Result;

                if (success)
                {
                    UiSoundsManager.Instance().PlayLevelUp();
                    //Показать анимацию получения нового уровня
                    log.Info("Успешное получение уровня");
                    //Перезагрузить сцену
                    lobbySceneSwitcher.ReloadScene();
                    var newLobbyEcs = Object.FindObjectOfType <LobbyEcsController>();
                    yield return(new WaitUntil(() => newLobbyEcs.IsWarshipsCreationCompleted()));

                    yield return(new WaitUntil(() => newLobbyEcs.IsSoftCurrencyReady()));

                    //Показать текущее меню
                    newLobbyEcs.ShowWarshipList();

                    newLobbyEcs.ShowWarshipOverviewById(warshipDto.Id);
                }
                else
                {
                    UiSoundsManager.Instance().PlayError();
                    //Показать уведомление, что ресурсов недостаточно
                    log.Error("Не удалось получить новый уровень");
                }
            }
        }
コード例 #3
0
        public void Evaluate(IList <NeatGenome> genomeList)
        {
            var boxes = new IBlackBox[genomeList.Count];

            for (int i = 0; i < genomeList.Count; i++)
            {
                boxes[i] = _decoder.Decode(genomeList[i]);
            }
            _fitnesses = null;

            if (_evaluationCount > 0)
            {
                UnityThread.ExecuteCoroutine(EvaluateInMainThread(boxes));
                Debug.Log($"Evaluation requested in {Thread.CurrentThread.ManagedThreadId} thread");

                while (_fitnesses == null)
                {
                    Thread.Sleep(10);
                }
                Debug.Assert(genomeList.Count == _fitnesses.Length);
                for (int i = 0; i < _fitnesses.Length; i++)
                {
                    genomeList[i].EvaluationInfo.SetFitness(_fitnesses[i]);
                }
                Debug.Log("Evaluation finished");
            }
            else
            {
                Debug.Log("Evaluator initialized");
                foreach (var item in genomeList)
                {
                    item.EvaluationInfo.SetFitness(0);
                }
            }
            _evaluationCount += 1;
        }
コード例 #4
0
 protected override void Execute(List <LobbyUiEntity> entities)
 {
     EnableShopLayer();
     UnityThread.ExecuteCoroutine(SetStoreContentWidth());
     lobbyLayoutSwitcher.SetCurrentLayer(ShittyUiLayerState.ShopLayer);
 }
コード例 #5
0
 protected override void Execute(List <LobbyUiEntity> entities)
 {
     EnableWarshipsLayer();
     lobbyLayoutSwitcher.SetCurrentLayer(ShittyUiLayerState.WarshipsList);
     UnityThread.ExecuteCoroutine(SetWarshipsListContentHeight());
 }
コード例 #6
0
 ///<summary>
 ///Dispatch a Coroutine-based AsyncAction. Return the same action back.
 ///</summary>
 public static CoroutineAction <TState> Dispatch <TState>(this IStore <TState> store, CoroutineAction <TState> action)
 {
     UnityThread.ExecuteCoroutine(action(store));
     return(action);
 }