using System.Threading.Tasks; using UnityEngine; using UnityEngine.AddressableAssets; namespace DDD { [CreateAssetMenu(fileName = "RestaurantData", menuName = "RestaurantData/RestaurantData", order = 0)] public class RestaurantData : ScriptSingleton { [SerializeField] private AssetReference _restaurantPlayerData; [SerializeField] private AssetReference _restaurantManagementData; [SerializeField] private AssetReference _restaurantRunData; [SerializeField] private AssetReference _restaurantCustomerData; public RestaurantPlayerData PlayerData { get; private set; } public RestaurantManagementData ManagementData { get; private set; } public RestaurantRunData RunData { get; private set; } public RestaurantCustomerData CustomerData { get; private set; } private bool _isLoaded; public async Task LoadData() { if (_isLoaded) { return; } PlayerData = await AssetManager.Instance.LoadAssetAsync(_restaurantPlayerData); ManagementData = await AssetManager.Instance.LoadAssetAsync(_restaurantManagementData); RunData = await AssetManager.Instance.LoadAssetAsync(_restaurantRunData); CustomerData = await AssetManager.Instance.LoadAssetAsync(_restaurantCustomerData); _isLoaded = true; } private void OnDisable() { if (_isLoaded == false) return; var assetManager = AssetManager.Instance; if (!assetManager) return; AssetManager.Instance.ReleaseAsset(_restaurantPlayerData); AssetManager.Instance.ReleaseAsset(_restaurantManagementData); AssetManager.Instance.ReleaseAsset(_restaurantRunData); AssetManager.Instance.ReleaseAsset(_restaurantCustomerData); PlayerData = null; ManagementData = null; RunData = null; CustomerData = null; _isLoaded = false; } } }