Esempio n. 1
0
    private void CreateNewUI(PizzaIngredient addedIngredient)
    {
        // instantiate UI
        var newIngredient = Instantiate(ingredientUI, ingredientUITransform.position, ingredientUITransform.rotation, ingredientUITransform);

        // add new UI to list of UI for updating
        ingredientUIList.Add(newIngredient);
        uniqueIngredientCounts.Add(1);

        // update text with info
        var ingredientTexts = newIngredient.GetComponentsInChildren <TMP_Text>();

        ingredientTexts[0].text = addedIngredient.GetIngredientName();
        ingredientTexts[1].text = "x" + uniqueIngredientCounts[ingredientUIList.IndexOf(newIngredient)];

        newIngredient.GetComponentInChildren <Image>().sprite = addedIngredient.GetIngredientIcon();
    }
Esempio n. 2
0
    private void UpdateCanvas(PizzaIngredient addedIngredient)
    {
        // checks if added ingredient already has UI
        foreach (var uiElement in ingredientUIList)
        {
            var ingredientTexts = uiElement.GetComponentsInChildren <TMP_Text>();
            if (addedIngredient.GetIngredientName() == ingredientTexts[0].text)
            {
                ++uniqueIngredientCounts[ingredientUIList.IndexOf(uiElement)];
                ingredientTexts[1].text = "x" + uniqueIngredientCounts[ingredientUIList.IndexOf(uiElement)];
                return;
            }
        }

        // if there is no UI create one
        CreateNewUI(addedIngredient);
    }