using System; using UnityEngine; namespace Zenject.SpaceFighter { // Main installer for our game public class GameInstaller : MonoInstaller { [Inject] Settings _settings = null; public override void InstallBindings() { Container.BindInterfacesAndSelfTo().AsSingle(); Container.BindFactory() // We could just use FromMonoPoolableMemoryPool here instead, but // for IL2CPP to work we need our pool class to be used explicitly here .FromPoolableMemoryPool(poolBinder => poolBinder // Spawn 5 enemies right off the bat so that we don't incur spikes at runtime .WithInitialSize(5) .FromSubContainerResolve() .ByNewPrefabInstaller(_settings.EnemyFacadePrefab) // Place each enemy under an Enemies game object at the root of scene hierarchy .UnderTransformGroup("Enemies")); Container.BindFactory() // We could just use FromMonoPoolableMemoryPool here instead, but // for IL2CPP to work we need our pool class to be used explicitly here .FromPoolableMemoryPool(poolBinder => poolBinder // Spawn 20 right off the bat so that we don't incur spikes at runtime .WithInitialSize(20) // Bullets are simple enough that we don't need to make a subcontainer for them // The logic can all just be in one class .FromComponentInNewPrefab(_settings.BulletPrefab) .UnderTransformGroup("Bullets")); Container.Bind().AsSingle(); Container.BindFactory() // We could just use FromMonoPoolableMemoryPool here instead, but // for IL2CPP to work we need our pool class to be used explicitly here .FromPoolableMemoryPool(poolBinder => poolBinder // Spawn 4 right off the bat so that we don't incur spikes at runtime .WithInitialSize(4) .FromComponentInNewPrefab(_settings.ExplosionPrefab) .UnderTransformGroup("Explosions")); Container.Bind().AsSingle(); Container.BindInterfacesTo().AsSingle(); Container.Bind().AsSingle(); GameSignalsInstaller.Install(Container); } [Serializable] public class Settings { public GameObject EnemyFacadePrefab; public GameObject BulletPrefab; public GameObject ExplosionPrefab; } // We could just use FromMonoPoolableMemoryPool above, but we have to use these instead // for IL2CPP to work class EnemyFacadePool : MonoPoolableMemoryPool { } class BulletPool : MonoPoolableMemoryPool { } class ExplosionPool : MonoPoolableMemoryPool { } } }