51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using TRInventoryUpdatable;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace TRInventoryUpdatable
|
|
{
|
|
[ExecuteInEditMode]
|
|
public class RegularPickableItem : MonoBehaviour, IPickable
|
|
{
|
|
public string ItemName;
|
|
public string itemNameInInventory;
|
|
public string ItemModelNameInInventoryManager;
|
|
public bool AddToKeysAndItemsInventory = true;
|
|
public UnityEvent AfterPickupEvent;
|
|
|
|
private void OnValidate()
|
|
{
|
|
// Automatically set GameObjectID based on the GameObject's name in the Editor
|
|
if (string.IsNullOrEmpty(ItemName))
|
|
{
|
|
ItemName = gameObject.name;
|
|
}
|
|
}
|
|
|
|
public void Pickup()
|
|
{
|
|
//Add to ring inventory the new item if it doesn't exist.
|
|
if (InventoryManager.GetInstance().AccessFieldInInventoryManager(ItemModelNameInInventoryManager).activeSelf == false)
|
|
{
|
|
InventoryManager.GetInstance().SaveTemporarilyRegularItemsData(ItemName, itemNameInInventory, ItemModelNameInInventoryManager, AddToKeysAndItemsInventory);
|
|
if (AddToKeysAndItemsInventory)
|
|
{
|
|
RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().AccessFieldInInventoryManager(ItemModelNameInInventoryManager).transform);
|
|
}
|
|
else
|
|
{
|
|
RingInventory.GetInstance().AddItemToCollectablesInventory(InventoryManager.GetInstance().AccessFieldInInventoryManager(ItemModelNameInInventoryManager).transform);
|
|
}
|
|
print("Is reconstructing inventory");
|
|
if (AfterPickupEvent != null)
|
|
{
|
|
AfterPickupEvent.Invoke();
|
|
}
|
|
InventoryManager.GetInstance().AccessFieldInInventoryManager(ItemModelNameInInventoryManager).SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
}
|