55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Connects FishingGameManager's caught-item event to FishingInventory.
|
|
/// Add this to the same prefab/root object, then assign Game Manager and Inventory.
|
|
/// </summary>
|
|
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<FishingGameManager>();
|
|
|
|
if (inventory == null)
|
|
inventory = GetComponentInParent<FishingInventory>();
|
|
|
|
if (inventory == null && gameManager != null)
|
|
inventory = gameManager.GetComponentInChildren<FishingInventory>(true);
|
|
}
|
|
|
|
private void OnItemCaught(FishingItemType itemType, int amount)
|
|
{
|
|
if (inventory == null)
|
|
return;
|
|
|
|
inventory.AddItem(itemType, amount);
|
|
}
|
|
}
|