Update the cards to pull in from addressables to wokr in build, remove erronous code preventing building
This commit is contained in:
@@ -57,5 +57,19 @@ namespace AppleHills.Data.CardSystem
|
||||
return Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is CardDefinition other)
|
||||
{
|
||||
return string.Equals(Id, other.Id, StringComparison.Ordinal);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id != null ? Id.GetHashCode() : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,17 +23,13 @@ namespace Data.CardSystem
|
||||
|
||||
[Header("Card Collection")]
|
||||
[SerializeField] private List<CardDefinition> availableCards = new List<CardDefinition>();
|
||||
|
||||
[Header("Auto-Loading Configuration")]
|
||||
[SerializeField] private bool autoLoadCardDefinitions = true;
|
||||
[SerializeField] private string cardDataPath = "Data/Cards";
|
||||
|
||||
|
||||
// Runtime data - will be serialized for save/load
|
||||
[SerializeField] private CardInventory playerInventory = new CardInventory();
|
||||
|
||||
|
||||
// Dictionary to quickly look up card definitions by ID
|
||||
private Dictionary<string, CardDefinition> _definitionLookup = new Dictionary<string, CardDefinition>();
|
||||
|
||||
|
||||
// Event callbacks using System.Action
|
||||
public event Action<List<CardData>> OnBoosterOpened;
|
||||
public event Action<CardData> OnCardCollected;
|
||||
@@ -43,23 +39,19 @@ namespace Data.CardSystem
|
||||
private void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
|
||||
// Auto-load card definitions if enabled
|
||||
if (autoLoadCardDefinitions)
|
||||
{
|
||||
LoadCardDefinitionsFromFolder();
|
||||
}
|
||||
|
||||
// Register for post-boot initialization
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
// Load card definitions from Addressables
|
||||
LoadCardDefinitionsFromAddressables();
|
||||
|
||||
// Build lookup dictionary
|
||||
BuildDefinitionLookup();
|
||||
|
||||
// Register for post-boot initialization
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
// Initialize any dependencies that require other services to be ready
|
||||
Logging.Debug("[CardSystemManager] Post-boot initialization complete");
|
||||
}
|
||||
|
||||
@@ -67,46 +59,35 @@ namespace Data.CardSystem
|
||||
{
|
||||
_isQuitting = true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Loads all card definitions from the specified folder
|
||||
/// Loads all card definitions from Addressables using the "BlokkemonCard" label
|
||||
/// </summary>
|
||||
private void LoadCardDefinitionsFromFolder()
|
||||
private async void LoadCardDefinitionsFromAddressables()
|
||||
{
|
||||
// Initialize list if needed
|
||||
if (availableCards == null)
|
||||
availableCards = new List<CardDefinition>();
|
||||
// Load by label instead of group name for better flexibility
|
||||
var handle = UnityEngine.AddressableAssets.Addressables.LoadResourceLocationsAsync(new string[] { "BlokkemonCard" }, UnityEngine.AddressableAssets.Addressables.MergeMode.Union);
|
||||
await handle.Task;
|
||||
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
availableCards = new List<CardDefinition>();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// In editor we can load assets directly from the project folder
|
||||
string folderPath = "Assets/" + cardDataPath;
|
||||
string[] guids = AssetDatabase.FindAssets("t:CardDefinition", new[] { folderPath });
|
||||
|
||||
List<CardDefinition> loadedDefinitions = new List<CardDefinition>();
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
CardDefinition cardDef = AssetDatabase.LoadAssetAtPath<CardDefinition>(assetPath);
|
||||
if (cardDef != null && !string.IsNullOrEmpty(cardDef.Id))
|
||||
var locations = handle.Result;
|
||||
var loadedIds = new HashSet<string>();
|
||||
foreach (var loc in locations)
|
||||
{
|
||||
loadedDefinitions.Add(cardDef);
|
||||
var cardHandle = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync<CardDefinition>(loc);
|
||||
await cardHandle.Task;
|
||||
if (cardHandle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
var cardDef = cardHandle.Result;
|
||||
if (cardDef != null && !string.IsNullOrEmpty(cardDef.Id) && !loadedIds.Contains(cardDef.Id))
|
||||
{
|
||||
availableCards.Add(cardDef);
|
||||
loadedIds.Add(cardDef.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replace the existing list with loaded definitions
|
||||
availableCards = loadedDefinitions;
|
||||
#else
|
||||
// In build, load from Resources folder
|
||||
CardDefinition[] resourceCards = Resources.LoadAll<CardDefinition>(cardDataPath);
|
||||
if (resourceCards != null && resourceCards.Length > 0)
|
||||
{
|
||||
availableCards = resourceCards.Where(card => card != null && !string.IsNullOrEmpty(card.Id)).ToList();
|
||||
}
|
||||
#endif
|
||||
|
||||
Logging.Debug($"[CardSystemManager] Loaded {availableCards.Count} card definitions from {cardDataPath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user