38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using UnityEngine.AddressableAssets;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(EarlyGameSystemGroup))]
|
|
public class GameDatabaseSystem : GameSystem, IInitializable, IServiceProvider
|
|
{
|
|
public const string GameDataAddressablesKey = "GameData";
|
|
|
|
private GameDatabase _gameDatabase;
|
|
|
|
public GameDatabaseSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void RegisterServices(IServiceLocator serviceLocator)
|
|
{
|
|
_gameDatabase = new GameDatabase();
|
|
ServiceLocator.RegisterService<IGameDatabase>(_gameDatabase);
|
|
}
|
|
|
|
public async UniTask InitializeAsync()
|
|
{
|
|
await Addressables.LoadAssetsAsync<Object>(GameDataAddressablesKey, OnAssetLoaded);
|
|
}
|
|
|
|
private void OnAssetLoaded(Object asset)
|
|
{
|
|
var id = asset.GetInstanceID();
|
|
id = unchecked(id + 0x40000000);
|
|
|
|
_gameDatabase.Add(id, asset);
|
|
}
|
|
}
|
|
}
|