- 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
70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
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)
|
|
{
|
|
// 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;
|
|
}
|
|
|
|
public static bool ListContainsEquivalent(List<PickupItemData> list, PickupItemData item)
|
|
{
|
|
foreach (var entry in list)
|
|
{
|
|
if (AreEquivalent(entry, item))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|