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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdc8848de9734ba3bb1c3e3ec81145e6
|
||||
timeCreated: 1778956904
|
||||
@@ -0,0 +1,13 @@
|
||||
using Code.Infrastructure.Generators;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Game.Gameplay.Player.Factory
|
||||
{
|
||||
[Config("Configs/Gameplay/PlayerFactory")]
|
||||
[CreateAssetMenu(fileName = "PlayerFactorySettings", menuName = "Configs/Gameplay/PlayerFactory")]
|
||||
public class PlayerFactorySettings : ScriptableObject
|
||||
{
|
||||
public AssetReference Player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c312323c8dc049b2b7e7330f54b09aad
|
||||
timeCreated: 1785871572
|
||||
Reference in new issue
Block a user