public void AddIngredientBookmarks() { List <int> ingredientBookmarkList = StringToIntList(Panels.instance.memberInfo.member.ingredientBookmarks); int amount = ingredientBookmarkList.Count; Vector2 panelSize = body.GetComponent <RectTransform>().rect.size; RectTransform content = body.GetChild(1).GetChild(0).GetComponent <RectTransform>(); float ySize = panelSize.y / ingredientOnePageAmount; float contentYSize = panelSize.y; if (amount > ingredientOnePageAmount) { contentYSize = ySize * amount; } content.offsetMin = new Vector2(0, 0); content.offsetMax = new Vector2(0, contentYSize); content.localPosition = new Vector2(0, -contentYSize / 2); for (int i = 0; i < amount; i++) { Transform newBookmark = Instantiate(ingredientBookmark); newBookmark.SetParent(content); IngredientBookmark bookmarkInfo = newBookmark.GetComponent <IngredientBookmark>(); ingredientBookmarks.Add(bookmarkInfo); RectTransform rectTransform = newBookmark.GetComponent <RectTransform>(); rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = new Vector2(0, ySize); rectTransform.localPosition = new Vector2(0, contentYSize / 2 + -ySize * i - ySize / 2); int ingredientID = ingredientBookmarkList[i]; string sql = "SELECT * FROM ingredient WHERE id = " + ingredientID + ";"; MySql.Data.MySqlClient.MySqlDataReader reader = DbConnecter.instance.Reader(sql); reader.Read(); Ingredient ingredient = new Ingredient(); ingredient.id = reader.GetInt32(0); ingredient.casNo = reader.GetString(1); ingredient.english = reader.GetString(2); ingredient.korean = reader.GetString(3); ingredient.ewgGrade = reader.GetString(4); ingredient.eye = reader.GetString(5); ingredient.respiratory = reader.GetString(6); ingredient.digestive = reader.GetString(7); ingredient.reproductive = reader.GetString(8); ingredient.integumentary = reader.GetString(9); reader.Close(); DbConnecter.instance.CloseConnection(); IngredientInfo ingredientInfo = newBookmark.GetChild(0).GetComponent <IngredientInfo>(); ingredientInfo.IngredientChange(ingredient, gameObject); bookmarkInfo.ingredientID = ingredient.id; } }
public void DeleteIngredientBookmark(int ingredientID, IngredientBookmark ingredientBookmark) { float ratePos = 1 - body.GetChild(1).GetComponent <ScrollRect>().verticalNormalizedPosition; int amount = ingredientBookmarks.Count; DbConnecter.instance.Connect(); List <int> intList = StringToIntList(Panels.instance.memberInfo.member.ingredientBookmarks); int number = Mathf.FloorToInt(ratePos * amount); number = Mathf.Clamp(number - 2, 0, number); intList.Remove(ingredientID); ingredientBookmarks.Remove(ingredientBookmark); Destroy(ingredientBookmark.gameObject); SortIngredientBookmark(number); string bookmarks = IntListToString(intList); UpdateIngredientBookmark(bookmarks); DbConnecter.instance.CloseConnection(); }
void SortIngredientBookmark(int number) { int amount = ingredientBookmarks.Count; Vector2 panelSize = body.GetComponent <RectTransform>().rect.size; RectTransform content = body.GetChild(1).GetChild(0).GetComponent <RectTransform>(); float ySize = panelSize.y / ingredientOnePageAmount; float contentYSize = panelSize.y; if (amount > ingredientOnePageAmount) { contentYSize = ySize * amount; } content.offsetMin = new Vector2(0, 0); content.offsetMax = new Vector2(0, contentYSize); content.anchoredPosition = new Vector2(0, -contentYSize / 2 + ySize * number); for (int i = 0; i < amount; i++) { IngredientBookmark unit = ingredientBookmarks[i]; RectTransform rectTransform = unit.GetComponent <RectTransform>(); rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = new Vector2(0, ySize); rectTransform.localPosition = new Vector2(0, contentYSize / 2 + -ySize * i - ySize / 2); } }