public void OnDrop(PointerEventData eventData) { SlotItemData droppedItemData = eventData.pointerDrag.GetComponent <SlotItemData>(); DropType dropType; if (droppedItemData.isInventoryItem) { if (this.isInventorySlot) { if (this.isEmpty()) { dropType = DropType.Move; } else { dropType = DropType.Swap; } } else { if (this.isEmpty()) { dropType = DropType.Deposit; } else { dropType = DropType.DepositAndLoot; } } } else { if (this.isInventorySlot) { if (this.isEmpty()) { dropType = DropType.Loot; } else { dropType = DropType.DepositAndLoot; } } else { if (this.isEmpty()) { dropType = DropType.Move; } else { dropType = DropType.Swap; } } } PerformDropOperation(this.item, droppedItemData, dropType); }
private void SwapItems(SlotItemData slotItem, SlotItemData droppedItem) { Item droppedItemtemp = droppedItem.item; int droppedAmounttemp = droppedItem.amount; droppedItem.SetItem(slotItem.item, slotItem.amount); slotItem.SetItem(droppedItemtemp, droppedAmounttemp); }
private void PerformDropOperation(SlotItemData slotItem, SlotItemData droppedItem, DropType dropType) { switch (dropType) { case DropType.Move: MoveItem(droppedItem); break; case DropType.Swap: SwapItems(slotItem, droppedItem); break; case DropType.Deposit: RepeatItemOperation(InventoryController.instance.RemoveItem, droppedItem.item, droppedItem.amount); RepeatItemOperation(ContainerController.Instance.DepositWithoutUI, droppedItem.item, droppedItem.amount); MoveItem(droppedItem); break; case DropType.Loot: RepeatItemOperation(ContainerController.Instance.Withdraw, droppedItem.item, droppedItem.amount); RepeatItemOperation(InventoryController.instance.AddItem, droppedItem.item, droppedItem.amount); MoveItem(droppedItem); break; case DropType.DepositAndLoot: if (this.isInventorySlot) { RepeatItemOperation(ContainerController.Instance.Withdraw, droppedItem.item, droppedItem.amount); RepeatItemOperation(InventoryController.instance.AddItem, droppedItem.item, droppedItem.amount); RepeatItemOperation(InventoryController.instance.RemoveItem, slotItem.item, slotItem.amount); RepeatItemOperation(ContainerController.Instance.DepositWithoutUI, slotItem.item, slotItem.amount); } else { RepeatItemOperation(ContainerController.Instance.Withdraw, slotItem.item, slotItem.amount); RepeatItemOperation(InventoryController.instance.AddItem, slotItem.item, slotItem.amount); RepeatItemOperation(InventoryController.instance.RemoveItem, droppedItem.item, droppedItem.amount); RepeatItemOperation(ContainerController.Instance.DepositWithoutUI, droppedItem.item, droppedItem.amount); } SwapItems(slotItem, droppedItem); break; } }
public void ClearContent() { this.item.remove(); this.item = null; }
public void SetContent(Item item, int amount) { this.item = Instantiate(sltoItemPrefab, gameObject.transform); this.item.isInventoryItem = isInventorySlot; this.item.SetItem(item, amount); }
private void Awake() { sltoItemPrefab = Resources.Load <SlotItemData>("UI/Item"); }
private void MoveItem(SlotItemData droppedItem) { SetContent(droppedItem.item, droppedItem.amount); droppedItem.remove(); }