Skip to content

Instantly share code, notes, and snippets.

@kdrzymala
Last active January 4, 2023 08:26
Show Gist options
  • Save kdrzymala/23d37c745377957cf9e63aeb55ceb6b5 to your computer and use it in GitHub Desktop.
Save kdrzymala/23d37c745377957cf9e63aeb55ceb6b5 to your computer and use it in GitHub Desktop.
A feature that's Injectable by Zenject
using Entitas;
using Zenject;
using System.Collections;
using System.Collections.Generic;
public class InjectableFeature : Feature
{
public InjectableFeature()
: base()
{
}
public InjectableFeature( string name )
: base( name )
{ }
public void IncjectSelfAndChildren( DiContainer container )
{
container.Inject( this );
InjectInChilndren( _cleanupSystems, container );
InjectInChilndren( _executeSystems, container );
InjectInChilndren( _initializeSystems, container );
InjectInChilndren( _tearDownSystems, container);
}
private void InjectInChilndren( IEnumerable collection, DiContainer container )
{
foreach ( var sys in collection ) {
var injectableFeature = sys as InjectableFeature;
if (injectableFeature != null ) {
injectableFeature.IncjectSelfAndChildren( container );
} else {
container.Inject( sys );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment