private void ShowWindow(CraftSlot _target, Vector2 offset) { id = 0; if (target == _target) { HideWindow(); } else { target = _target; tr.position = target.transform.position + new Vector3(offset.x, offset.y, 0); itemList = target.GetItems(); if (itemList == null) { selectItem = null; ChangeImage(null); } else { selectItem = itemList[id]; ChangeImage(selectItem.Sprite); } gameObject.SetActive(true); } }
private void RefreshRecipies() { for (int i = 0; i < _recipies.CraftingRecipes.Count; i++) { CraftingRecipe craftingRecipe = _recipies.CraftingRecipes[i]; if (!craftingRecipe.IsDefaultRecipe) { continue; } Item item = ItemDictionary.Instance.GetItemByID(craftingRecipe.FinalItemId); if (item == null) { continue; } GameObject slot = Instantiate(craftingRecipeSlot, slotParent); Transform recipeItemParent = slot.transform.Find("RecipeItemPanel"); CraftSlot craftSlot = slot.GetComponent <CraftSlot>(); craftSlot.SlotRecipe = craftingRecipe; craftSlot.AmountOfUniqueIds = craftingRecipe.ItemsNeeded; slot.transform.GetChild(0).GetComponent <Image>().sprite = item.Icon; slot.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = item.ItemName; for (int j = 0; j < craftSlot.AmountOfUniqueIds.Length; j++) { GameObject neededItem = Instantiate(neededItemSlot, recipeItemParent); string text = $"{craftSlot.AmountOfUniqueIds[j].y}x"; neededItem.GetComponent <Image>().sprite = ItemDictionary.Instance.GetItemByID((int)craftSlot.AmountOfUniqueIds[j].x).Icon; neededItem.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = text; } } }
public void HideWindow() { id = 0; target = null; itemList = null; selectItem = null; gameObject.SetActive(false); }
public override void SetSlot(Items items, CraftSlot slot) { if (slot != this) { return; } base.SetSlot(items, slot); resourceHandler(Item); }
public override void SetSlot(Items items, CraftSlot slot) { if (slot != this) { return; } base.SetSlot(items, slot); AcceptHandler(); }
public void AddItem(CraftSlot slot) { if (slot.index == 1) { item1 = slot.item; } else { item2 = slot.item; } onComboChanged.Invoke(); }
void Awake() { image = GetComponent <Image>(); if (index == 1) { first = this; } else { second = this; } }
public virtual void SetSlot(Items items, CraftSlot slot) { if (slot != this) { return; } Item = items; if (Item) { ChangeImage(Item.Sprite); } }
private void SelectCraftableItem(CraftSlot slot) { _activeSlot = slot; var hasAllIngredients = true; ClearResourceSlots(); for (var i = 0; i < slot.recipe.ingredients.Count; i++) { var foundIngredient = slot.recipe.foundIngredients.Find(cell => { return(slot.recipe.ingredients[i].item.id == cell[0].item.id); }) != null; _resourcesSlots[i].Init(slot.recipe.ingredients[i], !foundIngredient); hasAllIngredients &= foundIngredient; } _createButton.enabled = hasAllIngredients; _title.text = slot.recipe.result.item.title; _description.text = slot.recipe.result.item.description; }
/// <summary> /// 조합 리스트 설정 /// </summary> /// <param name="craftTable"></param> public void CraftItemList(CraftTable craftTable) { InitList(); for (int i = 0; i < MeterialImage.Count; i++) { MeterialImage[i].SlotClear(); MeterialText[i].text = ""; } foreach (CraftTable.CraftData itemdata in craftTable.m_Craft) { ItemImage.SlotClear(); ItemDesText.text = ""; ItemNameText.text = ""; CraftSlot slot = Instantiate(CraftSlotPrefab, transform.position, CraftSlotPrefab.transform.rotation); slot.transform.parent = CraftContents.transform; slot.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); slot.SetSlot(itemdata); CraftSlotList.Add(slot); } }
public override void UseItem(GameObject callingSlotObj) { var drop = callingSlotObj.GetComponent <DropItemHandler>(); if (drop.slotType != type) { InventorySlot slot = callingSlotObj.GetComponent <InventorySlot>(); var craftingSlots = GameObject.FindGameObjectsWithTag("Crafting Slot"); CraftSlot craftSlot = null; foreach (GameObject cSlot in craftingSlots) { if (cSlot.transform.GetChild(0).GetComponent <Image>().enabled == false) { craftSlot = cSlot.GetComponent <CraftSlot>(); break; } } if (craftSlot == null) { craftSlot = craftingSlots[0].GetComponent <CraftSlot>(); } var craftSlotScript = craftSlot.GetComponent <CraftSlot>(); craftSlotScript.SwapItems(slot); } else { Debug.Log("Swapping out"); CraftSlot slot = callingSlotObj.GetComponent <CraftSlot>(); List <int> availableSlots = CheckAvailableSlots(slot.itemList); var targetSlot = FindInventorySlotWithIndex(availableSlots[0]); var targetStack = targetSlot.itemStack; var localStack = slot.itemStack; slot.itemList.AddAt(availableSlots[0], slot.itemStack); if (targetSlot != null) { targetSlot.RemoveItem(); targetSlot.AddItem(localStack); slot.itemList.AddAt(targetSlot.itemIndex, localStack); } slot.RemoveItem(); slot.itemList.itemEvent.Raise(); if (targetStack != null) { slot.AddItem(targetStack); slot.craftList.AddAt(slot.itemIndex, targetStack); } if (slot.stackEvent != null) { slot.stackEvent.Raise(); } slot.itemList.itemEvent.Raise(); slot.craftList.itemEvent.Raise(); } }