diff --git a/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs b/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs index eaa4739fc..277970d52 100644 --- a/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs +++ b/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #if UNITY_EDITOR @@ -61,6 +62,18 @@ public static async Task LoadAsset(AssetReference reference) where T : Uni return null; } + public static async Task> LoadAssetsByLabel(string label) where T : UnityEngine.Object + { + var handle = Addressables.LoadAssetsAsync(label, null); + await handle.Task; + + if (handle.Status == AsyncOperationStatus.Succeeded) + return handle.Result.ToList(); + + Debug.LogError($"[AssetManager] Failed to load assets with label: {label}"); + return new List(); + } + public static async Task LoadScene(string key, LoadSceneMode mode = LoadSceneMode.Additive) { var handle = Addressables.LoadSceneAsync(key, mode); diff --git a/Assets/_DDD/_Scripts/GameData/DataManager.cs b/Assets/_DDD/_Scripts/GameData/DataManager.cs index 164606562..8056de96e 100644 --- a/Assets/_DDD/_Scripts/GameData/DataManager.cs +++ b/Assets/_DDD/_Scripts/GameData/DataManager.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; +using UnityEngine.U2D; namespace DDD { @@ -9,6 +11,8 @@ public class DataManager : Singleton, IManager public ItemDataSo ItemDataSo { get; private set; } public FoodDataSo FoodDataSo { get; private set; } public EnvironmentDataSo EnvironmentDataSo { get; private set; } + + private Dictionary _spriteAtlas; public bool IsInitialized { get; private set; } @@ -24,6 +28,28 @@ public async void PostInit() ItemDataSo = await AssetManager.LoadAsset(DataConstants.ItemDataSo); FoodDataSo = await AssetManager.LoadAsset(DataConstants.FoodDataSo); EnvironmentDataSo = await AssetManager.LoadAsset(DataConstants.EnvironmentDataSo); + + List spriteAtlases = await AssetManager.LoadAssetsByLabel(DataConstants.AtlasLabel); + _spriteAtlas = new Dictionary(spriteAtlases.Count); + + foreach (var atlas in spriteAtlases) + { + if (atlas == null) continue; + + var count = atlas.spriteCount; + if (count == 0) continue; + + var sprites = new Sprite[count]; + atlas.GetSprites(sprites); + + foreach (var sprite in sprites) + { + if (sprite == null) continue; + + var key = sprite.name.Replace("(Clone)", "").Trim(); + _spriteAtlas.TryAdd(key, sprite); + } + } IsInitialized = true; } @@ -40,6 +66,8 @@ public async Task WaitUntilInitialized() await Task.Yield(); } } + + public Sprite GetSprite(string key) => _spriteAtlas.GetValueOrDefault(key); // TODO : So가 늘어나는 경우 관리 방법 변경 필요성이 있음 // GetItemType(id) diff --git a/Assets/_DDD/_Scripts/GenerateGoogleSheet/Core/GoogleSheetManager.cs b/Assets/_DDD/_Scripts/GenerateGoogleSheet/Core/GoogleSheetManager.cs index 79d3d55c7..4dcb0dd34 100644 --- a/Assets/_DDD/_Scripts/GenerateGoogleSheet/Core/GoogleSheetManager.cs +++ b/Assets/_DDD/_Scripts/GenerateGoogleSheet/Core/GoogleSheetManager.cs @@ -15,6 +15,7 @@ using UnityEditor; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; +using UnityEngine.U2D; using ColorUtility = UnityEngine.ColorUtility; public class GoogleSheetManager : Singleton @@ -682,7 +683,6 @@ private async Task InternalCreateGoogleSheetSoAsync() FieldInfo field = dataType.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - PropertyInfo property = dataType.GetProperty(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); @@ -696,31 +696,7 @@ private async Task InternalCreateGoogleSheetSoAsync() { object value; - // Sprite, Color 등 기존 로직 유지 - if (explicitType == "Sprite" && (field?.FieldType == typeof(Sprite) || - property?.PropertyType == typeof(Sprite))) - { - string spriteKey = prop.Value.ToString().Trim(); - if (string.IsNullOrEmpty(spriteKey)) continue; - - if (!AssetManager.HasLabel(spriteKey, "Sprite")) - { - Debug.LogWarning($"[GoogleSheetManager] Sprite 라벨 없음: {spriteKey}"); - continue; - } - - var handle = Addressables.LoadAssetAsync(spriteKey); - await handle.Task; - - if (handle.Status != AsyncOperationStatus.Succeeded || handle.Result == null) - { - Debug.LogWarning($"[GoogleSheetManager] Sprite 로드 실패 또는 null: {spriteKey}"); - continue; - } - - value = handle.Result; - } - else if ((field?.FieldType.IsEnum ?? false) || (property?.PropertyType.IsEnum ?? false)) + if ((field?.FieldType.IsEnum ?? false) || (property?.PropertyType.IsEnum ?? false)) { Type enumType = field?.FieldType ?? property?.PropertyType; string formatted = NormalizeEnumKey(prop.Value.ToString()); @@ -758,7 +734,6 @@ private async Task InternalCreateGoogleSheetSoAsync() list.Add(dataInstance); } - // ✅ SetDataList() 호출 MethodInfo setMethod = soType.GetMethod("SetDataList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (setMethod != null) @@ -811,7 +786,13 @@ private string NormalizeEnumKey(string input) // 첫 글자 대문자화 return char.ToUpper(validName[0]) + validName.Substring(1); } - + + private string NormalizeSpriteKey(string name) + { + if (string.IsNullOrEmpty(name)) return ""; + return name.Replace("(Clone)", "").Trim(); + } + private void OnValidate() { if (_refreshTrigger && !_alreadyCreatedSo && EditorPrefs.GetBool("GoogleSheetManager_ShouldCreateSO")) diff --git a/Assets/_DDD/_Scripts/RestaurantEnvironment/RestaurantEnvironment.cs b/Assets/_DDD/_Scripts/RestaurantEnvironment/RestaurantEnvironment.cs index 889d8731a..4103c4c36 100644 --- a/Assets/_DDD/_Scripts/RestaurantEnvironment/RestaurantEnvironment.cs +++ b/Assets/_DDD/_Scripts/RestaurantEnvironment/RestaurantEnvironment.cs @@ -30,7 +30,7 @@ public async void Initialize(string id) { var spriteRenderer = _visualLook.AddComponent(); _renderer = spriteRenderer; - spriteRenderer.sprite = environmentData.Sprite; + spriteRenderer.sprite = DataManager.Instance.GetSprite(environmentData.SpriteKey); spriteRenderer.sortingOrder = 5; Material material = await AssetManager.LoadAsset(DataConstants.BasePropSpriteMaterial); spriteRenderer.material = new Material(material); diff --git a/Assets/_DDD/_Scripts/Utilities/Constants.cs b/Assets/_DDD/_Scripts/Utilities/Constants.cs index 7863de96a..927fb949d 100644 --- a/Assets/_DDD/_Scripts/Utilities/Constants.cs +++ b/Assets/_DDD/_Scripts/Utilities/Constants.cs @@ -12,9 +12,9 @@ public static class DataConstants public const string ItemDataSo = "ItemDataSo"; public const string FoodDataSo = "FoodDataSo"; public const string EnvironmentDataSo = "EnvironmentDataSo"; - public const string SpriteDataSo = "SpriteDataSo"; public const string RestaurantPlayerDataSo = "RestaurantPlayerDataSo"; + public const string AtlasLabel = "Atlas"; public const string BasePropSpriteMaterial = "BasePropSpriteMaterial"; }