Last active
January 4, 2023 08:26
-
-
Save kdrzymala/23d37c745377957cf9e63aeb55ceb6b5 to your computer and use it in GitHub Desktop.
A feature that's Injectable by Zenject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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