Update the cards to pull in from addressables to wokr in build, remove erronous code preventing building

This commit is contained in:
Michal Adam Pikulski
2025-10-21 10:05:49 +02:00
parent d1792014db
commit af77e07f99
20 changed files with 531 additions and 84 deletions

View File

@@ -13,6 +13,7 @@ MonoBehaviour:
m_Name: AddressableAssetGroupSortSettings
m_EditorClassIdentifier:
sortOrder:
- 0d5d36d6da388314b92b9c6967d23f39
- 75e1f68b7bf77f34f8ad4aeab74d4244
- eb8a37153d819c44194f7ce97570a3d3
- 2b3d7cefec0915e42be04aebf0400a56

View File

@@ -15,7 +15,7 @@ MonoBehaviour:
m_DefaultGroup: 6f3207429a65b3e4b83935ac19791077
m_currentHash:
serializedVersion: 2
Hash: 58bff643ea54adc47e3181c09b68468c
Hash: 00000000000000000000000000000000
m_OptimizeCatalogSize: 0
m_BuildRemoteCatalog: 0
m_CatalogRequestsTimeout: 0
@@ -60,6 +60,7 @@ MonoBehaviour:
m_BuildAddressablesWithPlayerBuild: 0
m_overridePlayerVersion: '[UnityEditor.PlayerSettings.bundleVersion]'
m_GroupAssets:
- {fileID: 11400000, guid: 124f05e204489af49943d7fc039640a4, type: 2}
- {fileID: 11400000, guid: efe7e1728e73e9546ac5dfee2eff524f, type: 2}
- {fileID: 11400000, guid: 6e4927e7e19eef34b93dc2baa9e9e8e2, type: 2}
- {fileID: 11400000, guid: 4186fdd83f912a14b97fbf4644266b0d, type: 2}
@@ -104,6 +105,7 @@ MonoBehaviour:
m_LabelTable:
m_LabelNames:
- default
- BlokkemonCard
m_SchemaTemplates: []
m_GroupTemplateObjects:
- {fileID: 11400000, guid: ea0a5135f5495eb4693a23d94617fe92, type: 2}

View File

@@ -0,0 +1,71 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bbb281ee3bf0b054c82ac2347e9e782c, type: 3}
m_Name: BlokkemonCards
m_EditorClassIdentifier: Unity.Addressables.Editor::UnityEditor.AddressableAssets.Settings.AddressableAssetGroup
m_GroupName: BlokkemonCards
m_GUID: 0d5d36d6da388314b92b9c6967d23f39
m_SerializeEntries:
- m_GUID: 28dbfbd7a6b2cd84b8274bd1126b220b
m_Address: Assets/Data/Cards/Card_Test example card 2 (Copy).asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 4b9c8b6ca63744a44acfe49ebe337619
m_Address: Assets/Data/Cards/Card_New Card 2.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 5d8121cdf52bfe9488b40ed22d649209
m_Address: Assets/Data/Cards/Card_New Card 1.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 6afed7a67f64404418f905e7808bf5cb
m_Address: Assets/Data/Cards/Card_Test example card 3 (Copy).asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 8f02c3699de87014bac8c03b96772a4b
m_Address: Assets/Data/Cards/Card_Test example card (Copy).asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 8fdeae7881d130f408e0f31c101ab41f
m_Address: Assets/Data/Cards/Card_Test example card (Copy) 1.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 91031de62f795884e8e2ccbaebeebf9b
m_Address: Assets/Data/Cards/Card_New Card.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: dec49537f6ae6d241acf8275eaa6c653
m_Address: Assets/Data/Cards/Card_Test example card 2 (Copy) 1.asset
m_ReadOnly: 0
m_SerializedLabels:
- BlokkemonCard
FlaggedDuringContentUpdateRestriction: 0
m_ReadOnly: 0
m_Settings: {fileID: 11400000, guid: 11da9bb90d9dd5848b4f7629415a6937, type: 2}
m_SchemaSet:
m_Schemas:
- {fileID: 11400000, guid: a0affac7520cbac4283e5d0fe0c0d28a, type: 2}
- {fileID: 11400000, guid: ca0e74b531acf5449a15f65103061116, type: 2}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 124f05e204489af49943d7fc039640a4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e5d17a21594effb4e9591490b009e7aa, type: 3}
m_Name: BlokkemonCards_BundledAssetGroupSchema
m_EditorClassIdentifier: Unity.Addressables.Editor::UnityEditor.AddressableAssets.Settings.GroupSchemas.BundledAssetGroupSchema
m_Group: {fileID: 11400000, guid: 124f05e204489af49943d7fc039640a4, type: 2}
m_InternalBundleIdMode: 1
m_Compression: 1
m_IncludeAddressInCatalog: 1
m_IncludeGUIDInCatalog: 1
m_IncludeLabelsInCatalog: 1
m_InternalIdNamingMode: 0
m_CacheClearBehavior: 0
m_IncludeInBuild: 1
m_BundledAssetProviderType:
m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider
m_StripDownloadOptions: 0
m_ForceUniqueProvider: 0
m_UseAssetBundleCache: 1
m_UseAssetBundleCrc: 1
m_UseAssetBundleCrcForCachedBundles: 1
m_UseUWRForLocalBundles: 0
m_Timeout: 0
m_ChunkedTransfer: 0
m_RedirectLimit: -1
m_RetryCount: 0
m_BuildPath:
m_Id: c258e2bcd3e8ac742ba98f152c0e6322
m_LoadPath:
m_Id: 88323bf0b2ef98446961cedd6232bd47
m_BundleMode: 0
m_AssetBundleProviderType:
m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider
m_UseDefaultSchemaSettings: 0
m_SelectedPathPairIndex: 0
m_BundleNaming: 0
m_AssetLoadMode: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a0affac7520cbac4283e5d0fe0c0d28a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5834b5087d578d24c926ce20cd31e6d6, type: 3}
m_Name: BlokkemonCards_ContentUpdateGroupSchema
m_EditorClassIdentifier: Unity.Addressables.Editor::UnityEditor.AddressableAssets.Settings.GroupSchemas.ContentUpdateGroupSchema
m_Group: {fileID: 11400000, guid: 124f05e204489af49943d7fc039640a4, type: 2}
m_StaticContent: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ca0e74b531acf5449a15f65103061116
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2a80cc88c9884512b8b633110d838780, type: 3}
m_Name: Card_New Card 2
m_EditorClassIdentifier: AppleHillsScripts::AppleHills.Data.CardSystem.CardDefinition
Id: 7ea4fa95-5327-439b-ab7f-94f2656281f2
Name: My New Addressable Card!
Description: Description goes hereeee
Rarity: 0
Zone: 0
CardImage: {fileID: 0}
CollectionIndex: 7

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4b9c8b6ca63744a44acfe49ebe337619
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,10 +1,9 @@
using System.IO;
using System.Linq;
using AppleHills.Editor.Utilities;
using Bootstrap;
using UnityEditor;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.AddressableAssets;
@@ -160,10 +159,15 @@ namespace Editor.Bootstrap
private static AddressableAssetEntry CreateCustomBootSettingsEntry(CustomBootSettings bootSettings,
AddressableAssetGroup group, string key)
{
var settings = AddressableAssetSettingsDefaultObject.Settings;
var entry = settings.CreateOrMoveEntry(
AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(bootSettings)),
group);
string assetPath = AssetDatabase.GetAssetPath(bootSettings);
var settings = AddressablesUtility.GetAddressableSettings(false);
if (settings == null || string.IsNullOrEmpty(assetPath) || group == null)
{
return null;
}
var guid = AssetDatabase.AssetPathToGUID(assetPath);
var entry = settings.CreateOrMoveEntry(guid, group);
entry.address = key;
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
return entry;
@@ -189,21 +193,7 @@ namespace Editor.Bootstrap
/// <returns></returns>
private static AddressableAssetGroup GetOrCreateGroup(string name, bool includeInBuild)
{
// Use GetSettings(true) to ensure the settings asset is created if missing
var settings = AddressableAssetSettingsDefaultObject.GetSettings(true);
if (settings == null)
{
Debug.LogError("AddressableAssetSettings could not be found or created. Please ensure Addressables are set up in your project.");
return null;
}
var group = settings.FindGroup(name);
if (group == null)
{
group = settings.CreateGroup(name, false, false, true, settings.DefaultGroup.Schemas);
group.GetSchema<BundledAssetGroupSchema>().IncludeInBuild = includeInBuild;
}
return group;
return AddressablesUtility.GetOrCreateGroup(name, includeInBuild);
}
/// <summary>

View File

@@ -4,8 +4,10 @@ using System.Linq;
using AppleHills.Data.CardSystem;
using AppleHills.UI.CardSystem;
using UnityEditor;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
using UnityEngine.UI;
using AppleHills.Editor.Utilities;
namespace AppleHills.Editor.CardSystem
{
@@ -1079,6 +1081,19 @@ namespace AppleHills.Editor.CardSystem
EditorUtility.SetDirty(_selectedCard);
AssetDatabase.SaveAssets();
// Add to Addressables group "BlokkemonCards" and apply "BlokkemonCard" label
string assetPath = AssetDatabase.GetAssetPath(_selectedCard);
if (!string.IsNullOrEmpty(assetPath))
{
if (AddressablesUtility.EnsureAssetInGroupWithLabel(assetPath, "BlokkemonCards", "BlokkemonCard"))
{
AddressablesUtility.SaveAddressableAssets();
}
else
{
Debug.LogError("Failed to add card to Addressables. Please ensure Addressables are set up in this project.");
}
}
// Clear dirty flag
_isDirty = false;
}

View File

@@ -0,0 +1,226 @@
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEngine;
using UnityEditor;
namespace AppleHills.Editor.Utilities
{
/// <summary>
/// Utility methods for working with the Addressables system in editor scripts.
/// Contains common operations for creating and managing groups and entries.
/// </summary>
public static class AddressablesUtility
{
/// <summary>
/// Get or create the Addressables settings. Returns null if Addressables are not properly set up.
/// </summary>
/// <param name="createIfMissing">If true, will attempt to create settings if they don't exist</param>
/// <returns>The AddressableAssetSettings or null if not available</returns>
public static AddressableAssetSettings GetAddressableSettings(bool createIfMissing = false)
{
var settings = AddressableAssetSettingsDefaultObject.GetSettings(createIfMissing);
if (settings == null && createIfMissing)
{
Debug.LogError("AddressableAssetSettings could not be found or created. Please ensure Addressables are set up in your project.");
}
return settings;
}
/// <summary>
/// Retrieve or create an Addressables group.
/// </summary>
/// <param name="name">Name of the group</param>
/// <param name="includeInBuild">Whether to include assets in this group when building</param>
/// <returns>The created or existing group, or null if settings aren't available</returns>
public static AddressableAssetGroup GetOrCreateGroup(string name, bool includeInBuild = true)
{
// Use GetSettings(true) to ensure the settings asset is created if missing
var settings = GetAddressableSettings(true);
if (settings == null)
{
return null;
}
var group = settings.FindGroup(name);
if (group == null)
{
group = settings.CreateGroup(name, false, false, true, settings.DefaultGroup.Schemas);
// Configure the bundle schema if it exists
var bundleSchema = group.GetSchema<BundledAssetGroupSchema>();
if (bundleSchema != null)
{
bundleSchema.IncludeInBuild = includeInBuild;
}
}
return group;
}
/// <summary>
/// Create or move an asset entry to a specified Addressables group
/// </summary>
/// <param name="assetPath">Path to the asset</param>
/// <param name="groupName">Name of the group to add the asset to</param>
/// <param name="address">Optional custom address for the asset</param>
/// <returns>The created or moved asset entry, or null if failed</returns>
public static AddressableAssetEntry AddAssetToGroup(string assetPath, string groupName, string address = null)
{
if (string.IsNullOrEmpty(assetPath))
{
Debug.LogError("Cannot add asset to Addressables: Asset path is empty");
return null;
}
var settings = GetAddressableSettings(false);
if (settings == null)
{
return null;
}
var group = GetOrCreateGroup(groupName);
if (group == null)
{
return null;
}
var guid = AssetDatabase.AssetPathToGUID(assetPath);
if (string.IsNullOrEmpty(guid))
{
Debug.LogError($"Cannot add asset to Addressables: Invalid asset path {assetPath}");
return null;
}
var entry = settings.CreateOrMoveEntry(guid, group);
// Set custom address if provided
if (!string.IsNullOrEmpty(address))
{
entry.address = address;
}
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
return entry;
}
/// <summary>
/// Ensure an asset is in the specified addressable group
/// </summary>
/// <param name="assetPath">Path to the asset</param>
/// <param name="groupName">Target group name</param>
/// <param name="markDirty">Whether to mark settings as dirty</param>
/// <returns>True if the asset is now in the correct group</returns>
public static bool EnsureAssetInGroup(string assetPath, string groupName, bool markDirty = true)
{
var settings = GetAddressableSettings(false);
if (settings == null)
{
return false;
}
var guid = AssetDatabase.AssetPathToGUID(assetPath);
if (string.IsNullOrEmpty(guid))
{
return false;
}
var group = GetOrCreateGroup(groupName);
if (group == null)
{
return false;
}
var entry = settings.FindAssetEntry(guid);
// If entry exists but is in wrong group, move it
if (entry != null && entry.parentGroup != group)
{
settings.MoveEntry(entry, group);
if (markDirty)
{
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
}
return true;
}
// If entry doesn't exist, create it
else if (entry == null)
{
entry = settings.CreateOrMoveEntry(guid, group);
if (markDirty)
{
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, entry, true);
}
return true;
}
// Entry already exists in correct group
return true;
}
/// <summary>
/// Save any pending changes to addressable assets
/// </summary>
public static void SaveAddressableAssets()
{
AssetDatabase.SaveAssets();
}
/// <summary>
/// Add a label to an addressable asset
/// </summary>
/// <param name="assetPath">Path to the asset</param>
/// <param name="label">Label to add</param>
/// <returns>True if the label was successfully added</returns>
public static bool AddLabelToAsset(string assetPath, string label)
{
if (string.IsNullOrEmpty(assetPath) || string.IsNullOrEmpty(label))
{
return false;
}
var settings = GetAddressableSettings(false);
if (settings == null)
{
return false;
}
var guid = AssetDatabase.AssetPathToGUID(assetPath);
var entry = settings.FindAssetEntry(guid);
if (entry == null)
{
Debug.LogWarning($"Asset at {assetPath} is not addressable. Add it to a group first before applying labels.");
return false;
}
// Make sure the label exists in the settings
if (!settings.GetLabels().Contains(label))
{
settings.AddLabel(label);
}
// Add the label to the entry
entry.labels.Add(label);
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entry, true);
return true;
}
/// <summary>
/// Ensure an asset is in an addressable group and has the specified label
/// </summary>
/// <param name="assetPath">Path to the asset</param>
/// <param name="groupName">Group to add the asset to</param>
/// <param name="label">Label to apply to the asset</param>
/// <returns>True if the asset was successfully added to the group and labeled</returns>
public static bool EnsureAssetInGroupWithLabel(string assetPath, string groupName, string label)
{
bool result = EnsureAssetInGroup(assetPath, groupName);
if (result && !string.IsNullOrEmpty(label))
{
result = AddLabelToAsset(assetPath, label);
}
return result;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5225b0b6611c4dc7a6e1f48919831efd
timeCreated: 1761029089

View File

@@ -287,10 +287,10 @@ Texture2D:
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 1
m_ColorSpace: 0
m_PlatformBlob:
image data: 1
_typelessdata: cd
_typelessdata: 00
m_StreamData:
serializedVersion: 2
offset: 0

View File

@@ -146,10 +146,10 @@ Texture2D:
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 1
m_ColorSpace: 0
m_PlatformBlob:
image data: 1
_typelessdata: cd
_typelessdata: 00
m_StreamData:
serializedVersion: 2
offset: 0

View File

@@ -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;
}
}
}

View File

@@ -24,10 +24,6 @@ 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();
@@ -44,22 +40,18 @@ namespace Data.CardSystem
{
_instance = this;
// Auto-load card definitions if enabled
if (autoLoadCardDefinitions)
{
LoadCardDefinitionsFromFolder();
}
// 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
// Load card definitions from Addressables
LoadCardDefinitionsFromAddressables();
// Build lookup dictionary
BuildDefinitionLookup();
Logging.Debug("[CardSystemManager] Post-boot initialization complete");
}
@@ -69,44 +61,33 @@ namespace Data.CardSystem
}
/// <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>

View File

@@ -2,7 +2,6 @@
using Core;
using System;
using System.Collections;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Audio;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using AppleHills.Core.Settings;
using Core;
@@ -72,10 +73,37 @@ namespace Utils
return frameAdjustedSpeed * screenNormalizationFactor;
}
public static bool AddressableKeyExists(object key)
public static bool AddressableKeyExists(object key, Addressables.MergeMode mergeMode = Addressables.MergeMode.Union)
{
IList<IResourceLocation> locations;
return Addressables.LoadResourceLocationsAsync(key).WaitForCompletion()?.Count > 0;
try
{
// Handle different key types
if (key is string[] keyArray)
{
// For string arrays, use the array as is with merge mode
return Addressables.LoadResourceLocationsAsync(keyArray, mergeMode).WaitForCompletion()?.Count > 0;
}
else if (key is IEnumerable<object> keyList)
{
// For collections of keys, convert to object[]
return Addressables.LoadResourceLocationsAsync(keyList.ToArray(), mergeMode).WaitForCompletion()?.Count > 0;
}
else if (key is string stringKey)
{
// For single string keys, wrap in array
return Addressables.LoadResourceLocationsAsync(new string[] { stringKey }, mergeMode).WaitForCompletion()?.Count > 0;
}
else
{
// For other single keys (AssetReference, etc.), wrap in object[]
return Addressables.LoadResourceLocationsAsync(new object[] { key }, mergeMode).WaitForCompletion()?.Count > 0;
}
}
catch (System.Exception ex)
{
Debug.LogWarning($"[AppleHillsUtils] Error checking addressable key existence: {ex.Message}");
return false;
}
}
}
}