示例#1
0
 public void OnEndDrag(PointerEventData eventData)
 {
     this.transform.SetParent(inv.slots[slot].transform);
     this.transform.position = inv.slots[slot].transform.position;
     for (int x = 0; x < amount; x++)
     {
         if (slot < inv.slotCount)
         {
             persistentInventory.addItem(item.ID, slot);
         }
         else
         {
             persistentInventory.addEquipment(item.ID, amount, slot - inv.slotCount);
         }
     }
     GetComponent <CanvasGroup>().blocksRaycasts = true;
 }
示例#2
0
    ///<summary>
    /// Loads te inventory including the saved items
    private void LoadInventory()
    {
        PersistentInventoryScript inventory = GameObject.FindObjectOfType <PersistentInventoryScript>();

        for (int i = 0; i < inventory.equipmentList.GetLength(0); i++)
        {
            for (int inventorySlot = 0; inventorySlot < inventory.equipmentList.GetLength(1); inventorySlot++)
            {
                inventory.removeEquipment(inventorySlot, 0);
            }

            int slot   = PlayerPrefs.GetInt("save_inventory_equipment_" + i + "_slot");
            int id     = PlayerPrefs.GetInt("save_inventory_equipment_" + i + "_id");
            int number = PlayerPrefs.GetInt("save_inventory_equipment_" + i + "_number");

            if (slot == 1)
            {
                // Ranged weapon
                number += 4;
            }
            if (slot == 0)
            {
                // Melee weapon
                number += 5;
            }

            inventory.addEquipment(id, number, slot);
        }

        for (int j = 0; j < inventory.itemList.GetLength(0); j++)
        {
            int slot   = PlayerPrefs.GetInt("save_inventory_items_" + j + "_slot");
            int id     = PlayerPrefs.GetInt("save_inventory_items_" + j + "_id");
            int number = PlayerPrefs.GetInt("save_inventory_items_" + j + "_number");

            for (int num = 0; num <= number; num++)
            {
                inventory.removeItem(0, j);
                inventory.addItem(id, slot);
            }
        }
    }