public void OnBeginDrag(PointerEventData eventData) { Debug.Log(slot); Debug.Log(inv.slotCount); if (item != null) { for (int x = 0; x < amount; x++) { if (slot < inv.slotCount) { persistentInventory.removeItem(item.ID, slot); } else if (slot >= inv.slotCount) { Debug.Log(".."); persistentInventory.removeEquipment(slot - inv.slotCount, amount); } } offset = eventData.position - new Vector2(this.transform.position.x, this.transform.position.y); this.transform.SetParent(this.transform.parent.parent); this.transform.position = eventData.position - offset; GetComponent <CanvasGroup>().blocksRaycasts = false; } }
///<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); } } }