Commit
Major refactoring & use item feature
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using InventorySystem; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class BaseInventoryItem | ||
{ | ||
|
||
} | ||
public interface IUseable | ||
{ | ||
void Use(InventorySlot slot); | ||
} | ||
public interface IEquippable | ||
{ | ||
void Equip(InventorySlot slot); | ||
void Unequip(InventorySlot slot); | ||
} | ||
public interface IDroppable | ||
{ | ||
void Drop(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using InventorySystem; | ||
using UnityEngine; | ||
|
||
public class CollectibleObject : MonoBehaviour, ICollectible | ||
{ | ||
public ItemDataSO itemData; | ||
public virtual void Collect(Collector collector) | ||
{ | ||
AddToInventory(collector); | ||
Destroy(gameObject); | ||
} | ||
protected virtual void AddToInventory(Collector collector) | ||
{ | ||
collector.Inventory.AddItem(itemData, 1); | ||
collector.OnItemCollected?.Invoke(itemData); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using InventorySystem; | ||
using UnityEngine; | ||
|
||
public class CrystalItem : BaseInventoryItem, IUseable | ||
{ | ||
private GameObject owner; | ||
public CrystalItem(GameObject owner) | ||
{ | ||
this.owner = owner; | ||
} | ||
public void Use(InventorySlot slot) | ||
{ | ||
slot.RemoveFromStack(1); | ||
Debug.Log("Crystal used"); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class ItemDB : ScriptableObject | ||
{ | ||
public static ItemDataSO[] allItems; | ||
|
||
public const int COIN = 0, CRYSTAL = 1; | ||
|
||
public static BaseInventoryItem GetItem(int id, GameObject owner) | ||
{ | ||
switch (id) | ||
{ | ||
case CRYSTAL: | ||
return new CrystalItem(owner); | ||
default: | ||
return null; | ||
} | ||
} | ||
public static ItemDataSO GetItemData(int id) | ||
{ | ||
return allItems[id]; | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace InventorySystem | ||
{ | ||
public class MouseDragItem : MonoBehaviour | ||
{ | ||
private Image img; | ||
private TextMeshProUGUI stackDisplay; | ||
public UI_InventorySlot from; | ||
private void Awake() | ||
{ | ||
img = GetComponentInChildren<Image>(); | ||
stackDisplay = GetComponentInChildren<TextMeshProUGUI>(); | ||
} | ||
public void SetItem(UI_InventorySlot from) | ||
{ | ||
this.from = from; | ||
img.sprite = from.GetItem().itemData.sprite; | ||
int stackSize = from.GetItem().stackSize; | ||
stackDisplay.text = stackSize > 1 ? stackSize.ToString() : ""; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.