DialogueComponent doodles

This commit is contained in:
2025-09-26 15:47:26 +02:00
parent f380b6fa54
commit abeb5060f9
35 changed files with 1025 additions and 373 deletions

View File

@@ -2,6 +2,7 @@
using UnityEngine;
using UnityEngine.Events;
using System; // for Action<T>
using Core; // register with ItemManager
namespace Interactions
{
@@ -174,5 +175,16 @@ namespace Interactions
Interactable.BroadcastInteractionComplete(false);
}
}
// Register with ItemManager when enabled
void Start()
{
ItemManager.Instance?.RegisterItemSlot(this);
}
void OnDestroy()
{
ItemManager.Instance?.UnregisterItemSlot(this);
}
}
}

View File

@@ -1,6 +1,7 @@
using Input;
using UnityEngine;
using System; // added for Action<T>
using Core; // register with ItemManager
namespace Interactions
{
@@ -12,6 +13,9 @@ namespace Interactions
protected Interactable Interactable;
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;
@@ -34,6 +38,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>
@@ -44,6 +56,9 @@ namespace Interactions
Interactable.interactionStarted.RemoveListener(OnInteractionStarted);
Interactable.characterArrived.RemoveListener(OnCharacterArrived);
}
// Unregister from ItemManager
ItemManager.Instance?.UnregisterPickup(this);
}
#if UNITY_EDITOR
@@ -96,9 +111,10 @@ namespace Interactions
bool wasPickedUp = (combinationResult == FollowerController.CombinationResult.NotApplicable);
Interactable.BroadcastInteractionComplete(wasPickedUp);
// Invoke native C# event when the item was picked up successfully
// Update pickup state and invoke event when the item was picked up successfully
if (wasPickedUp)
{
isPickedUp = true;
OnItemPickedUp?.Invoke(itemData);
}
}

View File

@@ -1,18 +1,58 @@
using UnityEngine;
using System.Collections.Generic;
using System;
[CreateAssetMenu(fileName = "PickupItemData", menuName = "Game/Pickup Item Data")]
public class PickupItemData : ScriptableObject
{
[SerializeField] private string _itemId;
public string itemName;
[TextArea]
public string description;
public Sprite mapSprite;
// Read-only property for itemId
public string itemId => _itemId;
// Auto-generate ID on creation or validation
void OnValidate()
{
// Only generate if empty
if (string.IsNullOrEmpty(_itemId))
{
_itemId = GenerateItemId();
#if UNITY_EDITOR
// Mark the asset as dirty to ensure the ID is saved
UnityEditor.EditorUtility.SetDirty(this);
#endif
}
}
private string GenerateItemId()
{
// Use asset name as the basis for the ID to keep it somewhat readable
string baseName = name.Replace(" ", "").ToLowerInvariant();
// Add a unique suffix based on a GUID
string uniqueSuffix = Guid.NewGuid().ToString().Substring(0, 8);
return $"{baseName}_{uniqueSuffix}";
}
// Method to manually regenerate ID if needed (for editor scripts)
public void RegenerateId()
{
_itemId = GenerateItemId();
}
public static bool AreEquivalent(PickupItemData a, PickupItemData b)
{
if (ReferenceEquals(a, b)) return true;
if (a is null || b is null) return false;
// First compare by itemId if available
if (!string.IsNullOrEmpty(a.itemId) && !string.IsNullOrEmpty(b.itemId))
return a.itemId == b.itemId;
// Compare by itemName as a fallback
return a.itemName == b.itemName;
}