47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
namespace DDD
|
|
{
|
|
[CreateAssetMenu(fileName = "GameData", menuName = "GameData/GameData")]
|
|
public class GameData : ScriptSingleton<GameData>
|
|
{
|
|
[SerializeField] private AssetReference _gameLocalizationData;
|
|
[SerializeField] private AssetReference _uiData;
|
|
|
|
public GameLocalizationData LocalizationData { get; private set; }
|
|
public UiData UiData { get; private set; }
|
|
|
|
private bool _isLoaded;
|
|
|
|
public async Task LoadData()
|
|
{
|
|
if (_isLoaded)
|
|
{
|
|
return;
|
|
}
|
|
|
|
LocalizationData = await AssetManager.Instance.LoadAssetAsync<GameLocalizationData>(_gameLocalizationData);
|
|
UiData = await AssetManager.Instance.LoadAssetAsync<UiData>(_uiData);
|
|
|
|
_isLoaded = true;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (_isLoaded == false) return;
|
|
|
|
var assetManager = AssetManager.Instance;
|
|
if (!assetManager) return;
|
|
|
|
AssetManager.Instance.ReleaseAsset(_gameLocalizationData);
|
|
AssetManager.Instance.ReleaseAsset(_uiData);
|
|
|
|
LocalizationData = null;
|
|
UiData = null;
|
|
|
|
_isLoaded = false;
|
|
}
|
|
}
|
|
} |