59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System;
|
|
using Code.Example.Platformer.Entity;
|
|
using Code.Example.Platformer.Level;
|
|
using Code.Infrastructure.EventBus;
|
|
using Code.Infrastructure.Loadings;
|
|
using Code.Infrastructure.SceneLoader;
|
|
using Reflex.Core;
|
|
using Reflex.Enums;
|
|
using UnityEngine;
|
|
using Resolution = Reflex.Enums.Resolution;
|
|
|
|
namespace Code.Example.Platformer
|
|
{
|
|
public class PlatformerEnemySceneInstaller :
|
|
MonoBehaviour,
|
|
IInstaller,
|
|
IPlatformerEnemyFactoryInitializedHandle,
|
|
IPlatformerPlayerFactoryInitializedHandle,
|
|
IDisposable
|
|
{
|
|
|
|
private Loading _sceneInit;
|
|
private Container _container;
|
|
|
|
private void LoadingComplete()
|
|
{
|
|
_container.Resolve<EventBus>()
|
|
.RaiseEvent<IOnPlatformerSceneLoadedHandler>(x => x.OnPlatformerSceneInitialized(_container));
|
|
}
|
|
|
|
public void InstallBindings(ContainerBuilder containerBuilder)
|
|
{
|
|
// Enemies
|
|
// Player
|
|
// Container
|
|
_sceneInit = new(3, LoadingComplete);
|
|
|
|
containerBuilder.Parent.Resolve<EventBus>().Subscribe(this);
|
|
|
|
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 void OnContainerBuild(Container container)
|
|
{
|
|
_container = container;
|
|
_sceneInit.DoProgress();
|
|
}
|
|
|
|
public void PlatformerEnemyFactoryInitialized() => _sceneInit.DoProgress();
|
|
|
|
public void PlatformerPlayerFactoryInitialized() => _sceneInit.DoProgress();
|
|
|
|
public void Dispose()
|
|
{
|
|
_container.Resolve<EventBus>().Unsubscribe(this);
|
|
}
|
|
}
|
|
} |