Create a simple dialogue authoring system, tied into our items (#10)
- Editor dialogue graph - Asset importer for processing the graph into runtime data - DialogueComponent that steers the dialogue interactions - DialogueCanbas with a scalable speech bubble to display everything - Brief README overview of the system Co-authored-by: AlexanderT <alexander@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #10
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Input;
|
||||
using UnityEngine;
|
||||
using System; // added for Action<T>
|
||||
using Core; // register with ItemManager
|
||||
|
||||
namespace Interactions
|
||||
{
|
||||
@@ -12,6 +14,15 @@ namespace Interactions
|
||||
private PlayerTouchController _playerRef;
|
||||
protected FollowerController FollowerController;
|
||||
|
||||
// Track if the item has been picked up
|
||||
public bool isPickedUp { get; private set; }
|
||||
|
||||
// Event: invoked when the item was picked up successfully
|
||||
public event Action<PickupItemData> OnItemPickedUp;
|
||||
|
||||
// Event: invoked when this item is successfully combined with another
|
||||
public event Action<PickupItemData, PickupItemData, PickupItemData> OnItemsCombined;
|
||||
|
||||
/// <summary>
|
||||
/// Unity Awake callback. Sets up icon, interactable, and event handlers.
|
||||
/// </summary>
|
||||
@@ -30,6 +41,14 @@ namespace Interactions
|
||||
ApplyItemData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register with ItemManager on Start
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
ItemManager.Instance?.RegisterPickup(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity OnDestroy callback. Cleans up event handlers.
|
||||
/// </summary>
|
||||
@@ -40,6 +59,9 @@ namespace Interactions
|
||||
Interactable.interactionStarted.RemoveListener(OnInteractionStarted);
|
||||
Interactable.characterArrived.RemoveListener(OnCharacterArrived);
|
||||
}
|
||||
|
||||
// Unregister from ItemManager
|
||||
ItemManager.Instance?.UnregisterPickup(this);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -81,15 +103,48 @@ namespace Interactions
|
||||
|
||||
protected virtual void OnCharacterArrived()
|
||||
{
|
||||
Debug.Log("[Pickup] OnCharacterArrived");
|
||||
|
||||
var combinationResult = FollowerController.TryCombineItems(this, out var combinationResultItem);
|
||||
if (combinationResultItem != null)
|
||||
{
|
||||
Interactable.BroadcastInteractionComplete(true);
|
||||
|
||||
// Fire the combination event when items are successfully combined
|
||||
if (combinationResult == FollowerController.CombinationResult.Successful)
|
||||
{
|
||||
var resultPickup = combinationResultItem.GetComponent<Pickup>();
|
||||
if (resultPickup != null && resultPickup.itemData != null)
|
||||
{
|
||||
// Get the combined item data
|
||||
var resultItemData = resultPickup.itemData;
|
||||
var heldItem = FollowerController.GetHeldPickupObject();
|
||||
|
||||
if (heldItem != null)
|
||||
{
|
||||
var heldPickup = heldItem.GetComponent<Pickup>();
|
||||
if (heldPickup != null && heldPickup.itemData != null)
|
||||
{
|
||||
// Trigger the combination event
|
||||
OnItemsCombined?.Invoke(itemData, heldPickup.itemData, resultItemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FollowerController?.TryPickupItem(gameObject, itemData);
|
||||
Interactable.BroadcastInteractionComplete(combinationResult == FollowerController.CombinationResult.NotApplicable);
|
||||
bool wasPickedUp = (combinationResult == FollowerController.CombinationResult.NotApplicable);
|
||||
Interactable.BroadcastInteractionComplete(wasPickedUp);
|
||||
|
||||
// Update pickup state and invoke event when the item was picked up successfully
|
||||
if (wasPickedUp)
|
||||
{
|
||||
isPickedUp = true;
|
||||
OnItemPickedUp?.Invoke(itemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user