Merge branch 'main' of https://homelab.tailf7f81b.ts.net/tschesky/AppleHillsProduction
This commit is contained in:
@@ -13,6 +13,7 @@ MonoBehaviour:
|
||||
m_Name: AddressableAssetGroupSortSettings
|
||||
m_EditorClassIdentifier:
|
||||
sortOrder:
|
||||
- 0d5d36d6da388314b92b9c6967d23f39
|
||||
- 75e1f68b7bf77f34f8ad4aeab74d4244
|
||||
- eb8a37153d819c44194f7ce97570a3d3
|
||||
- 2b3d7cefec0915e42be04aebf0400a56
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 124f05e204489af49943d7fc039640a4
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0affac7520cbac4283e5d0fe0c0d28a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca0e74b531acf5449a15f65103061116
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Data/Cards/Card_New Card 2.asset
Normal file
21
Assets/Data/Cards/Card_New Card 2.asset
Normal 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
|
||||
8
Assets/Data/Cards/Card_New Card 2.asset.meta
Normal file
8
Assets/Data/Cards/Card_New Card 2.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b9c8b6ca63744a44acfe49ebe337619
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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>
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
using System.IO;
|
||||
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;
|
||||
using UI.CardSystem;
|
||||
|
||||
namespace AppleHills.Editor.CardSystem
|
||||
{
|
||||
@@ -1078,7 +1080,20 @@ namespace AppleHills.Editor.CardSystem
|
||||
// Mark as dirty and save
|
||||
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;
|
||||
}
|
||||
|
||||
226
Assets/Editor/Utilities/AddressablesUtility.cs
Normal file
226
Assets/Editor/Utilities/AddressablesUtility.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Editor/Utilities/AddressablesUtility.cs.meta
Normal file
3
Assets/Editor/Utilities/AddressablesUtility.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5225b0b6611c4dc7a6e1f48919831efd
|
||||
timeCreated: 1761029089
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using Data.CardSystem;
|
||||
using Core;
|
||||
using AppleHills.UI.CardSystem;
|
||||
using UI.CardSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.Tests
|
||||
|
||||
@@ -4,10 +4,11 @@ using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI page for viewing the player's card collection in an album.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement.TweenSystem;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages a notification dot that displays a count (e.g., booster packs)
|
||||
|
||||
@@ -4,11 +4,11 @@ using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI page for opening booster packs and displaying the cards obtained.
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Main UI controller for the card album system.
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI page for the main menu of the card system.
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles displaying and interacting with a single card in the UI.
|
||||
|
||||
3
Assets/Scripts/UI/Core.meta
Normal file
3
Assets/Scripts/UI/Core.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea8964f9870d45479f09a4b05c2b0d0c
|
||||
timeCreated: 1761040697
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for UI pages that can transition in and out.
|
||||
@@ -5,7 +5,7 @@ using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages UI page transitions and maintains a stack of active pages.
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user