70 lines
3.1 KiB
C#
70 lines
3.1 KiB
C#
using Code.Infrastructure.Camera;
|
|
using Code.Infrastructure.Configs;
|
|
using Code.Infrastructure.Input;
|
|
using Code.Infrastructure.Loadings;
|
|
using Code.Infrastructure.SceneLoader;
|
|
using Reflex.Core;
|
|
using Reflex.Enums;
|
|
using UnityEngine;
|
|
using Resolution = Reflex.Enums.Resolution;
|
|
|
|
namespace Code.Infrastructure.App
|
|
{
|
|
public class PapaInstaller : MonoBehaviour, IInstaller, ISceneConfigsLoadedHandle, IInputServiceInitializedHandle, ICameraInitializedHandle
|
|
{
|
|
public void InstallBindings(ContainerBuilder containerBuilder)
|
|
{
|
|
containerBuilder.RegisterType(typeof(EventBus.EventBus), Lifetime.Singleton, Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(ConfigLocator), new[] { typeof(IConfigLocator) }, Lifetime.Singleton, Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(SceneLoader.SceneLoader), Lifetime.Singleton, Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(InputService),new[] { typeof(IInputService) }, Lifetime.Singleton, Resolution.Eager);
|
|
|
|
containerBuilder.OnContainerBuilt += Bootstrap;
|
|
|
|
containerBuilder.RegisterType(typeof(AppStateMachine), Lifetime.Singleton, Resolution.Lazy);
|
|
containerBuilder.RegisterType(typeof(AppStateMachineContext), Lifetime.Singleton, Resolution.Lazy);
|
|
|
|
containerBuilder.RegisterType(typeof(CameraFactory), Lifetime.Singleton, Resolution.Lazy);
|
|
containerBuilder.RegisterType(typeof(CameraStateMachine), Lifetime.Singleton, Resolution.Lazy);
|
|
containerBuilder.RegisterType(typeof(CameraStateMachineContext), Lifetime.Singleton, Resolution.Lazy);
|
|
|
|
}
|
|
|
|
private Loading _initialLoading;
|
|
private Container _thatRightContainer;
|
|
private void Bootstrap(Container container)
|
|
{
|
|
_thatRightContainer = container;
|
|
|
|
container.Resolve<EventBus.EventBus>().Subscribe(this);
|
|
|
|
container.Resolve<CameraFactory>().CreateCameraStateMachine(container.Resolve<CameraStateMachine>()).Forget();
|
|
|
|
_initialLoading = new Loading(3, () => EssentialLoadEnded(container));
|
|
}
|
|
|
|
private void EssentialLoadEnded(Container container)
|
|
{
|
|
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap).AllowStateTransition(AppStates.Gameplay);
|
|
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
|
|
}
|
|
|
|
public void SceneConfigsLoaded()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void InputServiceInitialized()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void CameraInitialized(CameraStateMachineContext.CameraLoadedData data)
|
|
{
|
|
_thatRightContainer.Resolve<CameraStateMachineContext>().cameraLoadedData = data;
|
|
_thatRightContainer.Resolve<CameraStateMachine>().SwitchState(CameraMode.None)
|
|
.AllowStateTransition(CameraMode.FirstPerson);
|
|
_initialLoading.DoProgress();
|
|
}
|
|
}
|
|
} |