// Network call completed private void callback(JSONObject result) { if (final == null) { // Create Result container final = new SuperCookResult(); final.total_can_make_right_now = int.Parse(result.GetField("total_can_make_right_now").ToString()); final.results = new List<SuperCookRecipe>(); } // Convert results JSONArray arr = JSON.Parse(result.GetField("results").ToString()).AsArray; foreach (JSONNode jn in arr) { SuperCookRecipe scRecipe = new SuperCookRecipe(); scRecipe.title = jn["title"]; scRecipe.url = jn["url"]; scRecipe.uses = jn["uses"]; scRecipe.id = jn["id"].AsInt; final.results.Add(scRecipe); } if (final.results.Count >= final.total_can_make_right_now) finished(final); else { skip += 40; getRecipes(ingredients, finished); } }
public void initialize(SuperCookRecipe recipe) { this.recipe = recipe; Text txt = gameObject.GetComponentInChildren<Text>(); RawImage img = gameObject.GetComponentInChildren<RawImage>(); Toggle favButton = gameObject.GetComponentInChildren<Toggle>(); txt.text = recipe.title; if (main.Instance.isFavorite(recipe.id.ToString())) favButton.isOn = true; else favButton.isOn = false; StartCoroutine(JSONClient.GetImage("http://www.supercook.com/thumbs/" + recipe.id + ".jpg", imageCallback, img)); }
public void drawFavorite(string url, string id, string title) { SuperCookRecipe r = new SuperCookRecipe(); r.url = url; r.id = int.Parse(id); r.title = title; GameObject button = (GameObject)Instantiate(Resources.Load("RecipeButton 1"), Vector3.zero, Quaternion.identity); button.GetComponent<recipeButton>().initialize(r); button.transform.SetParent(resultGrid.transform); button.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1); shiftResultGrid(); favorites.Add(new KeyValuePair<string,GameObject>(id,button)); }