using UnityEngine;
///
/// Connects FishingGameManager's caught-item event to FishingInventory.
/// Add this to the same prefab/root object, then assign Game Manager and Inventory.
///
public class FishingInventoryBinder : MonoBehaviour
{
[SerializeField] private FishingGameManager gameManager;
[SerializeField] private FishingInventory inventory;
private void Reset()
{
AutoBind();
}
private void Awake()
{
AutoBind();
}
private void OnEnable()
{
if (gameManager != null)
gameManager.ItemCaught += OnItemCaught;
}
private void OnDisable()
{
if (gameManager != null)
gameManager.ItemCaught -= OnItemCaught;
}
[ContextMenu("Auto Bind Inventory Binder")]
public void AutoBind()
{
if (gameManager == null)
gameManager = GetComponentInParent();
if (inventory == null)
inventory = GetComponentInParent();
if (inventory == null && gameManager != null)
inventory = gameManager.GetComponentInChildren(true);
}
private void OnItemCaught(FishingItemType itemType, int amount)
{
if (inventory == null)
return;
inventory.AddItem(itemType, amount);
}
}