public static UniTask <T> .Awaiter GetAwaiter <T> (this UniTask <T>?task) => task?.GetAwaiter() ?? UniTask.FromResult <T>(default).GetAwaiter();
/// <summary> /// 뷰 오픈. /// </summary> protected override async UniTask OnPush(object pushValue = null) { await UniTask.WhenAll(_registedPopupStack.Select(x => x.Push(pushValue))); await base.OnPush(pushValue); }
protected override async UniTask OnBackground() { await UniTask.Run(() => _registedPopupStack.Select(x => x.ToBackground())); await base.OnBackground(); }
/// <summary> /// Returns the result of the given <paramref name="onSuccess"/> function if the calling Result is a success. Otherwise, it returns the result of the given <paramref name="onFailure"/> function. /// </summary> public static async UniTask <T> Match <T>(this UniTask <Result> resultUniTask, Func <T> onSuccess, Func <string, T> onFailure) { return((await resultUniTask).Match(onSuccess, onFailure)); }
/// <summary> /// Invokes the given <paramref name="onSuccess"/> action if the calling Result is a success. Otherwise, it invokes the given <paramref name="onFailure"/> action. /// </summary> public static async UniTask Match(this UniTask <Result> resultUniTask, Action onSuccess, Action <string> onFailure) { (await resultUniTask).Match(onSuccess, onFailure); }
async Task DelayTransition() { await UniTask.Delay(TimeSpan.FromSeconds(3)); uiStack.DoTransition(_toGreenPanel, Color.green); }
private async void Start() { provider.OnInitialized.Subscribe(_ => _gameStateObservable.Value = GameState.Tutorial).AddTo(gameObject); await UniTask.Yield(); _gameStateObservable.Subscribe(async state => { switch (state) { case GameState.None: await UniTask.WaitUntil(() => tutrialController.ProgressObservable.Value > -1); _gameStateObservable.Value = GameState.Initialize; break; case GameState.Tutorial: tutrialController.ProgressObservable.Value = 2; await UniTask.WaitUntil(() => Input.GetMouseButtonDown(0)); bgm.Play(); Player = Instantiate(playerPrefab); Player.Initialize(provider); var cursorPosition = Input.mousePosition; cursorPosition -= Vector3.forward * Camera.main.transform.position.z; Player.transform.position = Camera.main.ScreenToWorldPoint(cursorPosition) - Vector3.down; tutrialController.ProgressObservable.Value = 3; _gameStateObservable.Value = GameState.InGame; break; case GameState.InGame: provider.people.ObserveRemove().First().Delay(System.TimeSpan.FromSeconds(1.5f)).Subscribe(_ => tutrialController.ProgressObservable.Value = 4).AddTo(gameObject); Player.Hp.Skip(1).Where(x => x < Player.weakedHp).First().Subscribe(_ => { tutrialController.ProgressObservable.Value = 5; }).AddTo(gameObject); Player.DiedAsync.Subscribe(_ => { tutrialController.ProgressObservable.Value = 6; foreach (var person in provider.people) { if (person.isFriendly) { person.isCatastorophy.Value = true; } } _gameStateObservable.Value = GameState.Result; }).AddTo(gameObject); break; case GameState.Result: await UniTask.WaitUntil(() => Input.GetMouseButtonDown(0)); tutrialController.End(); await UniTask.WaitUntil(() => Input.GetMouseButtonDown(0)); UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); break; } }).AddTo(gameObject); dialog.ObserveEveryValueChanged(d => d.alpha > 0) .Subscribe(x => { if (x) { bgm.Pause(); Time.timeScale = 0.0f; button.OnClickAsObservable() .Subscribe(_ => { Time.timeScale = 1.0f; }).AddTo(gameObject); } else { bgm.UnPause(); } provider.OnPause.Value = x; }).AddTo(gameObject); }
public async override void OnInvalidResult() { await UniTask.SwitchToMainThread(); UpdateList(new string[0]); }
public override async UniTask ExecuteAsync(CancellationToken cancellationToken = default) { var managers = Engine.GetAllServices <IActorManager>(); await UniTask.WhenAll(managers.SelectMany(m => m.GetAllActors()).Select(a => a.ChangeVisibilityAsync(false, Duration, cancellationToken: cancellationToken))); }
// Start()メソッドをUniTaskVoidにしても問題なく動く private async UniTaskVoid Start() { await UniTask.Delay(TimeSpan.FromSeconds(10)); Destroy(gameObject); }
void Start() { //スロット回転タスク UniTask <SlotResult> slotTask = UniTask.FromResult <SlotResult>(default);
public override async UniTask ExecuteAsync(CancellationToken cancellationToken = default) { var printer = await GetOrAddPrinterAsync(); if (cancellationToken.CancelASAP) { return; } var metadata = PrinterManager.Configuration.GetMetadataOrDefault(printer.Id); if (!printer.Visible) { ShowPrinterAsync(printer, metadata, cancellationToken).Forget(); } if (Assigned(DefaultPrinter) && DefaultPrinter.Value || !Assigned(DefaultPrinter) && metadata.AutoDefault) { SetDefaultPrinter(printer, cancellationToken); } if (metadata.StopVoice) { AudioManager.StopVoice(); } if (ShouldPlayAutoVoice) { await PlayAutoVoiceAsync(printer, cancellationToken); } if (cancellationToken.CancelASAP) { return; } var resetText = Assigned(ResetPrinter) && ResetPrinter.Value || !Assigned(ResetPrinter) && metadata.AutoReset; if (resetText) { ResetText(printer); } // Evaluate whether to append before printing to account prior printer state. var appendBacklog = !metadata.SplitBacklogMessages && !resetText && !string.IsNullOrEmpty(printer.Text) && AssignedAuthorId == printer.AuthorId; if (Assigned(LineBreaks) && LineBreaks > 0 || !Assigned(LineBreaks) && metadata.AutoLineBreak > 0 && !string.IsNullOrWhiteSpace(printer.Text)) { await AppendLineBreakAsync(printer, metadata, cancellationToken); } if (cancellationToken.CancelASAP) { return; } var printedText = Text.Value; // Copy to a temp var to prevent multiple evaluations of dynamic values. if (string.IsNullOrEmpty(printedText)) { return; } await PrintTextAsync(printedText, printer, cancellationToken); if (cancellationToken.CancelASAP) { return; } if (metadata.PrintFrameDelay > 0) // Wait at least one frame to make the printed text visible while in skip mode. { await UniTask.DelayFrame(metadata.PrintFrameDelay); } if (cancellationToken.CancelASAP) { return; } if (!Assigned(WaitForInput) && metadata.AutoWait || Assigned(WaitForInput) && WaitForInput.Value) { await WaitForInputAsync(printedText, cancellationToken); } if (cancellationToken.CancelASAP) { return; } if (metadata.AddToBacklog) { AddBacklog(printedText, appendBacklog); } }
public static bool IsCompleted <T> (this UniTask <T> task) => task.Status.IsCompleted();
public static bool IsCompleted(this UniTask task) => task.IsCompleted;
public IEnumerator UnitySetUp() => UniTask.ToCoroutine(async() => { Console.WriteLine($"[MirageTest] UnitySetUp class:{TestContext.CurrentContext.Test.ClassName} method:{TestContext.CurrentContext.Test.MethodName} "); serverGo = new GameObject("server", typeof(ServerObjectManager), typeof(NetworkServer)); clientGo = new GameObject("client", typeof(ClientObjectManager), typeof(NetworkClient)); socketFactory = serverGo.AddComponent <TestSocketFactory>(); server = serverGo.GetComponent <NetworkServer>(); client = clientGo.GetComponent <NetworkClient>(); if (ServerConfig != null) { server.PeerConfig = ServerConfig; } if (ClientConfig != null) { client.PeerConfig = ClientConfig; } server.SocketFactory = socketFactory; client.SocketFactory = socketFactory; serverObjectManager = serverGo.GetComponent <ServerObjectManager>(); serverObjectManager.Server = server; clientObjectManager = clientGo.GetComponent <ClientObjectManager>(); clientObjectManager.Client = client; ExtraSetup(); // wait 2 frames for start to be called await UniTask.DelayFrame(2); // create and register a prefab playerPrefab = new GameObject("player (unspawned)", typeof(NetworkIdentity), typeof(T)); // DontDestroyOnLoad so that "prefab" wont be destroyed by scene loading // also means that NetworkScenePostProcess will skip this unspawned object Object.DontDestroyOnLoad(playerPrefab); var identity = playerPrefab.GetComponent <NetworkIdentity>(); identity.PrefabHash = Guid.NewGuid().GetHashCode(); clientObjectManager.RegisterPrefab(identity); // wait for client and server to initialize themselves await UniTask.Delay(1); // start the server var started = new UniTaskCompletionSource(); server.Started.AddListener(() => started.TrySetResult()); server.StartServer(); await started.Task; if (AutoConnectClient) { // now start the client client.Connect("localhost"); await AsyncUtil.WaitUntilWithTimeout(() => server.Players.Count > 0); // get the connections so that we can spawn players serverPlayer = server.Players.First(); clientPlayer = client.Player; // create a player object in the server serverPlayerGO = Object.Instantiate(playerPrefab); serverPlayerGO.name = "player (server)"; serverIdentity = serverPlayerGO.GetComponent <NetworkIdentity>(); serverComponent = serverPlayerGO.GetComponent <T>(); serverObjectManager.AddCharacter(serverPlayer, serverPlayerGO); // wait for client to spawn it await AsyncUtil.WaitUntilWithTimeout(() => clientPlayer.HasCharacter); clientIdentity = clientPlayer.Identity; clientPlayerGO = clientIdentity.gameObject; clientPlayerGO.name = "player (client)"; clientComponent = clientPlayerGO.GetComponent <T>(); } await LateSetup(); });
// will fail. //[UnityTest] //public IEnumerator WhenAllT05_Generics1() => UniTask.ToCoroutine(async () => //{ // var t01 = Tes<MyGenerics<int>>(); // var t02 = Tes<MyGenerics<int>>(); // var t03 = Tes<MyGenerics<int>>(); // var t04 = Tes<MyGenerics<int>>(); // var t05 = Tes<MyGenerics<int>>(); // await UniTask.WhenAll(t01, t02, t03, t04, t05); //}); //[UnityTest] //public IEnumerator WhenAllT06_Generics1() => UniTask.ToCoroutine(async () => //{ // var t01 = Tes<MyGenerics<int>>(); // var t02 = Tes<MyGenerics<int>>(); // var t03 = Tes<MyGenerics<int>>(); // var t04 = Tes<MyGenerics<int>>(); // var t05 = Tes<MyGenerics<int>>(); // var t06 = Tes<MyGenerics<int>>(); // await UniTask.WhenAll(t01, t02, t03, t04, t05, t06); //}); //[UnityTest] //public IEnumerator WhenAllT07_Generics1() => UniTask.ToCoroutine(async () => //{ // var t01 = Tes<MyGenerics<int>>(); // var t02 = Tes<MyGenerics<int>>(); // var t03 = Tes<MyGenerics<int>>(); // var t04 = Tes<MyGenerics<int>>(); // var t05 = Tes<MyGenerics<int>>(); // var t06 = Tes<MyGenerics<int>>(); // var t07 = Tes<MyGenerics<int>>(); // await UniTask.WhenAll(t01, t02, t03, t04, t05, t06, t07); //}); //[UnityTest] //public IEnumerator WhenAllT15_Generics1() => UniTask.ToCoroutine(async () => //{ // var t01 = Tes<MyGenerics<int>>(); // var t02 = Tes<MyGenerics<int>>(); // var t03 = Tes<MyGenerics<int>>(); // var t04 = Tes<MyGenerics<int>>(); // var t05 = Tes<MyGenerics<int>>(); // var t06 = Tes<MyGenerics<int>>(); // var t07 = Tes<MyGenerics<int>>(); // var t08 = Tes<MyGenerics<int>>(); // var t09 = Tes<MyGenerics<int>>(); // var t10 = Tes<MyGenerics<int>>(); // var t11 = Tes<MyGenerics<int>>(); // var t12 = Tes<MyGenerics<int>>(); // var t13 = Tes<MyGenerics<int>>(); // var t14 = Tes<MyGenerics<int>>(); // var t15 = Tes<MyGenerics<int>>(); // await UniTask.WhenAll(t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15); //}); async UniTask <T> Tes <T>() { await UniTask.Yield(); return(default);
async public override UniTask TurnBehaviourAsync() { await UniTask.WaitUntil(() => bEnd); }
public IEnumerator WhenAllT01_Generics1() => UniTask.ToCoroutine(async() => { var t01 = Tes <MyGenerics <int> >(); await UniTask.WhenAll(t01); });
//---------------------------------------------------------------------- // private //---------------------------------------------------------------------- async UniTask LoadSceneWithFade( ISceneContext nextSceneContext, string nextSceneName, bool useCustomTransition, float fadeOutTime = 0.3f, float fadeInTime = 0.3f ) { if (isInTransition) { AltoLog.FW_Warn($"[SceneDirector] Now in transition - {nextSceneName} is dismissed."); return; } isInTransition = true; //----- 暗転と後片付け if (useCustomTransition && currentSceneContext != null) { await currentSceneContext.CustomFadeOut(); } else { await _screenFader.FadeOut(fadeOutTime); } sceneLoading?.Invoke(); DestroyAllObjectsInScene(); if (currentSceneContext != null) { await currentSceneContext.Finalize(); currentSceneContext.CancelTokenSource.Cancel(); } SetIsSceneReady(false); currentSceneContext = nextSceneContext; // 次のシーンに必要なリソースをロード、不要なものはアンロード await LoadAndUnloadResources(nextSceneContext); //----- 次のシーンの読み込み AltoLog.FW("[SceneDirector] - Init <b>Before</b> Load Scene"); if (nextSceneContext != null) { await nextSceneContext.InitBeforeLoadScene(); } await SceneManager.LoadSceneAsync(nextSceneName); DisableLocalAudioListener(); AltoLog.FW("[SceneDirector] - Init <b>After</b> Load Scene"); if (currentSceneContext != null) { await currentSceneContext.InitAfterLoadScene(); } SetIsSceneReady(true); sceneLoaded?.Invoke(); // シーンの 1 フレーム目は重くなるので 1 フレーム待ってからフェードイン await UniTask.DelayFrame(1); if (useCustomTransition && currentSceneContext != null) { await currentSceneContext.CustomFadeIn(); } else { await _screenFader.FadeIn(fadeInTime); } isInTransition = false; currentSceneContext?.OnStartupScene(); }
public IEnumerator AsyncAsTicks() => UniTask.ToCoroutine(async() => { var db = new SQLiteAsyncConnection(TestPath.GetTempFileName()); await TestAsyncDateTimeOffset(db); });
/// <summary> /// Returns the result of the given <paramref name="onSuccess"/> function if the calling Result is a success. Otherwise, it returns the result of the given <paramref name="onFailure"/> function. /// </summary> public static async UniTask <K> Match <T, K, E>(this UniTask <Result <T, E> > resultUniTask, Func <T, K> onSuccess, Func <E, K> onFailure) { return((await resultUniTask).Match(onSuccess, onFailure)); }
public async Task Sum(int start, int count) { { var xs = await UniTaskAsyncEnumerable.Range(start, count).SumAsync(); var ys = Enumerable.Range(start, count).Sum(); xs.Should().Be(ys); } { var xs = await UniTaskAsyncEnumerable.Range(start, count).SumAsync(x => x * 2); var ys = Enumerable.Range(start, count).Sum(x => x * 2); xs.Should().Be(ys); } { var xs = await UniTaskAsyncEnumerable.Range(start, count).SumAwaitAsync(x => UniTask.Run(() => x)); var ys = Enumerable.Range(start, count).Sum(x => x); xs.Should().Be(ys); } { var xs = await UniTaskAsyncEnumerable.Range(start, count).SumAwaitWithCancellationAsync((x, _) => UniTask.Run(() => x)); var ys = Enumerable.Range(start, count).Sum(x => x); xs.Should().Be(ys); } }
/// <summary> /// Invokes the given <paramref name="onSuccess"/> action if the calling Result is a success. Otherwise, it invokes the given <paramref name="onFailure"/> action. /// </summary> public static async UniTask Match <T, E>(this UniTask <Result <T, E> > resultUniTask, Action <T> onSuccess, Action <E> onFailure) { (await resultUniTask).Match(onSuccess, onFailure); }
public UniTask <Texture2D> ConvertAsync(byte[] obj, string name) => UniTask.FromResult(Convert(obj, name));
private async UniTask DestroyAtWaitForFrame() { await UniTask.DelayFrame(1); Destroy(gameObject); }
public static async UniTask loadScenesAsync(IEnumerable <SceneReference> scenes) => await UniTask.WhenAll(scenes.Select(loadSceneAsync));
protected override async UniTask Popped() { await UniTask.Run(() => _registedPopupStack.Select(x => x.Pop())); await base.Popped(); }
public UniTask FadeOut(float fadeOutDutation) { Play(default(Music), fadeOutDutation); return(UniTask.WaitWhile(() => fadingOut)); }
public IEnumerator ClientNotNullAfterSpawnInStarted() => UniTask.ToCoroutine(async () => { await AsyncUtil.WaitUntilWithTimeout(() => testIdentity.Client == client); });
public override async UniTask BeforeInitializeScene() { await UniTask.DelayFrame(10); }