riversong code showcase
This commit is contained in:
37
Source/Engine/GameData/GameDatabaseSystem.cs
Normal file
37
Source/Engine/GameData/GameDatabaseSystem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user