IEnumerator PostUnitsAsync(List <UnitPrep> unitPreps) { Debug.Log("PostScoreAsync..."); yield return(1); UnitPrepsModel units = new UnitPrepsModel(StaticAllData.currentMap._formationUnits); var model = new UnitPrepUploadModel() { unitPreps = JsonUtility.ToJson(units), userId = userID }; var json = JsonUtility.ToJson(model); Debug.Log(json); var task = RestClient.Post(ServerPath, json); yield return(task.SendWebRequest()); if (task.isNetworkError) { Debug.LogError(task.error); } else { Debug.Log("Success"); //this will need to be communicated to home } task.Dispose(); }
IEnumerator GetAllUnitsAsync() { Debug.Log("GetAllAsync..."); yield return(1); var task = RestClient.Get(ServerPath); //rest client get yield return(task.SendWebRequest()); if (task.isNetworkError) { Debug.LogError(task.error); } else { var unitLists = task.Deserialize <LoadUnitsResponse>(); if (unitLists == null) { Debug.Log("list was null"); } else if (unitLists.unitPrepJsons == null) { Debug.Log("prep jsons were null"); } else if (unitLists.unitPrepJsons.Count == 0) { Debug.Log("0 in list"); } if (unitLists != null && unitLists.unitPrepJsons != null && unitLists.unitPrepJsons.Count > 0) { Debug.Log("received units !"); foreach (UnitListContainer unitCont in unitLists.unitPrepJsons) { UnitPrepsModel unitPrepsM = JsonUtility.FromJson <UnitPrepsModel>(unitCont.UnitPrepJson); foreach (UnitPrep unit in unitPrepsM.unitPrepList) { StaticAllData.currentMap._formationUnits.Add(unit); } } HomeUtil.startHomeGame(); } else { Debug.Log("either of lists is null or no units"); } } task.Dispose(); }