示例#1
0
 private void SelectRecipe(RecipeButtonScript recipeButtonScript)
 {
     recipeButtonScript.OnPressed();
     FillRecipeInfo(recipeButtonScript);
     chosenRecipe = recipeButtonScript;
     recipeInfoGameObject.SetActive(true);
 }
示例#2
0
 private void FillRecipeInfo(RecipeButtonScript recipeButtonScript)
 {
     chosenRecipeNameTextComponent.text        = recipeButtonScript.CraftingRecipe.RecipeName;
     chosenRecipeDescriptionTextComponent.text = recipeButtonScript.CraftingRecipe.RecipeDescription;
     chosenRecipeIconImageComponent.sprite     = recipeButtonScript.RecipeIcon;
     ingredientsTextComponent.text             = GenerateIngredientsList(recipeButtonScript.CraftingRecipe);
     toolsTextComponent.text       = GenerateToolsList(recipeButtonScript.CraftingRecipe);
     reagentsTextComponent.text    = GenerateReagentsList(recipeButtonScript.CraftingRecipe);
     craftButtonTextComponent.text = GenerateButtonText(recipeButtonScript.CraftingRecipe);
 }
示例#3
0
 private void DeselectRecipe(RecipeButtonScript recipeButtonScript)
 {
     if (recipeButtonScript == null)
     {
         return;
     }
     recipeButtonScript.OnUnpressed();
     chosenRecipe = null;
     recipeInfoGameObject.SetActive(false);
 }
        /// <summary>
        ///     Generates a new recipe button in craftingRecipe.Category.
        /// </summary>
        /// <param name="craftingRecipe">The associated crafting recipe.</param>
        public void OnPlayerLearnedRecipe(CraftingRecipe craftingRecipe)
        {
            GameObject newRecipeButton = RecipeButtonScript.GenerateNew(
                recipeButtonTemplatePrefab,
                recipesGridLayout.transform,
                craftingRecipe
                );

            if (chosenCategory.CategoryAndIcon.RecipeCategory != craftingRecipe.Category)
            {
                newRecipeButton.SetActive(false);
            }

            GetRecipesInCategory(craftingRecipe.Category)
            .RecipeButtonScripts
            .Add(newRecipeButton.GetComponent <RecipeButtonScript>());
        }
        /// <summary>
        ///     Generates new recipe button with unique crafting recipe and its icon.
        /// </summary>
        /// <param name="recipeButtonTemplate">The template to create button from.</param>
        /// <param name="parentTransform">The place(as a transform) where the button will be stored.</param>
        /// <param name="craftingRecipe">The crafting recipe associated with the button.</param>
        /// <returns>A new recipe button.</returns>
        public static GameObject GenerateNew(
            GameObject recipeButtonTemplate,
            Transform parentTransform,
            CraftingRecipe craftingRecipe
            )
        {
            // instantiate a blank crafting button
            GameObject generatedButton = Instantiate(recipeButtonTemplate, parentTransform);

            RecipeButtonScript recipeButtonScript = generatedButton.GetComponent <RecipeButtonScript>();

            // we can't move this to the Awake() event because the button can be inactive, so Awake() will not be called
            recipeButtonScript.backgroundImageComponent = recipeButtonScript.backgroundGameObject.GetComponent <Image>();
            recipeButtonScript.borderImageComponent     = recipeButtonScript.borderGameObject.GetComponent <Image>();
            recipeButtonScript.iconImageComponent       = recipeButtonScript.iconGameObject.GetComponent <Image>();
            recipeButtonScript.recipeNameTextComponent  = recipeButtonScript.textGameObject.GetComponent <Text>();

            recipeButtonScript.craftingRecipe = craftingRecipe;
            // should we use different, overrided icon?
            if (craftingRecipe.RecipeIconOverride != null)
            {
                recipeButtonScript.recipeIcon = craftingRecipe.RecipeIconOverride;
            }
            else
            {
                // ok, let's just try to use an icon of a result game object
                SpriteRenderer spriteRenderer;
                foreach (GameObject resultPart in craftingRecipe.Result)
                {
                    spriteRenderer = resultPart.GetComponentInChildren <SpriteRenderer>();
                    if (spriteRenderer == null || spriteRenderer.sprite == null)
                    {
                        continue;
                    }
                    recipeButtonScript.recipeIcon = spriteRenderer.sprite;
                    break;
                }
            }

            recipeButtonScript.iconImageComponent.sprite      = recipeButtonScript.recipeIcon;
            recipeButtonScript.backgroundImageComponent.color = recipeButtonScript.deselectedColor;
            recipeButtonScript.borderImageComponent.color     = recipeButtonScript.uncraftableColor;
            recipeButtonScript.recipeNameTextComponent.text   = craftingRecipe.RecipeName;

            return(generatedButton);
        }
示例#6
0
 /// <summary>
 ///     Deselects a chosen recipe.
 ///     Selects the new recipe.
 /// </summary>
 /// <param name="recipeButtonScript">The recipe to select.</param>
 public void ChangeRecipe(RecipeButtonScript recipeButtonScript)
 {
     DeselectRecipe(chosenRecipe);
     SelectRecipe(recipeButtonScript);
 }