IEnumerator GetShopData() { WWWForm form = new WWWForm(); UnityWebRequest webRequest = UnityWebRequest.Get(getShopApi + "/" + LoginManager.UserID); webRequest.SendWebRequest(); while (!webRequest.isDone) { yield return(null); // Progress is always set to 1 on android // Debug.LogFormat("Progress: {0}", webRequest.uploadProgress); } if (webRequest.isHttpError || webRequest.isNetworkError) { Debug.Log(webRequest.error); } else { Debug.Log("Request Done!:" + webRequest.downloadHandler.text); shopsInfo = JsonUtility.FromJson <ShopsInfo>(webRequest.downloadHandler.text); if (shopsInfo.success) { UIManager.StartDate = DateTime.Now.ToString(); DataManager.instance.CreateCurrentDayShopInfo(shopsInfo); CreateShopStatusFile(); } } }
public void CreateCurrentDayShopInfo(ShopData.ShopsInfo shopsInfo) { DayData dayData = new DayData(); dayData.M_Id = LoginManager.UserID; dayData.day = shopsInfo.data.shops[0].user_day; dayData.checkIn = DateTime.UtcNow.ToString(); dayData.checkOut = DateTime.UtcNow.ToString(); dayData.shops = new List <Shop>(); for (int i = 0; i < shopsInfo.data.shops.Count; i++) { Shop shop = new Shop(); shop.id = shopsInfo.data.shops[i].id; shop.SS_Id = 2; // still pending from server shop.shop_Name = shopsInfo.data.shops[i].name; shop.pic_Name_1 = ""; shop.pic_Name_2 = ""; shop.pic_Name_3 = ""; shop.pic_Name_4 = ""; shop.contact_Number = ""; shop.location = ""; shop.checkIn = ""; shop.checkOut = ""; shop.sku = new List <SkuData>(); for (int j = 0; j < shopsInfo.data.sku.Count; j++) { SkuData sku = new SkuData { id = shopsInfo.data.sku[j].id, count = 0 }; shop.sku.Add(sku); } dayData.shops.Add(shop); } string data = JsonUtility.ToJson(dayData); File.WriteAllText(Application.persistentDataPath + "/Data/DayInfo.json", data); ShopData.ShopDataManager.CurrentDayShopInfo = "Loaded"; }