Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Code.Infrastructure.Utils;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using Reflex.Core;
|
||||
using Reflex.Injectors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Game.Gameplay.Player.Factory
|
||||
{
|
||||
public interface IPlayerFactory
|
||||
{
|
||||
UniTask<GameObject> CreatePlayer();
|
||||
void InjectPlayer(Container container);
|
||||
}
|
||||
|
||||
public class PlayerFactory : IDisposable, IPlayerFactory
|
||||
{
|
||||
private readonly SingleConfig<PlayerFactorySettings> _config;
|
||||
|
||||
private GameObject _playerInstance;
|
||||
|
||||
public PlayerFactory(SingleConfig<PlayerFactorySettings> config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
public async UniTask<GameObject> CreatePlayer()
|
||||
{
|
||||
_playerInstance ??= await Addressables.InstantiateAsync(_config.Config.Player).ToUniTask();
|
||||
|
||||
return _playerInstance;
|
||||
}
|
||||
|
||||
public void InjectPlayer(Container container)
|
||||
{
|
||||
GameObjectInjector.InjectRecursive(_playerInstance, container);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Addressables.ReleaseInstance(_playerInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user