108 lines
1.8 KiB
C#
108 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
// Example: InventoryItem.cs
|
|
|
|
[CreateAssetMenu(fileName = "InventorySlot", menuName = "Game Data/Game Slot")]
|
|
public class InventorySlot : ScriptableObject
|
|
{
|
|
public GameItem item;
|
|
public int quantity;
|
|
public int slotId = -1;
|
|
|
|
//todo: prevent item from being used if locked
|
|
public int isLocked;
|
|
|
|
|
|
public InventorySlot()
|
|
{
|
|
item = null;
|
|
quantity = 0;
|
|
}
|
|
|
|
public InventorySlot(GameItem item)
|
|
{
|
|
this.item = item;
|
|
quantity = 1;
|
|
}
|
|
|
|
public void Initialize(GameItem gameItem, int qty)
|
|
{
|
|
item = gameItem;
|
|
quantity = qty;
|
|
}
|
|
|
|
public void AssignGameItem(GameItem gameItem, int qty = 1)
|
|
{
|
|
item = gameItem;
|
|
quantity = qty;
|
|
}
|
|
|
|
|
|
public void AddQuantity(int amount)
|
|
{
|
|
quantity += amount;
|
|
}
|
|
|
|
public void RemoveQuantity(int amount)
|
|
{
|
|
quantity -= amount;
|
|
}
|
|
|
|
public void SetQuantity(int amount)
|
|
{
|
|
quantity = amount;
|
|
}
|
|
|
|
public void UseItem()
|
|
{
|
|
if (item.isConsumable) RemoveQuantity(1);
|
|
}
|
|
|
|
public void DropItem()
|
|
{
|
|
if (item.isDroppable) RemoveQuantity(1);
|
|
}
|
|
|
|
public void DestroyItem()
|
|
{
|
|
if (item.isDestroyable) RemoveQuantity(1);
|
|
}
|
|
|
|
public void SellItem()
|
|
{
|
|
if (item.isSellable) RemoveQuantity(1);
|
|
}
|
|
|
|
public bool IsEmpty()
|
|
{
|
|
return item == null;
|
|
}
|
|
|
|
public void AddItem(GameItem newItem)
|
|
{
|
|
item = newItem;
|
|
quantity = 1;
|
|
}
|
|
|
|
|
|
public Sprite GetIcon()
|
|
{
|
|
return item.icon;
|
|
}
|
|
|
|
public string GetItemName()
|
|
{
|
|
if (item == null)
|
|
{
|
|
Debug.Log("Item is null");
|
|
return null;
|
|
}
|
|
|
|
return item.itemName;
|
|
}
|
|
|
|
public float GetItemValue()
|
|
{
|
|
return item.itemValue;
|
|
}
|
|
} |