private void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused) { Rect labelRect = new Rect(rect.x, rect.y, rect.xMax - 45f, 15f); Rect plusRect = new Rect(rect.xMax - 8f - 25f, rect.y, 25f, 13f); string str = _fileList[index].Title; GUI.Label(labelRect, str); if (GUI.Button(plusRect, iconToolbarPlus, preButton)) { UnityTask.Run(async() => { try { bool res = await CloudFileWatcher.DownloadFileAsync(SettingsDrawer.UserID, _fileList[index]); if (!res) { Debug.LogWarning($"Could not download the file [{_fileList[index].Title}]"); } } catch (Exception e) { Debug.LogError("Exception thrown while downloading the file: " + e.Message + "\nInner Message: " + e.InnerException?.Message); } }); } if (index + 1 < _list.count) { DrawingHelper.Separator(new Rect(labelRect.x, labelRect.y + EditorGUIUtility.singleLineHeight + 1.5f, rect.width, 1.2f)); } }
public void CreateAndRun() { UnityTask.Run(() => { var result = FindPrimeNumber(1000); }); }
public UnityTask <List <CharacterResult> > GetUserCharacters(bool forceUpdate = false) { if (forceUpdate) { this.characterCache = null; } if (this.characterCache != null) { return(UnityTask <List <CharacterResult> > .Empty(this.characterCache)); } else { return(UnityTask <List <CharacterResult> > .Run(FetchCharacters())); } IEnumerator <List <CharacterResult> > FetchCharacters() { var getCharacters = this.playfabManager.Do <ListUsersCharactersRequest, ListUsersCharactersResult>(new ListUsersCharactersRequest(), PlayFabClientAPI.GetAllUsersCharactersAsync); while (getCharacters.IsDone == false) { yield return(null); } this.characterCache = getCharacters.Value.Characters; yield return(this.characterCache); } }
void BackgroundToBackgroundException() { var task1 = UnityTask.Run(() => { Debug.Log("1 Go"); var task2 = UnityTask.Run(() => { UnityTask.Delay(100); Debug.Log("2 Go"); throw new Exception("2 Fail"); }); task2.Wait(); if (task2.IsFaulted) { throw task2.Exception; } }); task1.Wait(); Debug.Log(task1.Status + " " + task1.Exception.Message); }
// **************************************************************************************************** // **************************************************************************************************** // MULTI-THREADED FUNCTIONS, THANKS TO UNITY TASKS // **************************************************************************************************** IEnumerator _MultiThread_CCDyn_UpdateTiles() { var task = UnityTask.Run(() => { theCCDynamicFieldManager.updateTiles(); }); yield return(task); }
void Background() { UnityTask.Run(() => { Debug.Log("Sleeping..."); UnityTask.Delay(2000); Debug.Log("Slept"); }); }
public void ReturnAValueToTheUIThread() { UnityTask.Run(() => { return(FindPrimeNumber(10000)); }).ContinueOnUIThread((r) => { ResultText.text = "The result is: " + r.Result.ToString(); }); }
public UnityTask <bool> RegisterForPushNotifications() { #if UNITY_ANDROID && USING_ANDROID_FIREBASE_MESSAGING return(UnityTask <bool> .Run(this.RegisterForAndroidPushNotificationsCoroutine())); #elif UNITY_IOS return(UnityTask <bool> .Run(this.RegisterForIosPushNotificationsCoroutine())); #else return(UnityTask <bool> .Run(this.UnsupportedPlatfromCoroutine())); #endif }
public void CreateContinuation() { UnityTask <long> unityTask = UnityTask.Run(() => { return(FindPrimeNumber(1000)); }).ContinueWith((r) => { return(FindPrimeNumber((int)r.Result)); }); }
void BackgroundException() { var task1 = UnityTask.Run(() => { throw new Exception("Hello World"); }); task1.Wait(); Debug.Log(task1.Status + " " + task1.Exception.Message); }
public void WaitAndReturnAValue() { UnityTask <long> unityTask = UnityTask.Run(() => { return(FindPrimeNumber(10000)); }); UnityTask.WaitAll(unityTask); long result = unityTask.Result; }
public UnityTask <T> GetTitleData <T>(string titleDataKey) where T : class { if (this.titleDataObjectCache.TryGetValue(titleDataKey, out object obj)) { return(UnityTask <T> .Empty(obj as T)); } else { return(UnityTask <T> .Run(FetchTitleDataObject())); }
public void OnEnable() { hideFlags = HideFlags.HideAndDontSave; LoadSettings(); if (_settings.AutoLogin) { _connectionStatus = ""; UnityTask.Run(() => TryLogin()); //CloudFileWatcher.Access.SetAuthorization(_settings.Token); } //_connectionStatus = !CloudFileWatcher.Access.Token.IsEmpty() ? "Connected." : "Disconnected."; }
public UnityTask <bool> ChangeDisplayName(string newDisplayName) { return(UnityTask <bool> .Run(ChangeDisplayNameCoroutine())); IEnumerator <bool> ChangeDisplayNameCoroutine() { var updateDisplayName = this.playfabManager.Do(new UpdateUserTitleDisplayNameRequest { DisplayName = newDisplayName, }); while (updateDisplayName.IsDone == false) { yield return(default);
IEnumerator coroutineSomeFunc() { bool result = false; //code to show "thinkng sign" UnityTask t = UnityTask.Run(() => { //and no freesing now result = Calculator.DoHeavy(myArg); }); yeild return(t); //code to hide "thinkng sign" if (result) { //continue game flow } }
void BackgroundToRotine() { UnityTask.Run(() => { Debug.Log("Thread A Running"); var task = UnityTask.RunCoroutine(RoutineFunction()); while (task.IsRunning) { Debug.Log("."); UnityTask.Delay(500); } Debug.Log("Thread A Done"); }); }
/// <summary> /// Called when drawing the GUI. /// </summary> private void OnGUI() { GUILayout.Label("Credentials"); GUILayout.Label("Username"); _settings.Username = EditorGUILayout.TextField(_settings.Username); GUILayout.Label("Password"); _password = EditorGUILayout.PasswordField(_password); GUILayout.Label(_connectionStatus); if (GUILayout.Button("Login")) { UnityTask.Run(async() => { _connectionStatus = "Connecting..."; Token token = null; try { token = await CloudFileWatcher.Access.GetToken(_settings.Username, _password); } catch (Exception ex) { Debug.LogError(ex.InnerException.Message); } if (token.token != null) { SetConnected(token); } else { //_connectionStatus = "Wrong user/password."; SetDisconnected("Wrong user/password."); } Repaint(); }); } if (GUILayout.Button("Logout")) { SetDisconnected(); } _settings.AutoLogin = GUILayout.Toggle(_settings.AutoLogin, "Remember me"); if (GUILayout.Button("Download")) { CloudFileWatcher.Access.DownloadSolution(); } //CloudFileWatcher.Watch(_settings.AutoLogin); }
public UnityTask <bool> Initialize() { return(UnityTask <bool> .Run(InitializeCoroutine())); IEnumerator <bool> InitializeCoroutine() { if (this.IsInitialized) { yield return(true); yield break; } // If it's already running, then wait for it to finish and leave if (this.isInitializationRunning) { while (this.isInitializationRunning) { yield return(default);
public UnityTask <List <ItemInstance> > GetInventoryItems() { if (this.usersInventoryCache != null) { return(UnityTask <List <ItemInstance> > .Empty(this.usersInventoryCache)); } else { return(UnityTask <List <ItemInstance> > .Run(GetInventoryItemsCoroutine())); } IEnumerator <List <ItemInstance> > GetInventoryItemsCoroutine() { // If it's already running, then wait for it to finish if (this.getInventoryCoroutineRunning) { while (this.getInventoryCoroutineRunning) { yield return(default);
public UnityTask <string> GetTitleData(string titleDataKey) { if (this.titleDataCache.TryGetValue(titleDataKey, out string titleDataValue)) { return(UnityTask <string> .Empty(titleDataValue)); } else { return(UnityTask <string> .Run(FetchTitleData())); } IEnumerator <string> FetchTitleData() { if (UnityEngine.Time.realtimeSinceStartup < 10.0) { UnityEngine.Debug.LogWarning($"Retrieving Title Data Key {titleDataKey} early in app startup. Prehaps add this to PlayFabManager to download at startup."); } yield return(null); } }
public UnityTask <bool> InitializeUnityPurchasing(System.Action <AppStore, ConfigurationBuilder> configurationBuilder) { return(UnityTask <bool> .Run(InitializeUnityPurchasingCoroutine())); IEnumerator <bool> InitializeUnityPurchasingCoroutine() { if (this.initializationState == InitializationState.InitializedSucceeded) { yield return(true); yield break; } float startTime = Time.realtimeSinceStartup; this.initializationState = InitializationState.Initializing; UnityPurchasing.Initialize(this, this.GetConfigurationBuilder(configurationBuilder)); while (this.initializationState == InitializationState.Initializing) { yield return(default);
void BackgroundToMain() { UnityTask.Run(() => { Debug.Log("Thread A Running"); var task = UnityTask.RunOnMain(() => { Debug.Log("Sleeping..."); UnityTask.Delay(2000); Debug.Log("Slept"); }); while (task.IsRunning) { Debug.Log("."); UnityTask.Delay(100); } Debug.Log("Thread A Done"); }); }
public UnityTask <List <StoreItem> > GetStore(string storeId, bool forceRefresh = false) { if (forceRefresh) { this.cachedStores.Remove(storeId); } if (this.cachedStores.ContainsKey(storeId)) { return(UnityTask <List <StoreItem> > .Empty(this.cachedStores[storeId])); } else { return(UnityTask <List <StoreItem> > .Run(FetchStore())); } IEnumerator <List <StoreItem> > FetchStore() { this.getStoreRequest.StoreId = storeId; var getStore = this.playfabManager.Do <GetStoreItemsRequest, GetStoreItemsResult>(this.getStoreRequest, PlayFabClientAPI.GetStoreItemsAsync); while (getStore.IsDone == false) { yield return(null); } var store = getStore.Value?.Store; // Caching off the store in case the user requests it again if (store != null) { this.cachedStores.Add(storeId, store); } yield return(store); } }
public UnityTask <bool> InitializeUnityPurchasing(System.Action <AppStore, ConfigurationBuilder> configurationBuilder) { return(UnityTask <bool> .Run(InitializeUnityPurchasingCoroutine())); IEnumerator <bool> InitializeUnityPurchasingCoroutine() { if (this.initializationState == InitializationState.InitializedSucceeded) { yield return(true); yield break; } float startTime = Time.realtimeSinceStartup; this.initializationState = InitializationState.Initializing; UnityPurchasing.Initialize(this, this.GetConfigurationBuilder(configurationBuilder)); while (this.initializationState == InitializationState.Initializing) { yield return(default(bool)); if (Time.realtimeSinceStartup - startTime > 5.0f) { throw new PurchasingInitializationTimeOutException(); } } if (this.initializationState == InitializationState.InitializedSucceeded) { yield return(true); } else { throw new PurchasingInitializationException(initializationFailureReason); } } }
public UnityTask <CatalogItem> GetCatalogItem(string itemId) { if (this.IsCatalogCached) { return(UnityTask <CatalogItem> .Empty(this.GetCachedCatalogItem(itemId))); } else { return(UnityTask <CatalogItem> .Run(Coroutine())); } IEnumerator <CatalogItem> Coroutine() { var getCatalog = this.GetCatalog(); while (getCatalog.IsDone == false) { yield return(null); } yield return(this.GetCachedCatalogItem(itemId)); } }
/// <summary> /// Retrieves the files from the server. /// </summary> public void FetchFiles() { _fileList.Clear(); UnityTask.Run(async() => { try { foreach (var file in await CloudFileWatcher.Access.GetFiles(SettingsDrawer.UserID)) { _fileList.Add(file); } } catch (NullReferenceException) { // Happens when the user is not connected Debug.LogWarning("Cannot fetch files: the DNAI user is not connected."); } catch (Exception ex) { Debug.LogError("Error while fetching files: " + ex.Message); } }); }
public UnityTask <List <CatalogItem> > GetCatalog() { if (this.cachedCatalog != null) { return(UnityTask <List <CatalogItem> > .Empty(this.cachedCatalog)); } else { return(UnityTask <List <CatalogItem> > .Run(FetchCatalog())); } IEnumerator <List <CatalogItem> > FetchCatalog() { var getCatalog = this.playfabManager.Do <GetCatalogItemsRequest, GetCatalogItemsResult>(this.getCatalogRequest, PlayFabClientAPI.GetCatalogItemsAsync); while (getCatalog.IsDone == false) { yield return(null); } var catalogItems = getCatalog.Value?.Catalog; if (catalogItems != null) { this.cachedCatalog = catalogItems; this.catalogItemDictionary.Clear(); foreach (var item in this.cachedCatalog) { this.catalogItemDictionary.Add(item.ItemId, item); } } yield return(catalogItems); } }
// ************************************************************************* // THREAD OPERATIONS // ************************************************************************* public void initiateSearch() { var task = UnityTask.Run(() => { _initiateSearch(); }); }
public UnityTask <PurchaseEventArgs> PurchaseProduct(string itemId) { return(UnityTask <PurchaseEventArgs> .Run(this.PurchaseProductCoroutine(itemId))); }
// ************************************************************************* // THREAD OPERATIONS // ************************************************************************* public void initiateEikonalSolver(CC_Map_Package fields, List <Location> goalLocs) { var task = UnityTask.Run(() => { _computeContinuumCrowdsFields(fields, goalLocs); }); }