-
-
Save jordanske/a4a4dd51015c1e5daabc5b1e07dabdad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Events; | |
public abstract class Interactable : MonoBehaviour | |
{ | |
[SerializeField] | |
protected UnityEvent OnInteractEvent; | |
public abstract void Interact(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
[AddComponentMenu("Redemption/Interactables/Pickup")] | |
public class InteractablePickup : Interactable | |
{ | |
private bool isInteracting; | |
[SerializeField] | |
private InventoryItem inventoryItem; | |
public void Start() | |
{ | |
isInteracting = false; | |
} | |
public override void Interact() | |
{ | |
if(isInteracting) { | |
return; | |
} | |
OnInteractEvent.Invoke(); | |
Debug.Log("Pickup item : " + inventoryItem.name); | |
InventoryManager.instance.AddItem(inventoryItem); | |
Destroy(gameObject); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[CreateAssetMenu(fileName="InventoryItem", menuName="Redemption/Inventory Item")] | |
public class InventoryItem : ScriptableObject { | |
[SerializeField] | |
[Tooltip("Item icon that is shown in the inventory")] | |
private Sprite itemIcon; | |
[SerializeField] | |
[Tooltip("Item name that is shown in the tooltip")] | |
private string itemName; | |
[SerializeField] | |
[TextArea(3, 10)] | |
[Tooltip("Item description that is shown in the tooltip")] | |
private string itemDescription; | |
[SerializeField] | |
[Tooltip("Gameobject to show when item is held in hand")] | |
private GameObject itemHandPrefab; | |
public Sprite ItemIcon { | |
get { | |
return itemIcon; | |
} | |
} | |
public string ItemName { | |
get { | |
return itemName; | |
} | |
} | |
public string ItemDescription { | |
get { | |
return itemDescription; | |
} | |
} | |
public GameObject ItemHandPrefab { | |
get { | |
return itemHandPrefab; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class InventoryManager : MonoBehaviour | |
{ | |
public static InventoryManager instance; | |
[SerializeField] | |
private GameObject inventory; | |
[SerializeField] | |
private GameObject itemSlotPrefab; | |
private int inventorySize; | |
[SerializeField] | |
private int inventoryColumns; | |
[SerializeField] | |
private int inventoryRows; | |
//[SerializeField] | |
private Image[] itemImages; | |
[SerializeField] | |
private InventoryItem[] items; | |
private bool inventoryActive; | |
public bool InventoryActive { | |
get { | |
return inventoryActive; | |
} | |
} | |
void Start () | |
{ | |
inventoryActive = false; | |
inventory.SetActive(false); | |
instance = this; | |
} | |
void Update() | |
{ | |
} | |
public void AddItem(InventoryItem item) | |
{ | |
for(int i = 0; i < inventorySize; i++) { | |
if(items[i] == null) { | |
items[i] = item; | |
itemImages[i].sprite = item.ItemIcon; | |
itemImages[i].enabled = true; | |
return; | |
} | |
} | |
} | |
public void RemoveItem(InventoryItem item) | |
{ | |
for(int i = 0; i < inventorySize; i++) { | |
if(items[i] == item) { | |
items[i] = null; | |
itemImages[i].sprite = null; | |
itemImages[i].enabled = false; | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment