public void ToggleFollow() { UniTask.Create(async() => { await Controller.I.SendAsync("ToggleFollow", Id); switch (FullUserInfo.Friendship) { case (int)FriendShip.Friend: FullUserInfo.Friendship = (int)FriendShip.Following; Repository.I.PersonalFullInfo.Followings .RemoveAll(i => i.Id == Id); break; case (int)FriendShip.Follower: FullUserInfo.Friendship = (int)FriendShip.None; Repository.I.PersonalFullInfo.Followings .RemoveAll(i => i.Id == Id); break; case (int)FriendShip.Following: FullUserInfo.Friendship = (int)FriendShip.Friend; Repository.I.PersonalFullInfo.Followings.Add(FullUserInfo); break; case (int)FriendShip.None: FullUserInfo.Friendship = (int)FriendShip.Follower; Repository.I.PersonalFullInfo.Followings.Add(FullUserInfo); break; } UpdateFriendShipView(); }); }
public IEnumerator 非同期送受信テスト_GlobalMessagePipe() { // GlobalMessagePipeを使用する前にSetProviderに設定する必要がある GlobalMessagePipe.SetProvider(_container.AsServiceProvider()); // 非同期用のPublisher/Subscriberを生成する var asyncSubscriber = GlobalMessagePipe.GetAsyncSubscriber <MyEvent>(); var asyncPublisher = GlobalMessagePipe.GetAsyncPublisher <MyEvent>(); var cts = new CancellationTokenSource(); var task1 = UniTask.Create(async() => { Debug.Log("イベント受信"); // イベントを受ける方 var ev = await asyncSubscriber.FirstAsync(cts.Token); Debug.Log($"イベント受信完了 : {ev.Message}"); }); var task2 = UniTask.Create(async() => { Debug.Log("イベント送信"); // イベントを投げる方 await asyncPublisher.PublishAsync(new MyEvent { Message = "イベント" }, cts.Token); Debug.Log("イベント送信完了"); }); return(UniTask.ToCoroutine(async() => await UniTask.WhenAll(task1, task2))); }
/// <summary> /// objeyi kaydetmeye yarar /// </summary> /// <typeparam name="T">Objenin türünü giriniz</typeparam> /// <param name="path">objenin save edileceği yer örn: meshler/</param> /// <param name="name">örn: /objeler.json</param> /// <param name="obj">struct , class yaparken zorunlu olay [system.serializable] eklemek </param> public async static UniTask SaveListAsync <T>(string path, string name, List <T> obj) { var tasks = new List <UniTask>(); if (Directory.Exists(SavesFolder + path)) { Directory.Delete(SavesFolder + path, true); } CheckPath(path); for (int i = 0; i < obj.Count; i++) { tasks.Add(UniTask.Create(async() => { await UniTask.Yield(); string konum = Path.Combine(SavesFolder + path + i.ToString() + name); string saveText = JsonUtility.ToJson(obj[i], true); File.WriteAllText(konum, saveText); })); } await UniTask.WhenAll(tasks); }
/// <summary> /// objeyi yüklemeye yarar /// </summary> /// <typeparam name="T">Objenin türünü giriniz</typeparam> /// <param name="path">objenin Load edileceği yer örn: meshler</param> /// <param name="name">örn: /objeler.json ve .json zorunlu</param> public async static UniTask <T[]> LoadArrayAsync <T>(string path, string name) { CheckPath(path); DirectoryInfo directoryInfo = new DirectoryInfo(SavesFolder + path); int count = directoryInfo.GetFiles().Length; T[] objectToLoad = new T[count]; var tasks = new List <UniTask>(); for (int i = 0; i < count; i++) { tasks.Add(UniTask.Create(async() => { await UniTask.Yield(); string konum = Path.Combine(SavesFolder + path + i.ToString() + name); if (File.Exists(konum)) { string loadText = File.ReadAllText(konum); objectToLoad[i] = JsonUtility.FromJson <T>(loadText); Debug2.Log(loadText); } })); } await UniTask.WhenAll(tasks); return(objectToLoad); }
public IEnumerator 非同期送受信テスト() { var task1 = UniTask.Create(async() => { bool isFinished = false; Debug.Log("イベント受信"); // イベントを受ける方 var subscriber = _container.Instantiate <Subscriber>(); subscriber .SubscribeAsync(() => { // 終わったらフラグをtrueにして終了させる isFinished = true; }); return(UniTask.WaitUntil(() => isFinished)); }); var task2 = UniTask.Create(async() => { Debug.Log("イベント送信"); // イベントを投げる方 var publisher = _container.Instantiate <Publisher>(); await publisher.SendAsync(new MyEvent { Message = "イベント" }); }); return(UniTask.ToCoroutine(async() => await UniTask.WhenAll(task1, task2))); }
public MinUserInfo() { UniTask.Create(async() => { await UniTask.DelayFrame(1); //to get data from object inititalizer >> {abdc = value} DownloadPicture().Forget(); }); }
public static void RunFramesLater(int n, Action action) => UniTask.Create(async() => { for (var i = 0; i < n; i++) { await UniTask.WaitForEndOfFrame(); } action(); });
public void ToggleOpenMatches() { UniTask.Create(async() => { await Controller.I.SendAsync("ToggleOpenMatches"); FullUserInfo.EnableOpenMatches = !FullUserInfo.EnableOpenMatches; UpdateOpenMatchesView(); }); }
public static void Show(MinUserInfo senderInfo) { UniTask.Create(async() => { var panel = (await Addressables.InstantiateAsync("challengeResponsePanel", LobbyReferences.I.Canvas)).GetComponent <ChallengeResponsePanel>(); panel.minUserView.Init(senderInfo); }); }
public void Respond(int response) { UniTask.Create(async() => { var res = await Controller.I.InvokeAsync <ChallengeResponseResult>( "RespondChallengeRequest", minUserView.MinUserInfo.Id, response == 0); Toast.I.Show(res.ToString()); Destroy(gameObject); }); }
public override async UniTask ProcessAsyncTask() { if (task_action == null) { return; } await UniTask.Create(task_action).AttachExternalCancellation(GetToken()); on_finished?.Invoke(false); is_completed = true; }
public void Start() { // 120フレーム間前進したらDestroyする DestroyAsync(UniTask.Create(async() => { // 120フレームの間前進する for (int i = 0; i < 120; i++) { transform.position += Vector3.forward * Time.deltaTime; await UniTask.Yield(); } })).Forget(); }
public void Distribute(List <int> cardIds) { UniTask.Create(async() => { foreach (var cardId in cardIds) { var card = await Card.CreateGroundCard(cardId, transform); card.transform.eulerAngles = Vector3.up * 180; Cards.Add(card); } DistributeAnim(DOTween.Sequence()); }); }
public async Task Cancel() { CancellationTokenSource cts = new CancellationTokenSource(); var t = UniTask.Create(async() => { await Task.Delay(TimeSpan.FromSeconds(1)); return(10); }).WithCancellation(cts.Token); cts.Cancel(); (await Assert.ThrowsAsync <OperationCanceledException>(async() => await t)).CancellationToken.Should().Be(cts.Token); }
public void RestartGame() { UniTask.Create(async() => { try { await hubConnection.CloseAsync(); } catch (Exception e) { Debug.Log(e); } await SceneManager.LoadSceneAsync(0); }).Forget(e => throw e); }
private void SetGo() { connectingText.enabled = true; try{ UniTask.Create(async() => { await firebaseUpdateBoard.SetGo(boardController.LastUpdate); boardController.boardUpdated -= SyncBoard; //相手のボード更新時に呼び出せれないようにする }).Forget(); } catch { connectFailedPanel.SetActive(true); } finally{ connectingText.enabled = false; } }
public static void Show(FullUserInfo fullUserInfo) { UniTask.Create(async() => { var key = (fullUserInfo is PersonalFullUserInfo) ? "personalFuv" : "fullUserView"; if (!activeInstance) { activeInstance = await Create(key); } else if (activeInstance.FullUserInfo.GetType() != fullUserInfo.GetType()) { activeInstance.Destroy(); activeInstance = await Create(key); } activeInstance.Init(fullUserInfo); }); }
/// <summary> /// Load scene asynchronously. /// </summary> /// <param name="sceneName">Name of scene to load.</param> /// <param name="canActivate">Callback to know when to activate scene when given a load percentage.</param> /// <param name="cleanupAction">Cleanup previous scene</param> public static async UniTask LoadAsync(string sceneName, Func <float, bool> canActivate = null, Func <UniTask> cleanupAction = null) { var prevSceneName = SceneManager.GetActiveScene().name; if (prevSceneName == sceneName) { Debug.Log($"{sceneName} already loaded."); return; } if (canActivate == null) { // load scene as is by default. await SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive); } else { var loadOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive); loadOperation.allowSceneActivation = false; while (loadOperation.progress < 0.85f || !canActivate(loadOperation.progress)) { // wait until both scene is mostly loaded and can activate. await Delay.NextFrame(); } loadOperation.allowSceneActivation = true; while (!loadOperation.isDone) { // wait until scene is entirely loaded. await Delay.NextFrame(); } } if (cleanupAction != null) { await UniTask.Create(cleanupAction); } await SceneManager.UnloadSceneAsync(prevSceneName); }
/// <summary> /// objeyi yüklemeye yarar /// </summary> /// <typeparam name="T">Objenin türünü giriniz</typeparam> /// <param name="path">objenin Load edileceği yer örn: meshler</param> /// <param name="name">örn: /objeler.json ve .json zorunlu</param> public async static UniTask <T> LoadAsync <T>(string path, string name) { T objectToLoad = default; var task = UniTask.Create(async() => { await UniTask.Yield(); CheckPath(path); string konum = Path.Combine(SavesFolder + path + name); if (File.Exists(konum)) { string loadText = File.ReadAllText(konum); objectToLoad = JsonUtility.FromJson <T>(loadText); } }); await UniTask.WhenAll(task); return(objectToLoad); }
private void Awake() { _eventManager.Add <Utility.SaveData.EventSaveCall>(this, ev => { // PlayerModelを保存する _saveDataHelper.Save("Chara/Player.save", "Player", _player.gameObject); }); _eventManager.Add <Utility.SaveData.EventLoadCall>(this, ev => { ev.Add(UniTask.Create((async() => { /* * // PlayerModel情報 * if (_saveDataHelper.Exists("Chara/Player.save", "Player")) * { * _saveDataHelper.Load("Chara/Player.save", "Player"); * }*/ }))); }); }
public IEnumerator 非同期送信テスト() { Debug.Log("イベント受信"); // イベントを受ける方 var subscriber = _container.Instantiate <Subscriber>(); subscriber.Subscribe(); var task2 = UniTask.Create(async() => { Debug.Log("イベント送信"); // イベントを投げる方 var publisher = _container.Instantiate <Publisher>(); await publisher.SendAsync(new MyEvent { Message = "イベント" }); }); return(UniTask.ToCoroutine(async() => await UniTask.WhenAll(task2))); }
public static void Create(PlayerInfo player, bool joining) { if (player.IsLocalPlayer) { return; } if (joining) { if (PlayerTransformSync.LocalInstance == null || player.PlayerId < QSBPlayerManager.LocalPlayerId) { // player was here before we joined return; } } else { if (!player.Visible) { return; } } var go = new GameObject($"player {player.PlayerId} JoinLeaveSingularity"); var ct = go.GetCancellationTokenOnDestroy(); UniTask.Create(async() => { DebugLog.DebugWrite($"{go.name}: WARP TASK"); await go.name.Try("running warp task", () => Run(go.transform, player, joining, ct)); Object.Destroy(go); DebugLog.DebugWrite($"{go.name}: WARP TASK DONE"); }); }
public void FinalizeRoom(FinalizeResult finalizeResult) { UniTask.Create(async() => { //wait for the last throw operation, this can be done better await UniTask.Delay(1200); await CoreGameplay.I.EatLast(finalizeResult.LastEaterTurnId); // FinalizeController.I. // DestroyModuleGroup(); // _finalizeFactory.Create(finalizeResult, _roomSettings); RoomUserView.Manager.I.RoomUserViews.ForEach(ruv => Object.Destroy(ruv.gameObject)); Object.FindObjectsOfType <PlayerBase>().ForEach(obj => Object.Destroy(obj.gameObject)); Object.Destroy(Object.FindObjectOfType <ChatSystem>().gameObject); Object.Destroy(PrizeView.I.gameObject); //immmm this will cause issues on the running funs like decreaseMoneyAimTime and events //change indie values instead of rewrite the whole object finalizeResult.PersonalFullUserInfo.Followers = Repository.I.PersonalFullInfo.Followers; finalizeResult.PersonalFullUserInfo.Followings = Repository.I.PersonalFullInfo.Followings; Repository.I.PersonalFullInfo = finalizeResult.PersonalFullUserInfo; Repository.I.PersonalFullInfo.DecreaseMoneyAimTimeLeft().Forget(); //todo you MUST edit each value on it's own now?, this is about replacing the whole //data object, but it seems fine FinalizeController.Construct(RoomReferences.I.Canvas, RoomSettings.I, finalizeResult) .Forget(); }); }
public static void RunNextFrame(Action action) => UniTask.Create(async() => { await UniTask.WaitForEndOfFrame(); action(); });
public override void OnServerAuthenticate(INetworkConnection conn) { conn.RegisterHandler <PasswordMessage>(PasswordMessageHandler); UniTask.Create(() => DisconnectLate(conn, 10f)); }
public static void RunWhen(Func <bool> predicate, Action action) => UniTask.Create(async() => { await UniTask.WaitUntil(predicate); action(); });