public CraftItemEventArgs(Inventory inv, bool pattern, CraftItemData result, CraftItemData grid, bool wasCrafted, Recipe recipe, PatternRecipe patternRecipe) { this.inv = inv; this.pattern = pattern; this.result = result; this.grid = grid; this.wasCrafted = wasCrafted; this.recipe = recipe; this.patternRecipe = patternRecipe; }
public void Update() { if (inv == null) { return; } //Initialize if not yet if (!inv.HasInitialized) { inv.Initialize(); } //Create UI if (generateUIFromSlotPrefab && !hasGenerated) { GenerateUI(inv.SlotAmount); hasGenerated = true; } ///TODO: Add Event here //Hiding Inventory if (hideInventory) { if (Input.GetKeyDown(toggleKey) && !isDraging) { if (isCraftInventory && dropOnCloseCrafting) { for (int i = 0; i < inv.slots.Count; i++) { var item = inv.slots[i]; Vector3 finalDropPos = dropPos; finalDropPos.x += Random.Range(-randomFactor.x, randomFactor.x); finalDropPos.y += Random.Range(-randomFactor.y, randomFactor.y); finalDropPos.z += Random.Range(-randomFactor.z, randomFactor.z); inv.DropItem(item.amount, finalDropPos, slot: i); } } togglableObject.SetActive(!togglableObject.activeInHierarchy); } } //Iterating slots go for (int i = 0; i < inv.slots.Count; i++) { // Create pattern grid if (isCraftInventory && i < pattern.Count) { pattern[i] = inv.slots[i].item; amount[i] = inv.slots[i].amount; } if (i >= slots.Count) { break; } // Rendering null Slot Image image; TextMeshProUGUI text; if (inv.slots[i].item == null) { for (int j = 0; j < slots[i].transform.childCount; j++) { if (slots[i].transform.GetChild(j).TryGetComponent <Image>(out image)) { image.sprite = null; image.color = new Color(0, 0, 0, 0); } else if (slots[i].transform.GetChild(j).TryGetComponent(out text)) { text.text = ""; } } continue; } // Rendering slot for (int j = 0; j < slots[i].transform.childCount; j++) { if (slots[i].transform.GetChild(j).TryGetComponent <Image>(out image)) { if (inv.slots[i].ItemInstance.hasDurability) { if (inv.slots[i].ItemInstance.durabilityImages.Count > 0) { image.sprite = GetNearestSprite(inv, inv.slots[i].durability, i); image.color = new Color(1, 1, 1, 1); } else { image.sprite = inv.slots[i].ItemInstance.sprite; image.color = new Color(1, 1, 1, 1); } } else { image.sprite = inv.slots[i].ItemInstance.sprite; image.color = new Color(1, 1, 1, 1); } } else if (slots[i].transform.GetChild(j).TryGetComponent(out text) && showAmount && inv[i].ItemInstance.showAmount) { text.text = inv.slots[i].amount.ToString(); } else if (slots[i].transform.GetChild(j).TryGetComponent(out text)) { text.text = ""; } } if (dragObj.GetComponent <DragSlot>().GetSlotNumber() == i && isDraging) { if (inv.slots[i].amount - dragObj.GetComponent <DragSlot>().GetAmount() == 0) { for (int j = 0; j < slots[i].transform.childCount; j++) { if (slots[i].transform.GetChild(j).TryGetComponent <Image>(out image)) { image.sprite = null; image.color = new Color(0, 0, 0, 0); } else if (slots[i].transform.GetChild(j).TryGetComponent(out text)) { text.text = ""; } } } else { for (int j = 0; j < slots[i].transform.childCount; j++) { if (slots[i].transform.GetChild(j).TryGetComponent(out text) && showAmount && inv[i].ItemInstance.showAmount) { text.text = (inv.slots[i].amount - dragObj.GetComponent <DragSlot>().GetAmount()).ToString(); } else if (slots[i].transform.GetChild(j).TryGetComponent(out text)) { text.text = ""; } } } } if (!isCraftInventory) { slots[i].GetComponent <Button>().onClick.RemoveAllListeners(); var index = i; slots[i].GetComponent <Button>().onClick.AddListener(() => { //Debug.Log($"Slot {slots[index].name} was clicked"); if (useOnClick) { inv.UseItemInSlot(index); } }); } } //Dont use on click if is crafting inventory if (isCraftInventory) { CraftItemData products = inv.CraftItem(new CraftItemData(pattern.ToArray(), amount.ToArray()), gridSize, false, true, productSlotsIndex.Length); List <Item> productsItem = new List <Item>(); if (products != CraftItemData.nullData && products.items.Length <= productSlotsIndex.Length) { if (products.items.Length == productSlotsIndex.Length) { for (int k = 0; k < products.items.Length; k++) { productsItem.Add(inv.slots[gridSize.x * gridSize.y + k].item ?? products.items[k]); } } else { for (int i = 0; i < productSlotsIndex.Length - products.items.Length + 1; i++) { productsItem = new List <Item>(); for (int k = 0; k < products.items.Length; k++) { if (gridSize.x * gridSize.y + k + i >= inv.slots.Count) { break; } if (inv.slots[gridSize.x * gridSize.y + k + i].item == products.items[k] || inv.slots[gridSize.x * gridSize.y + k + i].item == null) { productsItem.Add(inv.slots[gridSize.x * gridSize.y + k + i].item ?? products.items[k]); if (Enumerable.SequenceEqual(products.items, productsItem.ToArray())) { i = int.MaxValue - 1; break; } } } } } } int productIndex = 0; for (int i = 0; i < productSlotsIndex.Length; i++) { // If there is a item in the product slot it renders it and go to the next one if (inv.slots[productSlotsIndex[i]].HasItem) { // Iterating the childs for (int j = 0; j < slots[productSlotsIndex[i]].transform.childCount; j++) { if (slots[productSlotsIndex[i]].transform.GetChild(j).TryGetComponent(out Image image)) { // Having durability it renders the corresponding durability image if (inv.slots[productSlotsIndex[i]].ItemInstance.hasDurability) { if (inv.slots[productSlotsIndex[i]].ItemInstance.durabilityImages.Count > 0) { image.sprite = GetNearestSprite(inv, inv.slots[productSlotsIndex[i]].durability, productSlotsIndex[i]); image.color = new Color(1, 1, 1, 1); } else { image.sprite = inv.slots[productSlotsIndex[i]].ItemInstance.sprite; image.color = new Color(1, 1, 1, 1); } //productIndex++; } else { image.sprite = inv.slots[productSlotsIndex[i]].ItemInstance.sprite; image.color = new Color(1, 1, 1, 1); //productIndex++; } } else if (slots[productSlotsIndex[i]].transform.GetChild(j).TryGetComponent(out TextMeshProUGUI text) && showAmount && inv[productSlotsIndex[i]].ItemInstance.showAmount) { text.text = inv.slots[productSlotsIndex[i]].amount.ToString(); } else if (slots[productSlotsIndex[i]].transform.GetChild(j).TryGetComponent(out text)) { text.text = ""; } } if (products != null && products != CraftItemData.nullData) { if (inv[productSlotsIndex[i]].item == (products?.items[productIndex] ?? null) && inv[productSlotsIndex[i]].amount + (products?.amounts[productIndex] ?? int.MaxValue) <= inv[productSlotsIndex[i]].item?.maxAmount ) { productIndex++; } } //For click and drag slots[productSlotsIndex[i]].GetComponent <Button>().onClick.RemoveAllListeners(); var index = i; slots[productSlotsIndex[i]].GetComponent <Button>().onClick.AddListener(() => { if (products.items != null && products.items.Length <= productSlotsIndex.Length) { // If you dont want the other of the items in the product slot to matter this line should be different, It shoud check if the // List have the same items, not the same sequence. if (Enumerable.SequenceEqual(products.items, productsItem.ToArray())) { inv.CraftItem(new CraftItemData(pattern.ToArray(), amount.ToArray()), gridSize, true, true, productSlotsIndex.Length); } } }); } else if (products.items != null && products.items.Length <= productSlotsIndex.Length && productIndex < products.items.Length) { bool nextIndex = false; for (int j = 0; j < slots[productSlotsIndex[i]].transform.childCount; j++) { // Iterating the childs if (slots[productSlotsIndex[i]].transform.GetChild(j).TryGetComponent(out Image image)) { if (products.items[productIndex].hasDurability) { if (products.items[productIndex].durabilityImages.Count > 0) { image.sprite = GetNearestSprite(products.items[productIndex], products.items[productIndex].durability); image.color = new Color(1, 1, 1, .7f); } else { image.sprite = products.items[productIndex].sprite; image.color = new Color(1, 1, 1, .7f); } nextIndex = true; } else { image.sprite = products.items[productIndex].sprite; image.color = new Color(1, 1, 1, .7f); nextIndex = true; } } else if (slots[productSlotsIndex[i]].transform.GetChild(j).TryGetComponent(out TextMeshProUGUI text) && showAmount && products.items[productIndex].showAmount) { text.text = products.amounts[productIndex].ToString(); nextIndex = true; } else if (slots[productSlotsIndex[i]].transform.GetChild(j).TryGetComponent(out text)) { text.text = ""; nextIndex = true; } }
/** * * EnemyObjectが倒される時に呼ばれる。 * DropData.IDでCraftItemDataTableObjectのリストを検索して * PlayerDataに加える。 * */ public AbstractData GetDropItemData() { CraftItemData craftItem = CraftItemDataTableObject.Instance.Table.All.FirstOrDefault(itemData => itemData.ID == ID); return(craftItem); }