2025-08-18 10:48:36 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
[CreateAssetMenu(fileName = "GameData", menuName = "GameData/GameData")]
|
2025-08-19 04:51:42 +00:00
|
|
|
public class GameData : ScriptSingleton<GameData>
|
2025-08-18 10:48:36 +00:00
|
|
|
{
|
|
|
|
[SerializeField] private AssetReference _gameLocalizationData;
|
2025-08-21 07:25:27 +00:00
|
|
|
[SerializeField] private AssetReference _uiData;
|
2025-08-18 10:48:36 +00:00
|
|
|
|
|
|
|
public GameLocalizationData LocalizationData { get; private set; }
|
2025-08-21 07:25:27 +00:00
|
|
|
public UiData UiData { get; private set; }
|
2025-08-18 10:48:36 +00:00
|
|
|
|
|
|
|
private bool _isLoaded;
|
|
|
|
|
|
|
|
public async Task LoadData()
|
|
|
|
{
|
|
|
|
if (_isLoaded)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2025-08-21 07:25:27 +00:00
|
|
|
|
2025-08-27 08:52:33 +00:00
|
|
|
LocalizationData = await AssetManager.Instance.LoadAssetAsync<GameLocalizationData>(_gameLocalizationData);
|
|
|
|
UiData = await AssetManager.Instance.LoadAssetAsync<UiData>(_uiData);
|
2025-08-18 10:48:36 +00:00
|
|
|
|
|
|
|
_isLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
if (_isLoaded == false) return;
|
2025-08-27 08:52:33 +00:00
|
|
|
|
|
|
|
var assetManager = AssetManager.Instance;
|
|
|
|
if (!assetManager) return;
|
2025-08-18 10:48:36 +00:00
|
|
|
|
2025-08-27 08:52:33 +00:00
|
|
|
AssetManager.Instance.ReleaseAsset(_gameLocalizationData);
|
|
|
|
AssetManager.Instance.ReleaseAsset(_uiData);
|
|
|
|
|
|
|
|
LocalizationData = null;
|
|
|
|
UiData = null;
|
|
|
|
|
2025-08-18 10:48:36 +00:00
|
|
|
_isLoaded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|