コード例 #1
0
 // Item hinzufiegen Funktion
 // WENN die maxSize vom item 1 ist, DANN Platziere das Item im Shop
 public bool AddItem(Item item)
 {
     if (item.maxSize == 1)
     {
         PlaceEmpty(item);
         return(true);
     }
     else
     {
         // ANSONSTEN gehe jeden Slot der Liste durch und ueberpruefe ihn
         foreach (GameObject slot in allSlots)
         {
             ShopSlot tmp = slot.GetComponent <ShopSlot>();                // Referenz auf das ShopSlotscript
             // WENN der Slot nicht leer ist dann ueberpruefe:
             if (!tmp.IsEmpty)
             {
                 // OB das Item in dem Slot vom gleichen Item ist, wie das, was hinzugefuegt werden soll
                 // UND ob der Slot zum Stacken verfuegbar ist
                 // DANN fuege das Item hinzu
                 if (tmp.CurrentItem.type == item.type && tmp.IsAvailable)
                 {
                     tmp.AddItem(item);
                     return(true);
                 }
             }
         }
         // WENN das Item nicht gestackt werden konnte
         // DANN soll das item einfach platziert werden, sofern es mindestens einen leeren Slot gibt
         if (emptySlot > 0)
         {
             PlaceEmpty(item);
         }
     }
     return(false);
 }
コード例 #2
0
    // FUnktion: Places an item on an empty slot
    private bool PlaceEmpty(Item item)
    {
        // If we have atleast 1 empty slot
        if (emptySlot > 0)
        {
            foreach (GameObject slot in allSlots)                       //Runs through all slots
            {
                ShopSlot tmp = slot.GetComponent <ShopSlot>();          //Creates a reference to the slot

                if (tmp.IsEmpty)                                        //If the slot is empty
                {
                    tmp.AddItem(item);                                  //Adds the item
                    emptySlot--;                                        //Reduces the number of empty slots
                    return(true);
                }
            }
        }
        return(false);        // Ansonsten false
    }