private IEnumerator CheckGroupStatus() { AsyncTask <bool> task = new AsyncTask <bool>(() => { CloudUserManager groupMgr = CloudUserManager.Instance; // wait for the group manager to start int waitPeriods = 10; while (groupMgr == null && waitPeriods > 0) { Thread.Sleep(500); waitPeriods--; groupMgr = CloudUserManager.Instance; } return(groupMgr ? groupMgr.IsGroupTrained() : false); }); task.Start(); yield return(null); while (task.State == TaskState.Running) { yield return(null); } if (!task.Result) { if (!string.IsNullOrEmpty(task.ErrorMessage)) { Debug.LogError(task.ErrorMessage); } TrainGroupButton.SetActive(true); } CloudUserManager userManager = CloudUserManager.Instance; if (userManager && listHeaderText) { listHeaderText.text = "Group: " + userManager.userGroupId; } yield return(null); }
private IEnumerator TrainGroup() { AsyncTask <bool> task = new AsyncTask <bool>(() => { CloudUserManager groupMgr = CloudUserManager.Instance; return(groupMgr.StartGroupTraining()); }); bool abort = false; modalPanel.ShowProgress("Started group training. Please wait.", () => abort = true); task.Start(); yield return(null); while (task.State == TaskState.Running) { yield return(null); } if (!task.Result) { if (!string.IsNullOrEmpty(task.ErrorMessage)) { modalPanel.ShowMessage(task.ErrorMessage); } else { modalPanel.ShowMessage("Group training failed. Please, try again later."); } yield return(null); } else if (!abort) { task = new AsyncTask <bool>(() => { CloudUserManager groupMgr = CloudUserManager.Instance; bool isTrained = false; int retries = 0; while (!isTrained && retries++ < 3 && !abort) { Thread.Sleep(5000); isTrained = groupMgr.IsGroupTrained(); } return(isTrained); }); task.Start(); yield return(null); while (task.State == TaskState.Running) { yield return(null); } if (!abort) { if (!task.Result) { if (!string.IsNullOrEmpty(task.ErrorMessage)) { modalPanel.ShowMessage(task.ErrorMessage); } else { modalPanel.ShowMessage("Group training failed. Please, try again later."); } } else { modalPanel.ShowMessage("Group training succeeded."); TrainGroupButton.SetActive(false); } } } yield return(null); }