53 lines
1.2 KiB
C#
53 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public enum ItemType
|
|
{
|
|
Block,
|
|
Weapon,
|
|
Armor,
|
|
Consumable,
|
|
Tool,
|
|
Material
|
|
}
|
|
|
|
[CreateAssetMenu(fileName = "NewItem", menuName = "Inventory/Item")]
|
|
public class ItemData : ScriptableObject
|
|
{
|
|
public string id;
|
|
public string itemName;
|
|
public string description;
|
|
public ItemType type;
|
|
public GameObject modelPrefab;
|
|
public Sprite icon;
|
|
public int maxStack = 64;
|
|
public bool isCraftable;
|
|
public CraftingRecipe craftingRecipe;
|
|
|
|
[Header("Item Properties")]
|
|
public float weight = 1f;
|
|
public int value = 1;
|
|
public bool isDroppable = true;
|
|
public bool isStackable = true;
|
|
|
|
[System.Serializable]
|
|
public class CraftingRecipe
|
|
{
|
|
public string[] ingredients;
|
|
public int[] amounts;
|
|
public string resultId;
|
|
public int resultAmount = 1;
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
if (string.IsNullOrEmpty(id))
|
|
{
|
|
id = System.Guid.NewGuid().ToString();
|
|
}
|
|
}
|
|
|
|
public static ItemData FromJson(string json) => JsonUtility.FromJson<ItemData>(json);
|
|
public string ToJson() => JsonUtility.ToJson(this, true);
|
|
|
|
public bool CanStackWith(ItemData other) => other != null && id == other.id && isStackable;
|
|
} |