Merge branch 'NotLiminalPCG' of https://notscam.serveminecraft.net/ThomasCharester/Infratest into NotLiminalPCG

This commit is contained in:
ThomasCharester committed 2026-03-17 18:09:50 +03:00
commit 98e4a055fe
45 files changed
+395 -168

No files matched your search

@@ -31,11 +31,7 @@ namespace Code.Example.Platformer.Entity
[ToConfig] public AssetReference prefabReference;
}
[Config("Configs/Gameplay/Platformer/PlayerSettings")]
[Config("", false, true)]
public class PlatformerPlayerSettings
{
[ToConfig] public PlatformerEntityData EntityData;
[ToConfig] public AssetReference prefabReference;
}
{ }
}
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using Reflex.Core;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
namespace Code.Example.Platformer.Entity
{
public interface IPlatformerPlayerFactory
{
UniTaskVoid LoadPlayer();
void ReleasePlayer();
UniTaskVoid SpawnPlayer(Vector3 position);
}
public class PlatformerPlayerFactory : IPlatformerPlayerFactory, IDisposable
{
private EventBus _eventBus;
private AssetReference _playerConfigReference;
private AsyncOperationHandle<PlatformerEntitySettingsConfig> _playerConfigHandle;
private AsyncOperationHandle<GameObject> _playerPrefabHandle;
private PlatformerEntitySettingsConfig _playerConfig;
public PlatformerPlayerFactory(IConfigLocator configLocator, EventBus eventBus)
{
_eventBus = eventBus;
_playerConfigReference = configLocator.TryGetConfigAssetReference<PlatformerPlayerSettingsConfig>();
LoadConfigs().Forget();
}
private async UniTaskVoid LoadConfigs()
{
_playerConfigHandle = Addressables.LoadAssetAsync<PlatformerEntitySettingsConfig>(_playerConfigReference);
await _playerConfigHandle.ToUniTask();
_playerConfig = _playerConfigHandle.Result;
_eventBus.RaiseEvent<IPlatformerPlayerFactoryInitializedHandle>(x => x.PlatformerPlayerFactoryInitialized());
}
public async UniTaskVoid LoadPlayer()
{
if (_playerPrefabHandle.IsValid())
{
_eventBus.RaiseEvent<IPlatformerPlayerLoadedHandle>(x => x.PlatformerPlayerLoaded());
return;
}
UnityEngine.Debug.LogWarning($"Player loaded");
_playerPrefabHandle = Addressables.LoadAssetAsync<GameObject>(_playerConfig.prefabReference);
await _playerPrefabHandle.ToUniTask();
var racer = _playerPrefabHandle.Result.GetComponent<Entity>();
racer.SetData(_playerConfig.EntityData);
_eventBus.RaiseEvent<IPlatformerPlayerLoadedHandle>(x => x.PlatformerPlayerLoaded());
}
public void ReleasePlayer()
{
_playerPrefabHandle.Release();
}
public async UniTaskVoid SpawnPlayer(Vector3 position)
{
var player = await Addressables.InstantiateAsync(_playerConfig.prefabReference, position, Quaternion.identity).ToUniTask();
GameObjectInjector.InjectObject(player, Container.RootContainer); // TODO САМОЕ НЕСТАБИЛЬНОЕ ДЕРЬМО ВО ВСЕЛЕННОЙ КОНТЕЙНЕР ДОЛЖЕН БЫТЬ КОНТЕКСТНЫМ
_eventBus.RaiseEvent<IPlatformerPlayerSpawnedHandle>(x => x.PlatformerPlayerSpawned(player.GetComponent<Entity>()));
}
public void Dispose()
{
UnityEngine.Debug.LogWarning($"Enemies released");
_playerPrefabHandle.Release();
_playerConfigHandle.Release();
}
}
public interface IPlatformerPlayerFactoryInitializedHandle : IGlobalSubscriber
{
public void PlatformerPlayerFactoryInitialized();
}
public interface IPlatformerPlayerLoadedHandle : IGlobalSubscriber
{
public void PlatformerPlayerLoaded();
}
public interface IPlatformerPlayerSpawnedHandle : IGlobalSubscriber
{
public void PlatformerPlayerSpawned(Entity entity);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 70a3deb8fbb44749b5aeea7b3997a459
timeCreated: 1773136472
@@ -62,7 +62,7 @@ namespace Code.Example.Platformer.Entity
private void JumpPerformed(InputAction.CallbackContext callbackContext)
{
if (!onGround) return;
rigidbody2D.AddForceY(150f);
rigidbody2D.AddForceY(100f);
_acceleration = 1f;
}
@@ -11,7 +11,12 @@ using Resolution = Reflex.Enums.Resolution;
namespace Code.Example.Platformer
{
public class PlatformerEnemySceneInstaller : MonoBehaviour, IInstaller, IPlatformerEnemyFactoryInitializedHandle
public class PlatformerEnemySceneInstaller :
MonoBehaviour,
IInstaller,
IPlatformerEnemyFactoryInitializedHandle,
IPlatformerPlayerFactoryInitializedHandle,
IDisposable
{
// [SerializeField] private PlatformerCanvas gameplayPlatformerCanvas;
[SerializeField] private PlatformerFirstLevelData firstLevelData;
@@ -27,14 +32,16 @@ namespace Code.Example.Platformer
public void InstallBindings(ContainerBuilder containerBuilder)
{
// Enemies
// Player
// Container
_sceneInit = new(2, LoadingComplete);
_sceneInit = new(3, LoadingComplete);
// containerBuilder.RegisterValue(gameplayPlatformerCanvas);
containerBuilder.Parent.Resolve<EventBus>().Subscribe(this);
containerBuilder.RegisterValue(firstLevelData);
containerBuilder.RegisterType(typeof(PlatformerEnemyFactory), new []{typeof(IPlatformerEnemyFactory)}, Lifetime.Scoped, Resolution.Eager);
containerBuilder.RegisterType(typeof(PlatformerPlayerFactory), new []{typeof(IPlatformerPlayerFactory)}, Lifetime.Scoped, Resolution.Eager);
containerBuilder.OnContainerBuilt += OnContainerBuild;
}
private Container _container;
@@ -51,5 +58,15 @@ namespace Code.Example.Platformer
{
_sceneInit.DoProgress();
}
public void PlatformerPlayerFactoryInitialized()
{
_sceneInit.DoProgress();
}
public void Dispose()
{
_container.Resolve<EventBus>().Unsubscribe(this);
}
}
}
@@ -17,7 +17,12 @@ namespace Code.Example.Platformer
{
[State(typeof(AppStates),typeof(AppStateMachineContext))]
[StateRaisingEvent]
public partial class PlatformerState : IOnPlatformerSceneLoadedHandler, ICinematicMachineHandle, IPlatformerEnemyLoadedHandle
public partial class PlatformerState :
IOnPlatformerSceneLoadedHandler,
ICinematicMachineHandle,
IPlatformerEnemyLoadedHandle,
IPlatformerPlayerLoadedHandle,
IPlatformerPlayerSpawnedHandle
{
public PlatformerState(AppStateMachineContext context, EventBus eventBus) : base(context, eventBus)
{
@@ -33,7 +38,8 @@ namespace Code.Example.Platformer
// Enemy snail
// Enemy bee
// Enemy boar
_loading = new(5, LoadingCompleted);
// Player
_loading = new(6, LoadingCompleted);
Context.UIService.OpenPanel(UIPanelType.Loading);
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer, LoadSceneMode.Single).Forget();
@@ -48,6 +54,8 @@ namespace Code.Example.Platformer
Context.UIService.ClosePanel(UIPanelType.Loading);
_enemyFactory.SpawnEnemy(PlatformerEntityType.Snail, _firstLevelData.enemySpawnPoints[0].position);
_playerFactory.SpawnPlayer(_firstLevelData.playerCheckPoints[0].position);
}
@@ -57,6 +65,8 @@ namespace Code.Example.Platformer
_enemyFactory.ReleaseEnemy(PlatformerEntityType.Snail);
_enemyFactory.ReleaseEnemy(PlatformerEntityType.Boar);
_playerFactory.ReleasePlayer();
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.Platformer);
EventBus.Unsubscribe(this);
Context.InputService.DisableMap(ActionMappings.Platformer);
@@ -68,9 +78,14 @@ namespace Code.Example.Platformer
}
private IPlatformerEnemyFactory _enemyFactory;
private IPlatformerPlayerFactory _playerFactory;
private PlatformerFirstLevelData _firstLevelData;
private Container _fixdamncontainer;
public void OnPlatformerSceneInitialized(Container container)
{
_fixdamncontainer = container;
_firstLevelData = container.Resolve<PlatformerFirstLevelData>();
_enemyFactory = container.Resolve<IPlatformerEnemyFactory>();
@@ -78,6 +93,10 @@ namespace Code.Example.Platformer
_enemyFactory.WarmEnemy(PlatformerEntityType.Boar);
_enemyFactory.WarmEnemy(PlatformerEntityType.Snail);
_playerFactory = container.Resolve<IPlatformerPlayerFactory>();
_playerFactory.LoadPlayer();
_loading.DoProgress();
}
@@ -92,5 +111,15 @@ namespace Code.Example.Platformer
{
if(entity) _loading.DoProgress();
}
public void PlatformerPlayerLoaded()
{
_loading.DoProgress();
}
public void PlatformerPlayerSpawned(Entity.Entity entity)
{
Context.CameraFactory.GetCinematicCamera(CameraMode.Platformer).Follow = entity.transform;
}
}
}