internal void Initialize() { #if UNITY_EDITOR _requestType = WebtaskRequestType.GetCounter; #endif StartCoroutine(WebtaskIoRequest(_requestType)); }
private IEnumerator WebtaskIoRequest(WebtaskRequestType requestType) { var postData = ((int)requestType).ToString(); using (UnityWebRequest www = UnityWebRequest.Post(EnvironmentVariables.CounterWebTaskUri, postData)) { Logger.Instance.Log($"Starting POST request to webtask.io (Post data: {postData}).", gameObject); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Logger.Instance.LogWarning("An error occured when attempting to download the examination number from webtask.io.\nDefaulting to 1.", gameObject); _playerNumber = 1; } else { Logger.Instance.Log("The download was successful from webtask.io.", gameObject); try { _playerNumber = int.Parse(www.downloadHandler.text); } catch { Logger.Instance.LogWarning("An error occured when attempting parse the reveiced examination number.\nDefaulting to 1.", gameObject); _playerNumber = 1; } Logger.Instance.Log($"The player is number {_playerNumber}.", gameObject); } } _examinationModeIndex = GetExaminationMode(); ExaminationModeNumber = _examinationModeIndex + 1; Logger.Instance.Log($"Loaded Mode {ExaminationModeNumber}.", gameObject); }