public void OnDrop(PointerEventData eventData)
    {
        if (PlayerData.Slots[SlotID] == null)
        {
            return;
        }
        ItemInput droppedItem = eventData.pointerDrag.GetComponent <ItemInput>();
        SlotInput otherSlot   = droppedItem.GetComponent <ItemInput>().OriginalParent.GetComponent <SlotInput>();

        if (otherSlot == this || IsLocked || otherSlot.IsLocked)
        {
            return;
        }
        Debug.Assert(PlayerData.Slots[SlotID].transform.childCount == 0 || PlayerData.Slots[SlotID].transform.childCount == 1);
        if (!CraftingSlot && !otherSlot.CraftingSlot && !IsStructureSlot && !otherSlot.IsStructureSlot ||
            CraftingSlot && otherSlot.CraftingSlot ||
            IsStructureSlot && otherSlot.IsStructureSlot)
        {
            SlotToSlot(droppedItem, otherSlot);
        }
        else if (CraftingSlot && !otherSlot.CraftingSlot && !otherSlot.IsStructureSlot)
        {
            SlotCraftTransfer(droppedItem, otherSlot, PlayerData.CraftingInventory, PlayerData.NumCraftingSlots,
                              PlayerData.CraftingSlots, PlayerData.CraftingItems, Pd.GetInventory());
        }
        else if (!CraftingSlot && otherSlot.CraftingSlot && !otherSlot.IsStructureSlot)
        {
            SlotCraftTransfer(droppedItem, otherSlot, Pd.GetInventory(), PlayerData.NumItemSlots,
                              PlayerData.Slots, PlayerData.Items, PlayerData.CraftingInventory);
        }
        else if (Pd.CurrentTile.Structure.Value != null)
        {
            Dictionary <String, Item> structureInventory = Pd.CurrentTile.Structure.Value.GetComponent <StructureData>().Inventory;
            List <GameObject>         itContainer        = Pd.CurrentTile.Structure.Value.GetComponent <StructureData>().ItemContainer;
            if (IsStructureSlot && !otherSlot.IsStructureSlot)
            {
                SlotStructureTransfer(droppedItem, otherSlot, structureInventory, PlayerData.NumStructSlots, PlayerData.StructureSlots, itContainer, Pd.GetInventory());
            }
            else if (!IsStructureSlot && otherSlot.IsStructureSlot)
            {
                SlotStructureTransfer(droppedItem, otherSlot, Pd.GetInventory(), PlayerData.NumItemSlots, PlayerData.Slots, PlayerData.Items, structureInventory);
            }
        }
    }
 protected void SlotToSlot(ItemInput droppedItem, SlotInput otherSlot)
 {
     if (PlayerData.Slots[this.SlotID].transform.childCount == 1)
     {
         otherSlot.StoredItem      = this.StoredItem;
         otherSlot.StoredItem.Slot = otherSlot.SlotID;
         GameObject thisItem = PlayerData.Slots[this.SlotID].GetComponentInChildren <ItemInput>().gameObject;
         thisItem.transform.SetParent(otherSlot.transform);
         thisItem.transform.localPosition = Vector2.zero;
     }
     else
     {
         otherSlot.StoredItem.Slot = this.SlotID;
         otherSlot.StoredItem      = null;
     }
     droppedItem.transform.SetParent(this.transform);
     droppedItem.transform.localPosition = Vector2.zero;
     this.StoredItem      = droppedItem.GetComponent <ItemInput>().Item;
     this.StoredItem.Slot = this.SlotID;
 }
Exemple #3
0
    public void OnDrop(PointerEventData eventData)
    {
        ItemInput     droppedItem = eventData.pointerDrag.GetComponent <ItemInput>();
        SlotContainer otherSlot   = droppedItem.GetComponent <ItemInput>().SlotParent.GetComponent <SlotContainer>();

        if (otherSlot == this)
        {
            return;
        }
        //if (!CraftingSlot && !otherSlot.CraftingSlot || CraftingSlot && otherSlot.CraftingSlot) {
        SlotToSlot(droppedItem, otherSlot);

        /*} else if (CraftingSlot && !otherSlot.CraftingSlot) {
         *  SlotCraftTransfer(droppedItem, otherSlot, PlayerData.CraftingInventory, PlayerData.NumCraftingSlots,
         *      PlayerData.CraftingSlots, PlayerData.CraftingItems, Pd.GetInventory());
         * } else {
         *  SlotCraftTransfer(droppedItem, otherSlot, Pd.GetInventory(), PlayerData.NumItemSlots,
         *      PlayerData.Slots, PlayerData.Items, PlayerData.CraftingInventory);
         * }
         */
    }