Пример #1
0
    /// <summary>
    /// Sets the currently selected recipie.
    /// </summary>
    public void setSelectedRecipe(ButtonRecipe recipe)
    {
        this.selectedRecipe = recipe;

        ItemData[] ingredients;
        if (recipe == null)
        {
            ingredients = new ItemData[0];
        }
        else
        {
            ingredients = recipe.getRecipe().getIngredients();
        }
        for (int i = 0; i < this.ingredientIcons.Length; i++)
        {
            RecipeIngredientIcon icon = this.ingredientIcons[i];

            if (i <= ingredients.Length - 1)
            {
                icon.setItem(ingredients[i]);
                icon.setColor(this.getPlayer().inventory.containsItem(ingredients[i], out int j) ? RecipeIngredientIcon.EnumColor.GREEN : RecipeIngredientIcon.EnumColor.RED);
            }
            else
            {
                icon.setItem(null);
                icon.setColor(RecipeIngredientIcon.EnumColor.GRAY);
            }
        }

        this.updateCraftButtonInteractable();
    }
Пример #2
0
    private void Awake()
    {
        // Load the recipies from the resources folder.
        this.allRecipies = Resources.LoadAll <Recipe>("recipes");

        this.recipeButtons = new List <ButtonRecipe>();

        // Generate all of the slots.
        const int   btnsPerRow = 6;
        const float sidePad    = 16;

        float x = sidePad;
        float y = -sidePad;

        float btnSize = this.slotPrefab.GetComponent <RectTransform>().sizeDelta.y;

        foreach (Recipe recipe in this.allRecipies)
        {
            if (recipe != null)
            {
                ButtonRecipe recipeBtn = GameObject.Instantiate(this.slotPrefab, this.recipeRect).GetComponent <ButtonRecipe>();
                recipeBtn.transform.localPosition = new Vector3(x + (btnSize / 2), y - (btnSize / 2), 0);
                recipeBtn.setRecipie(recipe);
                this.recipeButtons.Add(recipeBtn);

                recipeBtn.GetComponent <Button>().onClick.AddListener(delegate {
                    if (this.selectedRecipe != null)
                    {
                        this.selectedRecipe.setOutlined(false);
                    }
                    recipeBtn.setOutlined(true);
                    this.setSelectedRecipe(recipeBtn);
                });

                x += btnSize + sidePad;

                if (x > 500)
                {
                    x  = sidePad;
                    y -= btnSize + sidePad;
                }
            }
        }

        this.updateCraftButtonInteractable();
    }