void Init_() { foreach (Recipe recipe in ItemManager.Instance.recipeData.RecipeList) { //rect.sizeDelta = new Vector2(rect.sizeDelta.x, obj.GetComponent<RectTransform>().position.y + 100); GameObject obj = Instantiate(recipeButtonPrefab, bpContent); RecipeButton recipeBtn = obj.GetComponent <RecipeButton>(); recipeBtn.recipeID = recipe.RecipeId; } }
private void AddButtons() { for (int i = 0; i < recipeList.Count; i++) { Recipe recipe = recipeList[i]; GameObject newButton = Instantiate(button); newButton.transform.SetParent(contentPanel); newButton.transform.localScale = new Vector3(1, 1, 1); RecipeButton recipeButton = newButton.GetComponent <RecipeButton>(); recipeButton.Setup(recipe, this); } }
private void StartProgressBar(Recipe recipe, int id) { _activeCraft = _queuedButtons.FirstOrDefault(i => i.QueueID == id); if (_activeCraft == null) { throw new UnityException("PlayerCraftingViewModel got bad things"); } var slider = _activeCraft.Button.transform.GetComponentInChildren <Slider>(); var binding = slider.gameObject.AddComponent <SliderBinding>(); binding.Initialize(() => _crafter.CurrentCraftRemainingAsZeroToOne); }
void Start() { if (recipeButtonPrefab != null) { for (int i = 0; i < database.Recipes.Count; i++) { GameObject recipeButtonInstance = Instantiate(recipeButtonPrefab).gameObject; recipeButtonInstance.transform.SetParent(Grid.transform); RecipeButton rb = recipeButtonInstance.AddComponent <RecipeButton>(); recipeButtonInstance.GetComponent <Button>().onClick.AddListener(new UnityEngine.Events.UnityAction(rb.CallDisplayer)); if (rb.holdedRecipe == null) { rb.holdedRecipe = database.Recipes[rb.transform.GetSiblingIndex()]; } recipeButtonInstance.transform.GetChild(0).GetComponent <Text>().text = database.ItemByID(rb.holdedRecipe.OutputID).Name.ToString(); } } }
// add button to queued list, hook in cancel action private void OnCraftingQueued(Recipe recipe, int id) { foreach (var ingredient in recipe.Ingredients) { if (_inventory.TryRemoveProduct(ingredient.ProductId, ingredient.Quantity) < ingredient.Quantity) { Debug.Log("Craft button requested good is could not afford"); } } var button = CreateQueuedButton(recipe); var queued = new RecipeButton { Button = button, Recipe = recipe, QueueID = id }; _queuedButtons.Add(queued); button.onClick.AddListener(() => { CancelCrafting(queued.QueueID); }); }
public void CreateCraftingWindow(PlayerResources newPlayerResources) { cookingRecipes = new RecipeButton[ItemModel.instance.cookingRecipes.Count]; for (int i = 0; i < ItemModel.instance.cookingRecipes.Count; ++i) { GameObject newButton = Instantiate(recipeButtonPrefab, content); RecipeButton recipeButton = newButton.GetComponent <RecipeButton>(); recipeButton.SetRecipe(i, 0); recipeButton.button.onClick.AddListener(() => SelectItem(recipeButton.Id)); cookingRecipes[i] = recipeButton; cookingRecipes[i].gameObject.SetActive(false); } workbenchRecipes = new RecipeButton[ItemModel.instance.workbenchRecipes.Count]; for (int i = 0; i < ItemModel.instance.workbenchRecipes.Count; ++i) { GameObject newButton = Instantiate(recipeButtonPrefab, content); RecipeButton recipeButton = newButton.GetComponent <RecipeButton>(); recipeButton.SetRecipe(i, 1); recipeButton.button.onClick.AddListener(() => SelectItem(recipeButton.Id)); workbenchRecipes[i] = recipeButton; workbenchRecipes[i].gameObject.SetActive(false); } forgeRecipes = new RecipeButton[ItemModel.instance.forgeRecipes.Count]; for (int i = 0; i < ItemModel.instance.forgeRecipes.Count; ++i) { GameObject newButton = Instantiate(recipeButtonPrefab, content); RecipeButton recipeButton = newButton.GetComponent <RecipeButton>(); recipeButton.SetRecipe(i, 2); recipeButton.button.onClick.AddListener(() => SelectItem(recipeButton.Id)); forgeRecipes[i] = recipeButton; forgeRecipes[i].gameObject.SetActive(false); } playerResources = newPlayerResources; }
void UpdateDisplayedRecipes() { foreach (var recipe in unlockedRecipes) { //if its not already displaying display it if (!displayedRecipes.ContainsKey(recipe)) { GameObject go; if (recipe.IsFinalNode) { //Debug.Log("display final " + recipe.name); go = GameObject.Instantiate(recipeButtonPrefab, sellableRoot); } else { //Debug.Log("display " + recipe.name); go = GameObject.Instantiate(recipeButtonPrefab, contentRoot); } displayedRecipes.Add(recipe, go); go.name = recipe.name; RecipeButton button = go.GetComponentInChildren <RecipeButton>(); if (recipe.IsFinalNode) { button.nameLabel.text = recipe.name + " +" + recipe.GetMoneyPerTick() + "/t"; } else { button.nameLabel.text = recipe.name; } button.priceLabel.text = "$" + recipe.getPrice(); button.button.onClick.AddListener(delegate { SelectRecipe(recipe); }); button.buttonImage.color = button.newRecipeColor; } } LayoutRebuilder.ForceRebuildLayoutImmediate(rootGrid); }